diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2012-10-02 04:55:56 +0000 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2012-10-02 04:55:56 +0000 |
commit | a7f9dda0668bfce4fba51df1bf2976b4a93a8bd5 (patch) | |
tree | 57ea8bcf2e66532a36c833a7bc57cff9d5d0e4dd /src/examples/searchParserAppDemo.py | |
parent | f5d2b716ffb57b65660a7ee0bbf04332dfb29620 (diff) | |
download | pyparsing-git-a7f9dda0668bfce4fba51df1bf2976b4a93a8bd5.tar.gz |
Add example files to SVN
Diffstat (limited to 'src/examples/searchParserAppDemo.py')
-rw-r--r-- | src/examples/searchParserAppDemo.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/examples/searchParserAppDemo.py b/src/examples/searchParserAppDemo.py new file mode 100644 index 0000000..b6ea064 --- /dev/null +++ b/src/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 |