]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blob - parser/grammar.ebnf
935e6a4d3477f7bfa557fde4a28c5dca83786eaa
[phdru.name/cgi-bin/blog-ru/search-tags.git] / parser / grammar.ebnf
1 # Grammar rules for tag searching
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 expression = or_expression / aterm_expression
19
20 or_expression = aterm_expression or_op expression
21
22 and_expression = term_expression and_op aterm_expression
23
24 not_expression = not_op space0 (parens_expression / name)
25
26 aterm_expression = and_expression / term_expression
27
28 term_expression = not_expression / parens_expression / (name space_b4letter)
29
30 parens_expression = "(" space0 expression space0 ")"
31
32 and_op = (space0 ("&&" / "&") space0) / (space0 ("AND" / "and") space_b4letter)
33
34 or_op = (space0 ("||" / "|") space0) / (space0 ("OR" / "or") space_b4letter)
35
36 not_op = (space0 "!" space0) / (space0 ("NOT" / "not") space_b4letter)
37
38 letter = ~"[a-z]"i
39
40 name = ~"[a-z][a-z0-9_]*"
41
42 space_b4letter = (space1 &letter) / space0
43
44 space0 = ~" *"
45
46 space1 = ~" +"
47
48 # vim: set ft=text :