summaryrefslogtreecommitdiff
path: root/examples/searchParserAppDemo.py
diff options
context:
space:
mode:
authorCengiz Kaygusuz <cngkaygusuz@gmail.com>2017-11-20 20:46:39 -0500
committerCengiz Kaygusuz <cngkaygusuz@gmail.com>2017-11-20 20:46:39 -0500
commit27e183a78c8062ed7c2bbb91655a5e56cd697bba (patch)
tree88fd355a0cc6da4c130582e092d702836596cbb2 /examples/searchParserAppDemo.py
parent4ba589cf13588e90992e23deb5a9784340efd2cc (diff)
downloadpyparsing-git-27e183a78c8062ed7c2bbb91655a5e56cd697bba.tar.gz
Move src to root
Diffstat (limited to 'examples/searchParserAppDemo.py')
-rw-r--r--examples/searchParserAppDemo.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/searchParserAppDemo.py b/examples/searchParserAppDemo.py
new file mode 100644
index 0000000..259e0e3
--- /dev/null
+++ b/examples/searchParserAppDemo.py
@@ -0,0 +1,34 @@
+from searchparser import SearchQueryParser
+
+products = [ "grape juice", "grape jelly", "orange juice", "orange jujubees",
+ "strawberry jam", "prune juice", "prune butter", "orange marmalade",
+ "grapefruit juice" ]
+
+class FruitSearchParser(SearchQueryParser):
+ def GetWord(self, word):
+ return set( p for p in products if p.startswith(word + " ") )
+
+ def GetWordWildcard(self, word):
+ return set( p for p in products if p.startswith(word[:-1]) )
+
+ def GetQuotes(self, search_string, tmp_result):
+ result = Set()
+ # I have no idea how to use this feature...
+ return result
+
+ def GetNot(self, not_set):
+ return set( products ) - not_set
+
+
+parser = FruitSearchParser()
+
+tests = """\
+ grape or orange
+ grape*
+ not(grape*)
+ prune and grape""".splitlines()
+
+for t in tests:
+ print(t.strip())
+ print(parser.Parse(t))
+ print('') \ No newline at end of file