]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blob - parser/grammar.ebnf
4a702edf2bbcfa7f0bfcecb1c47171580cefacb9
[phdru.name/cgi-bin/blog-ru/search-tags.git] / parser / grammar.ebnf
1 # Grammar rules for tag searching; EBNF.
2
3 # The grammar defines expressions in the following forms:
4 #  TAG - search blog posts that contain the tag;
5 #  !TAG - search blog posts that don't contain the tag;
6 #  TAG & TAG - search blog posts that contain both tags;
7 #  TAG | TAG - search blog posts that contain any of the tags;
8 # Parentheses are allowed to group expressions; for example:
9 #  TAG & (TAG | TAG)
10 #  !(TAG | TAG)
11 # Allowed operators: conjunction - & && AND and
12 #                    disjunction - | || OR or
13 #                    negation    - ! NOT not
14 # Usual priority: NOT recognized before AND, AND before OR.
15 # This  is a simple version of the grammar and it allows
16 # rather stupid expressions, like (TAG) or ((TAG)) or !(!(TAG)).
17
18 @@grammar :: Tags
19
20 start = expression $ ;
21
22 expression = expression1 !&or_op | or_expression ;
23
24 or_expression = expression1 or_op expression ;
25
26 and_expression = expression2 and_op expression1 ;
27
28 not_expression = not_op expression3 ;
29
30 parens_expression = '(' expression ')' ;
31
32 expression1 = expression2 !&and_op | and_expression ;
33
34 expression2 = !&not_op expression3 | not_expression ;
35
36 expression3 = parens_expression | name ;
37
38 and_op = '&&' | '&' | 'AND' | 'and' ;
39
40 or_op = '||' | '|' | 'OR' | 'or' ;
41
42 not_op = '!' | 'NOT' | 'not' ;
43
44 name = /[a-z][a-z0-9_]+/ ;