forked from FabienHenon/fiqlex
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fiql_parser.yrl
38 lines (27 loc) · 1.81 KB
/
fiql_parser.yrl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Nonterminals or_expression and_expression constraint group arguments list_arguments list_argument_items.
Terminals '(' ')' or_op and_op selector arg_float arg_int arg_bool value comparison equal not_equal.
Rootsymbol or_expression.
Right 100 or_op.
Right 200 and_op.
or_expression -> and_expression : '$1'.
or_expression -> or_expression or_op or_expression : {or_op, '$1', '$3'}.
and_expression -> constraint : '$1'.
and_expression -> or_expression and_op or_expression : {and_op, '$1', '$3'}.
constraint -> group : '$1'.
constraint -> selector : {op, {selector, list_to_binary(extract_token('$1'))}}.
constraint -> selector comparison arguments : {op, {selector_and_value, list_to_binary(extract_token('$1')), {comparison, list_to_binary(extract_token('$2'))}, '$3'}}.
constraint -> selector equal arguments : {op, {selector_and_value, list_to_binary(extract_token('$1')), equal, '$3'}}.
constraint -> selector not_equal arguments : {op, {selector_and_value, list_to_binary(extract_token('$1')), not_equal, '$3'}}.
group -> '(' or_expression ')' : '$2'.
arguments -> value : unicode:characters_to_binary(extract_token('$1')).
arguments -> selector : unicode:characters_to_binary(extract_token('$1')).
arguments -> arg_float : extract_token('$1').
arguments -> arg_int : extract_token('$1').
arguments -> arg_bool : extract_token('$1').
arguments -> list_arguments : '$1'.
list_arguments -> '(' ')' : [].
list_arguments -> '(' list_argument_items ')' : '$2'.
list_argument_items -> arguments : ['$1'].
list_argument_items -> arguments or_op list_argument_items : ['$1' | '$3'].
Erlang code.
extract_token({_Token, _Line, Value}) -> Value.