-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFragmentGrammar.jj
222 lines (190 loc) · 5.04 KB
/
FragmentGrammar.jj
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// $Id: FragmentGrammar.jj,v 1.8 2010/11/02 08:23:28 ylafon Exp $
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2009 and onwards.
// Please first read the full copyright statement at the URI below
// http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
options {
IGNORE_CASE = false;
STATIC = false;
UNICODE_INPUT = false;
/*
DEBUG_TOKEN_MANAGER = true;
DEBUG_PARSER = true;
*/
}
PARSER_BEGIN(FragmentParser)
import java.io.StringReader;
import java.io.IOException;
public class FragmentParser {
FragmentParser() {
}
public static void main(String args[]) {
if (args.length < 1) {
System.err.println("Not enought parameters");
System.exit(1);
}
for (int i=0; i< args.length; i++) {
String param = args[i];
System.out.println("Checking: "+param);
if (param.indexOf("#") >= 0) {
param = param.substring(param.indexOf("#")+1);
} else if (param.indexOf("?") >= 0) {
param = param.substring(param.indexOf("?")+1);
}
StringReader sr = new StringReader(param);
try {
new FragmentParser(sr).parserUnit();
System.out.println("OK");
} catch (Exception ex) {
System.out.println("failed");
}
}
}
}
PARSER_END(FragmentParser)
/*
* The tokenizer
*/
<DEFAULT>
TOKEN :
{
<TIMEPREFIX: ( "t" | "%74" ) >
| <TIMEUNIT: ( "s" | "%73" ) >
| < DEFTIMEFORMAT : ( "n" | "%6e" | "%6E" ) ( "p" | "%70" ) ( "t" | "%74" ) >
| < TIMEFORMAT : ( "s" | "%73" ) ( "m" | "%6d" | "%6D" ) ( "p" | "%70" ) ( "t" | "%74" ) ( "e" | "%65" ) ( "-" ( ( ( "2" | "%32" ) ( "5" | "%35" ) ) | ( ( "3" | "%33" ) ( "0" | "%30" ) ( "-" ( "d" | "%64" ) ( "r" | "%72" ) ( "o" | "%6f" | "%6F" ) ( "p" | "%70" ) )? ) ) )? >
| < XYWHPREFIX : ( "x" | "%78" ) ( "y" | "%79" ) ( "w" | "%77" ) ( "h" | "%68" ) >
| < XYWHUNIT : ( ( "p" | "%70" ) ( "i" | "%69" ) ( "x" | "%78" ) ( "e" | "%65" ) ( "l" | "%6c" | "%6C" ) ) | ( ( "p" | "%70" ) ( "e" | "%65" ) ( "r" | "%72" ) ( "c" | "%63" ) ( "e" | "%65" ) ( "n" | "%6e" | "%6E" ) ( "t" | "%74" ) ) >
| < TRACKPREFIX : ( "t" | "%74" ) ( "r" | "%72" ) ( "a" | "%61" ) ( "c" | "%63" ) ( "k" | "%6b" | "%6B" ) >
| < NAMEPREFIX : ( "i" | "%69" ) ( "d" | "%64" ) >
}
<DEFAULT>
TOKEN :
{
< COLON : ":" >
| < EQ : "=" >
| < AMP : "&" >
| < COMMA : "," >
| < DOT : ( "." | "%2E" | "%2e" ) >
}
<DEFAULT>
TOKEN : /* rfc2234 */
{
< #ALPHA : ["A"-"Z","a"-"z"] >
| < DIGIT : ["0"-"9"] >
| < #HEXDIG : ( <DIGIT> | ["A"-"F","a"-"f"] ) >
}
<DEFAULT>
TOKEN : /* rfc3986 */
{
<PDIGIT : "%3" <DIGIT> >
| < UNRESERVED : <ALPHA> | <DIGIT> | "-" | "." | "_" | "~" >
| < PCT_ENCODED : "%" <HEXDIG> <HEXDIG> >
| < SUB_DELIMS : "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "=" >
}
////////////////////////////////////////////////////////////////////
// End of Lexical Scanner //
////////////////////////////////////////////////////////////////////
void pdigit() :
{}
{
( <DIGIT> | <PDIGIT> )
}
void utf8string() :
{}
{
( <UNRESERVED> | <PCT_ENCODED> | <TIMEPREFIX> | <TIMEUNIT> | <DEFTIMEFORMAT> | <XYWHPREFIX> | <XYWHUNIT> | <TRACKPREFIX> | <NAMEPREFIX> | <DIGIT> | <PDIGIT> )+
}
void parserUnit() :
{}
{
mediasegment()
<EOF>
}
void mediasegment() :
{}
{
namesegment() | axissegment()
}
void namesegment() :
{}
{
( <NAMEPREFIX> <EQ> nameparam() )
}
void nameparam() :
{}
{
utf8string()
}
void axissegment() :
{
boolean gottime = false;
boolean gotspace = false;
boolean gottrack = false;
}
{
// implement the grammar + the restriction in the prose
( timesegment() { gottime = true; }
| spacesegment() { gotspace = true; }
| tracksegment() { gottrack = true; }
)
( <AMP> ( timesegment() { if (gottime) throw new ParseException(); gottime = true; }
| spacesegment() { if (gotspace) throw new ParseException(); gotspace = true; }
| tracksegment() { if (gottrack) throw new ParseException(); gottrack = true; }
) )*
}
void timesegment() :
{}
{
<TIMEPREFIX> <EQ> timeparam()
}
void timeparam() :
{}
{
npttimedef() | othertimedef()
}
void npttimedef() :
{}
{
( <DEFTIMEFORMAT> <COLON> )? ( ( clocktime() ( <COMMA> clocktime() )? ) | ( <COMMA> clocktime() ) )
}
void clocktime() :
{}
{
( pdigit() )+ ( ( <DOT> ( pdigit() )* ( <TIMEUNIT> )? )
| ( <COLON> pdigit() pdigit() ( <COLON> pdigit() pdigit() )? ( <DOT> ( pdigit() )* )? ) )?
}
void othertimedef() :
{}
{
<TIMEFORMAT> <COLON> ( ( frametime() ( <COMMA> frametime() )? ) | ( <COMMA> frametime() ) )
}
void frametime() :
{}
{
( pdigit() )+ <COLON> pdigit() pdigit() <COLON> pdigit() pdigit() ( <COLON> pdigit() pdigit() ( <DOT> pdigit() pdigit() )? )?
}
void spacesegment() :
{}
{
xywhdef()
}
void xywhdef() :
{}
{
<XYWHPREFIX> <EQ> xywhparam()
}
void xywhparam() :
{}
{
( <XYWHUNIT> <COLON> )? ( pdigit() )+ <COMMA> ( pdigit() )+ <COMMA> ( pdigit() )+ <COMMA> ( pdigit() )+
}
void tracksegment() :
{}
{
<TRACKPREFIX> <EQ> trackparam()
}
void trackparam() :
{}
{
utf8string()
}