forked from JetBrains/Grammar-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExprParser.bnf
75 lines (69 loc) · 2.66 KB
/
ExprParser.bnf
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
generate=[psi="no"]
classHeader="//header.txt"
parserClass="org.intellij.grammar.expression.ExpressionParser"
extends(".*expr")=expr
elementTypeFactory="org.intellij.grammar.expression.ExpressionParserDefinition.createType"
tokenTypeFactory="org.intellij.grammar.expression.ExpressionParserDefinition.createTokenType"
elementTypeHolderClass="org.intellij.grammar.expression.ExpressionTypes"
parserUtilClass="org.intellij.grammar.parser.GeneratedParserUtilBase"
tokens=[
space='regexp:\s+'
comment='regexp://.*'
number='regexp:\d+(\.\d*)?'
id='regexp:\p{Alpha}\w*'
string="regexp:('([^'\\]|\\.)*'|\"([^\"\\]|\\.)*\")"
syntax='regexp:;|\.|\+|-|\*\*|\*|==|=|/|,|\(|\)|\^|\!=|\!|>=|<=|>|<'
]
}
root ::= element *
private element ::= expr ';'? {recoverWhile=element_recover}
private element_recover ::= !('(' | '+' | '-' | '!' | 'multiply' | id | number)
// left recursion and empty PSI children define expression root
expr ::= assign_expr
| conditional_group
| add_group
| boolean_group
| mul_group
| unary_group
| exp_expr
| factorial_expr
| call_expr
| qualification_expr
| primary_group
{extraRoot=true}
private boolean_group ::= xor_expr | between_expr | is_not_expr
private conditional_group ::= elvis_expr | conditional_expr
private unary_group ::= unary_plus_expr | unary_min_expr | unary_not_expr
private mul_group ::= mul_expr | div_expr
private add_group ::= plus_expr | minus_expr
private primary_group ::= special_expr | simple_ref_expr | literal_expr | paren_expr
// expressions: auto-operator detection or parens
fake ref_expr ::= expr? '.' identifier
simple_ref_expr ::= identifier {extends=ref_expr elementType=ref_expr}
qualification_expr ::= expr '.' identifier {extends=ref_expr elementType=ref_expr}
call_expr ::= ref_expr arg_list
arg_list ::= '(' [ !')' expr (',' expr) * ] ')' {pin(".*")=1}
literal_expr ::= number
identifier ::= id
unary_min_expr ::= '-' expr
unary_plus_expr ::= '+' expr
unary_not_expr ::= '!' expr
xor_expr ::= expr '^' expr
assign_expr ::= expr '=' expr { rightAssociative=true }
conditional_expr ::= expr ('<' | '>' | '<=' | '>=' | '==' | '!=') expr
div_expr ::= expr '/' expr
mul_expr ::= expr '*' expr
minus_expr ::= expr '-' expr
plus_expr ::= expr '+' expr
exp_expr ::= expr ('**' expr) + // N-ary variant
factorial_expr ::= expr '!'
paren_expr ::= '(' expr ')'
elvis_expr ::= expr '?' expr ':' expr
is_not_expr ::= expr IS NOT expr
between_expr ::= expr BETWEEN add_group AND add_group {
methods=[testExpr="expr[0]"]
}
// test specific expressions
external special_expr ::= meta_special_expr
meta_special_expr ::= 'multiply' '(' simple_ref_expr ',' mul_expr ')' {elementType="special_expr" pin=2}