]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blob - parser/grammar.ebnf
b657738ad5f30a6ab29508f8364b212faffa4708
[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 # This  is a simple version of the grammar and it allows
15 # rather stupid expressions, like !!TAG or ((TAG))
16
17 @@grammar :: Tags
18
19 start = expression $ ;
20
21 expression = (
22            | expression and_op expression
23            | expression or_op expression
24            | not_op expression
25            | expression_parens
26            | name ) ;
27
28 expression_parens = '(' expression ')' ;
29
30 name = /[a-z][a-z0-9_]+/ ;
31
32 and_op = '&' | '&&' | 'AND' | 'and' ;
33
34 or_op = '|' | '||' | 'OR' | 'or' ;
35
36 not_op = '!' | 'NOT' | 'not' ;