Imported Upstream version 2.10+ds
[debian/jabref.git] / src / java / net / sf / jabref / search / Parser.g
index 2ae61c3..e5d9635 100644 (file)
-header {\r
-package net.sf.jabref.search;\r
-import java.io.StringReader;\r
-}\r
-\r
-class SearchExpressionParser extends Parser;\r
-\r
-options {\r
-       importVocab = SearchExpressionLexer; // use vocab generated by lexer\r
-       exportVocab = SearchExpressionParser;\r
-       defaultErrorHandler = false;\r
-       buildAST = true;\r
-       k = 3;\r
-}\r
-\r
-tokens {\r
-       RegularExpression;\r
-       And;\r
-       Or;\r
-       Not;\r
-       ExpressionSearch;\r
-}\r
-\r
-// ---------- Java Source Code ----------\r
-\r
-{\r
-       public boolean caseSensitive = false;\r
-    public boolean regex = true;\r
-       /** Creates a parser and lexer instance and tests the specified String.\r
-         * Returns the AST if s is in valid syntax for advanced field search, null otherwise. */\r
-       public static AST checkSyntax(String s, boolean caseSensitive, boolean regex) {\r
-               // Is there some way to prevent instance creation here?\r
-               // How can a parser and/or lexer be reused?\r
-               SearchExpressionParser parser = new SearchExpressionParser(new SearchExpressionLexer(\r
-                               new StringReader(s)));\r
-               parser.caseSensitive = caseSensitive;\r
-               parser.regex = regex;\r
-               try {\r
-                       parser.searchExpression();\r
-                       return parser.getAST();\r
-               } catch (Exception e) {\r
-                       return null;\r
-               }\r
-       }\r
-}\r
-\r
-// ---------- Text and Regular Expressions ----------\r
-\r
-quotedRegularExpression[boolean caseSensitive, boolean regex]:\r
-               var_s:STRING\r
-                       {\r
-                               ## = astFactory.make((new ASTArray(2)).add(new RegExNode(RegularExpression,var_s.getText(),caseSensitive,regex)).add(##));\r
-                       }\r
-               ;\r
-\r
-simpleRegularExpression[boolean caseSensitive, boolean regex]:\r
-               var_s:FIELDTYPE\r
-                       {\r
-                               ## = astFactory.make((new ASTArray(2)).add(new RegExNode(RegularExpression,var_s.getText(),caseSensitive,regex)).add(##));\r
-                       }\r
-               ;\r
-\r
-// ---------- Condition and Expressions ----------\r
-\r
-searchExpression:\r
-       condition EOF;\r
-\r
-condition:\r
-               (expression LITERAL_and condition) => expression LITERAL_and! condition { ## = #( [And], ##); }\r
-               |\r
-               (expression LITERAL_or condition) => expression LITERAL_or! condition { ## = #( [Or], ##); }\r
-               |\r
-               expression // negation is done in expression\r
-               ;\r
-\r
-expression:\r
-               expressionSearch\r
-               |\r
-               LPAREN! condition RPAREN!\r
-               |\r
-               LITERAL_not! expressionSearch { ## = #( [Not], ## ); }         // NOT single expression\r
-               |\r
-               LITERAL_not! LPAREN! condition RPAREN! { ## = #( [Not], ## ); } // NOT ( ... )\r
-               ;\r
-\r
-expressionSearch:\r
-               quotedRegularExpression[false,true] compareType quotedRegularExpression[caseSensitive,regex]\r
-                       { ## = #( [ExpressionSearch], ## ); }\r
-               |\r
-               simpleRegularExpression[false,true] compareType quotedRegularExpression[caseSensitive,regex]\r
-                       { ## = #( [ExpressionSearch], ## ); }\r
-               |\r
-               simpleRegularExpression[false,true] compareType simpleRegularExpression[caseSensitive,regex]\r
-                       { ## = #( [ExpressionSearch], ## ); }\r
-               |\r
-               quotedRegularExpression[false,true] compareType simpleRegularExpression[caseSensitive,regex]\r
-                       { ## = #( [ExpressionSearch], ## ); }\r
-               ;\r
-\r
-compareType:\r
-               LITERAL_contains | LITERAL_matches | EQUAL | EEQUAL | NEQUAL\r
-               ;\r
-\r
+header {
+package net.sf.jabref.search;
+import java.io.StringReader;
+}
+
+class SearchExpressionParser extends Parser;
+
+options {
+       importVocab = SearchExpressionLexer; // use vocab generated by lexer
+       exportVocab = SearchExpressionParser;
+       defaultErrorHandler = false;
+       buildAST = true;
+       k = 3;
+}
+
+tokens {
+       RegularExpression;
+       And;
+       Or;
+       Not;
+       ExpressionSearch;
+}
+
+// ---------- Java Source Code ----------
+
+{
+       public boolean caseSensitive = false;
+    public boolean regex = true;
+       /** Creates a parser and lexer instance and tests the specified String.
+         * Returns the AST if s is in valid syntax for advanced field search, null otherwise. */
+       public static AST checkSyntax(String s, boolean caseSensitive, boolean regex) {
+               // Is there some way to prevent instance creation here?
+               // How can a parser and/or lexer be reused?
+               SearchExpressionParser parser = new SearchExpressionParser(new SearchExpressionLexer(
+                               new StringReader(s)));
+               parser.caseSensitive = caseSensitive;
+               parser.regex = regex;
+               try {
+                       parser.searchExpression();
+                       return parser.getAST();
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+}
+
+// ---------- Text and Regular Expressions ----------
+
+quotedRegularExpression[boolean caseSensitive, boolean regex]:
+               var_s:STRING
+                       {
+                               ## = astFactory.make((new ASTArray(2)).add(new RegExNode(RegularExpression,var_s.getText(),caseSensitive,regex)).add(##));
+                       }
+               ;
+
+simpleRegularExpression[boolean caseSensitive, boolean regex]:
+               var_s:FIELDTYPE
+                       {
+                               ## = astFactory.make((new ASTArray(2)).add(new RegExNode(RegularExpression,var_s.getText(),caseSensitive,regex)).add(##));
+                       }
+               ;
+
+// ---------- Condition and Expressions ----------
+
+searchExpression:
+       condition EOF;
+
+condition:
+               (expression LITERAL_and condition) => expression LITERAL_and! condition { ## = #( [And], ##); }
+               |
+               (expression LITERAL_or condition) => expression LITERAL_or! condition { ## = #( [Or], ##); }
+               |
+               expression // negation is done in expression
+               ;
+
+expression:
+               expressionSearch
+               |
+               LPAREN! condition RPAREN!
+               |
+               LITERAL_not! expressionSearch { ## = #( [Not], ## ); }         // NOT single expression
+               |
+               LITERAL_not! LPAREN! condition RPAREN! { ## = #( [Not], ## ); } // NOT ( ... )
+               ;
+
+expressionSearch:
+               quotedRegularExpression[false,true] compareType quotedRegularExpression[caseSensitive,regex]
+                       { ## = #( [ExpressionSearch], ## ); }
+               |
+               simpleRegularExpression[false,true] compareType quotedRegularExpression[caseSensitive,regex]
+                       { ## = #( [ExpressionSearch], ## ); }
+               |
+               simpleRegularExpression[false,true] compareType simpleRegularExpression[caseSensitive,regex]
+                       { ## = #( [ExpressionSearch], ## ); }
+               |
+               quotedRegularExpression[false,true] compareType simpleRegularExpression[caseSensitive,regex]
+                       { ## = #( [ExpressionSearch], ## ); }
+               ;
+
+compareType:
+               LITERAL_contains | LITERAL_matches | EQUAL | EEQUAL | NEQUAL
+               ;
+