-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtgtokens.g4
88 lines (72 loc) · 1.6 KB
/
mtgtokens.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
grammar mtgtokens;
// First declare individual words, then group them in revelant lexer rules.
TAP: 'T' | 't';
UNTAP: 'Q' | 'q';
COLOURS_SHORT
: 'W' | 'w'
| 'U' | 'u'
| 'R' | 'r'
| 'B' | 'b'
| 'G' | 'g'
| 'C' | 'c'
;
AND: 'and';
OR: 'or';
THE: 'the';
OF: 'of';
COMMA: ',';
COLON: ':';
TILDE: '~';
WMORE: 'more';
WHEN: 'when';
WHENEVER: 'whenever';
AS: 'as';
AT: 'at';
A: 'a';
AN: 'an';
ANOTHER: 'another';
THAT: 'that';
EACH: 'each';
TARGET: 'target';
YOU: 'you';
YOUR: 'your';
OPPONENT: 'opponent';
PLAYER: 'player';
DRAW: 'draw';
STEP: 'step';
COMBAT: 'combat';
UPKEEP: 'upkeep';
PRECOMBAT: 'precombat';
POSTCOMBAT: 'postcombat';
BEGINNING: 'beginning';
MAIN: 'main';
END: 'end';
PHASE: 'phase';
SELECTIVES: YOUR | EACH | THAT;
NUMBER
: [1-9][0-9]* // don't allow flat {0}.
;
WORD_NUMBER: 'one' | 'two' | 'three' | 'four' | 'five' | 'six' | 'seven' | 'eight' | 'nine' | 'ten'
| 'eleven' /* not used */ | 'twelve' | 'thirteen' | 'fourteen' /* not used */ | 'fifteen' | 'twenty'
;
COLOURS_LONG
: 'white' | 'blue' | 'red' | 'black' | 'green' | 'colorless'
;
/*
Mana costs can be simply {3}, or {r}, or {2/r}, or {3}{G/P}.
Multiples are handled by the mana_cost rule.
Need / to handle hybrid costs, and 2 for two-brid costs.
*/
MANA_COST
: '{' ( NUMBER | COLOURS_SHORT | ('2' '/' COLOURS_SHORT) | (COLOURS_SHORT '/' ('P'|'p')) ) '}'
;
// Maybe don't even list all of them, just accept a string.
CREATURE_TYPE
: [A-z ]+
;
// These are catchall rules, so put them at the end.
WS : [ \r\t\f\n]+ -> skip;
OTHER: . -> skip;
STRING
: '"' [A-z ]+ '"'
;