]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blob - parser/grammar.ebnf
Docs(TODO): Try Pyleri
[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)); in the future
16 # it will be fixed by making the grammar more complex and stricter.
17
18 ?start : expression
19
20 ?expression : or_expression
21             | and_expression
22             | and_sub_expression
23
24 or_expression : or_sub_expression (or or_sub_expression)+
25
26 ?or_sub_expression : and_expression
27                    | and_sub_expression
28
29 and_expression : and_sub_expression (and and_sub_expression)+
30
31 ?and_sub_expression : not_expression
32                     | expression_parens
33                     | name
34
35 not_expression: not and_sub_expression
36
37 expression_parens : "(" expression ")"
38
39 name : /[a-z][a-z0-9_]+/
40
41 ?and : and_op
42      | and_op and_op
43      | and_word
44
45 ?or : or_op
46     | or_op or_op
47     | or_word
48
49 ?not : not_op
50      | not_word
51
52 ?and_op : "&"
53
54 ?or_op : "|"
55
56 ?not_op : "!"
57
58 ?and_word : "AND"
59           | "and"
60
61 ?or_word : "OR"
62          | "or"
63
64 ?not_word : "NOT"
65           | "not"
66
67 %import common.WS
68 %ignore WS