forked from dhobsd/asciitosvg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg-path.y
140 lines (107 loc) · 4.59 KB
/
svg-path.y
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
%name A2S_SVGPath
%token_prefix TK_
%wildcard ANY.
svg_path ::= moveto_drawto_command_groups.
moveto_drawto_command_groups ::= moveto_drawto_command_groups moveto_drawto_command_group.
moveto_drawto_command_groups ::= moveto_drawto_command_group.
moveto_drawto_command_group ::= moveto drawto_commands.
drawto_commands ::= drawto_commands drawto_command.
drawto_commands ::= drawto_command.
drawto_command ::= closepath.
drawto_command ::= lineto.
drawto_command ::= horizontal_lineto.
drawto_command ::= vertical_lineto.
drawto_command ::= curveto.
drawto_command ::= smooth_curveto.
drawto_command ::= quadratic_bezier_curveto.
drawto_command ::= smooth_quadratic_bezier_curveto.
drawto_command ::= elliptical_arc.
moveto ::= MCMD(A) moveto_argument_sequence(B).
{
if (count(B) == 2) {
$this->commands[] = array_merge(array(A), B);
} else {
if (A->value == 'm') {
$arr = array ('value' => 'l');
} else {
$arr = array ('value' => 'L');
}
$c = array_splice(B, 2);
$this->commands[] = array_merge(array(A), B);
$this->commands[] = array_merge(array($arr), $c);
}
}
moveto_argument_sequence(A) ::= lineto_argument_sequence(B)
coordinate_pair(C). { A = array_merge(B, C); }
moveto_argument_sequence(A) ::= coordinate_pair(B). { A = B; }
closepath ::= ZCMD(A). { $this->commands[] = array(A); }
lineto ::= LCMD(A) lineto_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
lineto_argument_sequence(A) ::= lineto_argument_sequence(B) coordinate_pair(C).
{ A = array_merge(B, C); }
lineto_argument_sequence(A) ::= coordinate_pair(B). { A = B; }
horizontal_lineto ::= HCMD(A) horizontal_lineto_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
horizontal_lineto_argument_sequence(A) ::=
horizontal_lineto_argument_sequence(B) coordinate(C).
{ A = array_merge(B, array(C)); }
horizontal_lineto_argument_sequence(A) ::= coordinate(B). { A = array(B); }
vertical_lineto ::= VCMD(A) vertical_lineto_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
vertical_lineto_argument_sequence(A) ::= vertical_lineto_argument_sequence(B)
coordinate(C).
{ A = array_merge(B, array(C)); }
vertical_lineto_argument_sequence(A) ::= coordinate(B). { A = array(B); }
curveto ::= CCMD(A) curveto_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
curveto_argument_sequence(A) ::= curveto_argument_sequence(B)
curveto_argument(C).
{ A = array_merge(B, C); }
curveto_argument_sequence(A) ::= curveto_argument(B). { A = B; }
curveto_argument(A) ::= coordinate_pair(B) coordinate_pair(C)
coordinate_pair(D).
{ A = array_merge(B, C, D); }
smooth_curveto ::= SCMD(A) smooth_curveto_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
smooth_curveto_argument_sequence(A) ::= smooth_curveto_argument_sequence(B)
smooth_curveto_argument(C).
{ A = array_merge(B, C); }
smooth_curveto_argument_sequence(A) ::= smooth_curveto_argument(B). { A = B; }
smooth_curveto_argument(A) ::= coordinate_pair(B) coordinate_pair(C).
{ A = array_merge(B, C); }
quadratic_bezier_curveto ::= QCMD(A)
quadratic_bezier_curveto_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
quadratic_bezier_curveto_argument_sequence(A) ::=
quadratic_bezier_curveto_argument_sequence(B)
quadratic_bezier_curveto_argument(C).
{ A = array_merge(B, C); }
quadratic_bezier_curveto_argument_sequence(A) ::=
quadratic_bezier_curveto_argument(B).
{ A = B; }
quadratic_bezier_curveto_argument(A) ::= coordinate_pair(B) coordinate_pair(C).
{ A = array_merge(B, C); }
smooth_quadratic_bezier_curveto ::= TCMD(A)
smooth_quadratic_bezier_curveto_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
smooth_quadratic_bezier_curveto_argument_sequence(A) ::=
smooth_quadratic_bezier_curveto_argument_sequence(B)
coordinate_pair(C).
{ A = array_merge(B, C); }
smooth_quadratic_bezier_curveto_argument_sequence(A) ::= coordinate_pair(B).
{ A = B; }
elliptical_arc ::= ACMD(A) elliptical_arc_argument_sequence(B).
{ $this->commands[] = array_merge(array(A), B); }
elliptical_arc_argument_sequence(A) ::= elliptical_arc_argument_sequence(B)
elliptical_arc_argument(C).
{ A = array_merge(B, C); }
elliptical_arc_argument_sequence(A) ::= elliptical_arc_argument(B).
{ A = B; }
elliptical_arc_argument(A) ::= POSNUM(B) POSNUM(C) number(D) FLAG(E) FLAG(F)
coordinate_pair(G).
{ A = array_merge(array(B, C, D, E, F), G); }
coordinate_pair(A) ::= coordinate(B) coordinate(C). { A = array(B, C); }
coordinate(A) ::= number(B). { A = B; }
number(A) ::= POSNUM(B). { A = B; }
number(A) ::= FLAG(B). { A = B; }
number(A) ::= NEGNUM(B). { A = B; }