]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blob - parser/grammar
Reorder handling: AND - OR - NOT
[phdru.name/cgi-bin/blog-ru/search-tags.git] / parser / grammar
1 # Grammar rules for tag searching; BNF.
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    - !
14 # This  is a simple version of the grammar and it allows
15 # rather stupid expressions, like !!TAG or ((TAG)); in the future
16 # it will be fixed by making the grammar more complex and stricter.
17
18 NAME : '[a-z][a-z0-9_]+'
19
20 AND_OP : '&'
21
22 OR_OP : '|'
23
24 NOT_OP : '!'
25
26 SP1 : '[ \t]+'
27
28 expression : NAME
29            | expression SP0 AND_OP AND_OP SP0 expression
30            | expression SP0 AND_OP SP0 expression
31            | l_expression and_word r_expression
32            | expression SP0 OR_OP OR_OP SP0 expression
33            | expression SP0 OR_OP SP0 expression
34            | l_expression or_word r_expression
35            | NOT_OP SP0 expression
36            | expression_parens
37
38 l_expression : expression_parens
39              | expression_sp
40
41 r_expression : expression_parens
42              | sp_expression
43
44 expression_parens : '(' SP0 expression SP0 ')'
45
46 sp_expression : SP1 expression
47
48 expression_sp : expression SP1
49
50 and_word : 'A' 'N' 'D'
51          | 'a' 'n' 'd'
52
53 or_word : 'O' 'R'
54         | 'o' 'r'
55
56 SP0 : SP1 | empty
57
58 empty :