-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNip.g4
95 lines (85 loc) · 3.16 KB
/
Nip.g4
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// To generate run:
// java -jar antlr-4.9.3-complete.jar Nip.g4 -o Generated -Dlanguage=CSharp -no-listener -visitor -package NipSharp
grammar Nip;
/* * Parser Rules */
// Left hand side
flagProperty: FLAG;
affixProperty: AFFIX;
stat: IDENTIFIER | INTEGER;
meProperty: IDENTIFIER;
functionName: IDENTIFIER;
property: IDENTIFIER;
maxQuantity: MAXQUANTITY;
tier: TIER;
mercTier: MERCTIER;
charmTier: CHARMTIER;
swapTier: SWAPTIER;
// Right hand side
number: INTEGER | FLOAT;
numberOrAlias: IDENTIFIER | INTEGER;
statExpr
: statExpr op=(MUL | DIV) statExpr #statMulDivRule
| statExpr op=(ADD | SUB) statExpr #statAddSubRule
| op=(ADD | SUB)? '['stat']' #statNameRule
| op=(ADD | SUB)? 'me.'meProperty #statMeRule
| op=(ADD | SUB)? functionName'(item)' #statFunctionRule
| op=(ADD | SUB)? number #statNumberRule
| op=(ADD | SUB)? '('statExpr')' #statExprParenRule
;
statRule
: statExpr op=(EQ | NEQ | GT | GTE | LT | LTE) statExpr #statRelationalRule
| statRule op=(AND | OR) statRule #statLogicalRule
| '('statRule')' #statParenRule
;
// Because we peek at the value
propertyRule
: '['flagProperty']' op=(EQ | NEQ | GT | GTE | LT | LTE) numberOrAlias #propFlagRule // This is special because it's actually [flag]&value == value
| 'me.'meProperty op=(EQ | NEQ | GT | GTE | LT | LTE) numberOrAlias #propMeRule
| '['affixProperty']' op=(EQ | NEQ | GT | GTE | LT | LTE) numberOrAlias #propAffixRule // This is special because it creates a chain of OR's, (i.e, [prefix] == 1 turns into [prefix0] == 1 || [prefix1] == 1 || [prefix2] == 1)
| '['property']' op=(EQ | NEQ | GT | GTE | LT | LTE) numberOrAlias #propRelationalRule
| property op=(EQ | NEQ | GT | GTE | LT | LTE) numberOrAlias #propRelationalRule
| propertyRule op=(AND | OR) propertyRule #propLogicalRule
| '('propertyRule')' #propParenRule
;
// These are all special as I have no idea what they really do.
additionalRule
: '['maxQuantity']' op=EQ statExpr #additionalMaxQuantityRule
| '['tier']' op=EQ statExpr #additionalTierRule
| '['mercTier']' op=EQ statExpr #additionalMercTierRule
| '['charmTier']' op=EQ statExpr #additionalCharmTierRule
| '['swapTier']' op=EQ statExpr #additionalSwapTierRule
| additionalRule op=(AND | OR) additionalRule #additionalLogicalRule
| '('additionalRule')' #additionalParenRule
;
nipRule: propertyRule? ('#' statRule? ('#' additionalRule?)?)?;
line: nipRule | <EOF>;
/* * Lexer Rules */
fragment DIGIT: [0-9];
fragment LETTER: [a-z];
fragment QUOTE: '\'';
fragment COMMA: ',';
FLAG: 'flag';
AFFIX: ('prefix' | 'suffix');
MAXQUANTITY: 'maxquantity';
TIER: 'tier';
MERCTIER: 'merctier';
CHARMTIER: 'charmtier';
SWAPTIER: 'swaptier';
FLOAT: DIGIT+ '.' DIGIT+;
INTEGER: DIGIT+;
IDENTIFIER: LETTER(LETTER | DIGIT | QUOTE | COMMA)*;
EQ: '==';
NEQ: '!=';
GT: '>';
GTE: '>=';
LT: '<';
LTE: '<=';
AND: '&&';
OR: '||';
MUL: '*';
DIV: '/';
ADD: '+';
SUB: '-';
WS: [\t\r\n ]+ -> skip;
LINE_COMMENT: '//' ~[\r\n]* -> skip;
BLOCK_COMMENT: '/*' .*? '*/' -> skip; // The wildcard catch in the middle might be wrong? But seems to work?