-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tikz.g4
112 lines (87 loc) · 2.23 KB
/
Tikz.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
grammar Tikz;
begin
: BEGINTIKZPICTURE allGlobalProperties instructions* ENDTIKZPICTURE EOF
;
instructions
: node instructions
| draw instructions
| draw
| node
;
draw
: DRAW edgeProperties nodeList SEMICOLON
| DRAW edgeProperties coordinates (VARIABLE|EXPRESSION) coordinates SEMICOLON
| DRAW edgeProperties coordinates (VARIABLE|EXPRESSION) radius SEMICOLON
| DRAW edgeProperties coordinates (VARIABLE|EXPRESSION) nodeProperties label
;
radius
: OPEN_PARANTHESES (VARIABLE|EXPRESSION) CLOSE_PARANTHESES
;
nodeList
: edgeNode '--' nodeList
| edgeNode
;
edgeNode
: coordinates
| OPEN_PARANTHESES (VARIABLE|EXPRESSION) CLOSE_PARANTHESES
;
edgeProperties
: '[' (properties)? ']'
|
;
node
: NODE nodeProperties nodeId nodeProperties AT coordinates nodeProperties label
;
nodeId
: OPEN_PARANTHESES (VARIABLE|EXPRESSION)? CLOSE_PARANTHESES
|
;
allGlobalProperties
: '[' (globalProperties)? ']'
|
;
globalProperties
: globalProperties ',' globalProperties
| EVERY (VARIABLE|EXPRESSION) '/.' 'style' '=' '{' properties '}'
| properties
;
nodeProperties
: '[' (properties)? ']'
|
;
properties
: individualProperty ',' properties
| individualProperty
;
individualProperty
: (VARIABLE|EXPRESSION)+ EQUAL_TO (VARIABLE|EXPRESSION)+
| (VARIABLE|EXPRESSION)+
;
coordinates
: OPEN_PARANTHESES (VARIABLE|EXPRESSION) (COMMA|AND) (VARIABLE|EXPRESSION) CLOSE_PARANTHESES #cartesianCoordinates
| OPEN_PARANTHESES (VARIABLE|EXPRESSION) COLON (VARIABLE|EXPRESSION) CLOSE_PARANTHESES #polarCoordinates
;
label
: LABEL_VARIABLE
;
// List of all the tokens used during the lexer phase
BEGINTIKZPICTURE: '\\begin{tikzpicture}';
ENDTIKZPICTURE: '\\end{tikzpicture}';
NODE: '\\node';
DRAW: '\\draw';
AT: 'at';
AND: 'and';
EVERY: 'every';
OPEN_PARANTHESES: '(';
CLOSE_PARANTHESES: ')';
EQUAL_TO: '=';
COMMA: ',';
COLON: ':';
SEMICOLON: ';';
PAUSE : '\\pause' -> skip;
// EXPRESSION should be above VARIABLE for higher precedence
LABEL_VARIABLE: '{' ~'\n'*? '}' [ \r\t]* ';';
EXPRESSION: [0-9/*-+.]+;
VARIABLE: [-a-zA-Z0-9_!$.><|\\+]+;
COMMENT : '%' ~[\n]* -> skip ;
WS : [ \r\t\n]+ -> skip ;