source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj@ 6897

Last change on this file since 6897 was 6897, checked in by stoecker, 10 years ago

see #9778 - use TLS for JOSM website access

File size: 19.2 KB
RevLine 
[3848]1// License: GPL. For details, see LICENSE file.
2options {
3 STATIC = false;
[6521]4 OUTPUT_DIRECTORY = "parsergen";
[3848]5}
6
7PARSER_BEGIN(MapCSSParser)
[4252]8package org.openstreetmap.josm.gui.mappaint.mapcss.parsergen;
[3848]9
10import java.awt.Color;
11import java.util.ArrayList;
12import java.util.List;
13
[3967]14import org.openstreetmap.josm.gui.mappaint.Keyword;
[3848]15import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
[4069]16import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
[3848]17import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
18import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
19import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
20import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
21import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
[5705]22import org.openstreetmap.josm.gui.mappaint.mapcss.ExpressionFactory;
23import org.openstreetmap.josm.gui.mappaint.mapcss.LiteralExpression;
[4069]24import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException;
[4011]25import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
[3902]26import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
[4069]27import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector;
[6740]28import org.openstreetmap.josm.tools.ColorHelper;
[3848]29import org.openstreetmap.josm.tools.Pair;
[5577]30import org.openstreetmap.josm.tools.Utils;
[6248]31import org.openstreetmap.josm.Main;
[3848]32
[6897]33/*************
34 * <pre>
35 * Parser definitions
36 *
37 * rule
38 * _______________________|______________________________
39 * | |
40 * selector declaration
41 * _________|___________________ _________|____________
42 * | | | |
43 *
44 * way|z11-12[highway=residential] { color: red; width: 3 }
45 *
46 * |_____||___________________| |_________|
47 * | | |
48 * zoom condition instruction
49 *
50 * more general:
51 *
52 * way|z13-[a=b][c=d]::subpart, way|z-3[u=v]:closed::subpart2 { p1 : val; p2 : val; }
53 *
54 * 'val' can be a literal, or an expression like "prop(width, default) + 0.8".
55 *
56 * {@literal @media} { ... } queries are supported, following http://www.w3.org/TR/css3-mediaqueries/#syntax
57 *
58 * media_query
59 * ___________________________|_______________________________
60 * | |
61 * {@literal @media} all and (min-josm-version: 7789) and (max-josm-version: 7790), all and (user-agent: xyz) { ... }
62 * |______________________|
63 * |
64 * media_expression
65 * </pre>
66 */
67
[3848]68public class MapCSSParser {
[3863]69 MapCSSStyleSource sheet;
[3848]70}
71PARSER_END(MapCSSParser)
72
73/*************
74 * Token definitions
75 */
76
77<DEFAULT>
[6896]78TOKEN [IGNORE_CASE]:
79{
80 /* Special keywords in some contexts, ordinary identifiers in other contexts.
81 Don't use the javacc token contexts (except DEFAULT and COMMENT) because
82 they complicate error handling. Instead simply add a parsing rule <code>ident()</code>
83 that parses the IDENT token and in addition all the keyword tokens. */
84 < AND: "and" >
85| < SET: "set" >
86| < NOT: "not" >
87| < MEDIA: "@media" >
88}
89
90<DEFAULT>
[3848]91TOKEN:
92{
[6896]93 < IDENT: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","-","0"-"9"] )* >
[3848]94| < UINT: ["1"-"9"] ( ["0"-"9"] )* >
95| < UFLOAT: ( ["0"-"9"] )+ ( "." ( ["0"-"9"] )+ )? >
[3876]96| < STRING: "\"" ( [" ","!","#"-"[","]"-"~","\u0080"-"\uFFFF"] | "\\\"" | "\\\\" )* "\"" >
[6686]97| < #PREDEFINED: "\\" ["d","D","s","S","w","W"] >
98| < #REGEX_CHAR_WITHOUT_STAR: [" "-")","+"-".","0"-"[","]"-"~","\u0080"-"\uFFFF"] | "\\/" | "\\\\" | "\\[" | "\\]" | "\\+" | "\\." | "\\'" | "\\\"" | <PREDEFINED> >
[3876]99| < REGEX: "/" <REGEX_CHAR_WITHOUT_STAR> ( <REGEX_CHAR_WITHOUT_STAR> | "*" )* "/" >
[3848]100| < #H: ["0"-"9","a"-"f","A"-"F"] >
[6774]101| < HEXCOLOR: "#" ( <H><H><H><H><H><H><H><H> | <H><H><H><H><H><H> | <H><H><H> ) >
[3848]102| < S: ( " " | "\t" | "\n" | "\r" | "\f" )+ >
103| < STAR: "*" >
104| < SLASH: "/" >
105| < LBRACE: "{" >
106| < RBRACE: "}" >
107| < LSQUARE: "[" >
108| < RSQUARE: "]" >
109| < LPAR: "(" >
110| < RPAR: ")" >
[3867]111| < GREATER_EQUAL: ">=" >
112| < LESS_EQUAL: "<=" >
113| < GREATER: ">" >
114| < LESS: "<" >
[3848]115| < EQUAL: "=" >
116| < EXCLAMATION: "!" >
[3876]117| < TILDE: "~" >
[3848]118| < COLON: ":" >
119| < DCOLON: "::" >
120| < SEMICOLON: ";" >
121| < COMMA: "," >
[3856]122| < PIPE: "|" >
[3848]123| < PIPE_Z: "|z" >
124| < PLUS: "+" >
125| < MINUS: "-" >
[3856]126| < AMPERSAND: "&" >
127| < QUESTION: "?" >
[3876]128| < DOLLAR: "$" >
129| < CARET: "^" >
[6560]130| < FULLSTOP: "." >
[6609]131| < ELEMENT_OF: "∈" >
[6613]132| < CROSSING: "⧉" >
[3848]133| < COMMENT_START: "/*" > : COMMENT
134| < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from
135}
136
137<COMMENT>
138TOKEN:
139{
140 < COMMENT_END: "*/" > : DEFAULT
141}
142
143<COMMENT>
144SKIP:
145{
146 < ~[] >
147}
148
149int uint() :
150{
151 Token i;
152}
153{
154 i=<UINT> { return Integer.parseInt(i.image); }
155}
156
[3911]157int int_() :
158{
159 int i;
160}
161{
162 <MINUS> i=uint() { return -i; } | i=uint() { return i; }
163}
164
[3848]165float ufloat() :
166{
167 Token f;
168}
169{
170 ( f=<UFLOAT> | f=<UINT> )
171 { return Float.parseFloat(f.image); }
172}
173
[3876]174float float_() :
175{
176 float f;
177}
178{
179 <MINUS> f=ufloat() { return -f; } | f=ufloat() { return f; }
180}
181
[3848]182String string() :
183{
184 Token t;
185}
186{
187 t=<STRING>
[3876]188 { return t.image.substring(1, t.image.length() - 1).replace("\\\"", "\"").replace("\\\\", "\\"); }
[3848]189}
190
[6896]191String ident():
192{
193 Token t;
194 String s;
195}
196{
197 ( t=<IDENT> | t=<SET> | t=<NOT> | t=<AND> ) { return t.image; }
198}
199
[3848]200String string_or_ident() :
201{
202 Token t;
203 String s;
204}
205{
[6896]206 ( s=ident() | s=string() ) { return s; }
[3848]207}
208
[3876]209String regex() :
210{
211 Token t;
212}
213{
214 t=<REGEX>
215 { return t.image.substring(1, t.image.length() - 1); }
216}
217
[3848]218/**
219 * white-space
220 */
221void s() :
222{
223}
224{
225 ( <S> )?
226}
227
228/**
229 * mix of white-space and comments
230 */
231void w() :
232{
233}
234{
[3876]235 ( <S> | <COMMENT_START> <COMMENT_END> )*
[3848]236}
237
238/**
[6830]239 * comma delimited list of floats (at least 2, all &gt;= 0)
[3848]240 */
[3856]241List<Float> float_array() :
[3848]242{
243 float f;
244 List<Float> fs = new ArrayList<Float>();
245}
246{
247 f=ufloat() { fs.add(f); }
248 (
249 <COMMA> s()
250 f=ufloat() { fs.add(f); }
251 )+
252 {
[3856]253 return fs;
[3848]254 }
255}
256
257/**
258 * root
259 */
260void sheet(MapCSSStyleSource sheet):
261{
262 MapCSSRule r;
263}
264{
[3863]265 { this.sheet = sheet; }
[3848]266 w()
[6896]267 rules(true) ( media() w() rules(true) )*
268 <EOF>
269}
270
271void media():
272{
273 boolean pass = false;
274 boolean q;
275 boolean empty = true;
276}
277{
278 <MEDIA> w()
279 ( q=media_query() { pass = pass || q; empty = false; }
280 ( <COMMA> w() q=media_query() { pass = pass || q; } )*
281 )?
282 <LBRACE> w()
283 rules(empty || pass)
284 <RBRACE>
285}
286
287boolean media_query():
288{
289 Token t;
290 String mediatype = "all";
291 boolean pass = true;
292 boolean invert = false;
293 boolean e;
294}
295{
296 ( <NOT> { invert = true; } w() )?
[3876]297 (
[6896]298 t=<IDENT> { mediatype = t.image.toLowerCase(); } w()
299 ( <AND> w() e=media_expression() { pass = pass && e; } w() )*
300 |
301 e=media_expression() { pass = pass && e; } w()
302 ( <AND> w() e=media_expression() { pass = pass && e; } w() )*
303 )
304 {
305 if (!"all".equals(mediatype)) {
306 pass = false;
307 }
308 return invert ? (!pass) : pass;
309 }
310}
311
312boolean media_expression():
313{
314 Token t;
315 String feature;
316 Object val = null;
317}
318{
319 <LPAR> w() t=<IDENT> { feature = t.image; } w() ( <COLON> w() val=literal() )? <RPAR>
320 { return this.sheet.evalMediaExpression(feature, val); }
321}
322
323void rules(boolean add):
324{
325 MapCSSRule r;
326}
327{
328 (
[3876]329 try {
[6896]330 r=rule() { if (add && r != null) { sheet.rules.add(r); } } w()
[4069]331 } catch (MapCSSException mex) {
332 error_skipto(RBRACE, mex);
333 w();
[3876]334 } catch (ParseException ex) {
[4069]335 error_skipto(RBRACE, null);
[3876]336 w();
337 }
338 )*
[3848]339}
340
341MapCSSRule rule():
342{
343 List<Selector> selectors = new ArrayList<Selector>();
344 Selector sel;
345 List<Instruction> decl;
346}
347{
[3902]348 sel=child_selector() { selectors.add(sel); }
[3876]349 (
350 <COMMA> w()
[3902]351 sel=child_selector() { selectors.add(sel); }
[3876]352 )*
[3848]353 decl=declaration()
354 { return new MapCSSRule(selectors, decl); }
355}
356
[3902]357Selector child_selector() :
358{
[6607]359 Selector.ChildOrParentSelectorType type = null;
[4069]360 Condition c;
361 List<Condition> conditions = new ArrayList<Condition>();
362 Selector selLeft;
363 LinkSelector selLink = null;
364 Selector selRight = null;
[3902]365}
366{
[4069]367 selLeft=selector() w()
[3902]368 (
[6607]369 (
370 ( <GREATER> { type = Selector.ChildOrParentSelectorType.CHILD; } | <LESS> { type = Selector.ChildOrParentSelectorType.PARENT; } )
371 ( ( c=condition(Context.LINK) | c=class_or_pseudoclass(Context.LINK) ) { conditions.add(c); } )*
372 |
[6609]373 <ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.ELEMENT_OF; }
[6613]374 |
375 <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; }
[6607]376 )
[4069]377 { selLink = new LinkSelector(conditions); }
378 w()
379 selRight=selector() w()
[3902]380 )?
[6607]381 { return selRight != null ? new ChildOrParentSelector(selLeft, selLink, selRight, type) : selLeft; }
[3902]382}
383
[3848]384Selector selector() :
385{
386 Token base;
387 Condition c;
388 Pair<Integer, Integer> r = null;
389 List<Condition> conditions = new ArrayList<Condition>();
390 String sub = null;
391}
392{
393 ( base=<IDENT> | base=<STAR> )
394 ( r=zoom() )?
[6560]395 ( ( c=condition(Context.PRIMITIVE) | c=class_or_pseudoclass(Context.PRIMITIVE) ) { conditions.add(c); } )*
[3848]396 ( sub=subpart() )?
[3902]397 { return new GeneralSelector(base.image, r, conditions, sub); }
[3848]398}
399
400Pair<Integer, Integer> zoom() :
401{
402 Integer min = 0;
403 Integer max = Integer.MAX_VALUE;
404}
405{
406 <PIPE_Z>
407 (
[3876]408 <MINUS> max=uint()
409 |
[4280]410 LOOKAHEAD(2)
411 min=uint() <MINUS> ( max=uint() )?
412 |
413 min=uint() { max = min; }
[3848]414 )
415 { return new Pair<Integer, Integer>(min, max); }
416}
417
[4069]418Condition condition(Context context) :
[3848]419{
[3856]420 Condition c;
421 Expression e;
422}
423{
[3911]424 <LSQUARE> s()
[3876]425 (
[4069]426 LOOKAHEAD( simple_key_condition(context) s() <RSQUARE> )
427 c=simple_key_condition(context) s() <RSQUARE> { return c; }
[3876]428 |
[4069]429 LOOKAHEAD( simple_key_value_condition(context) s() <RSQUARE> )
430 c=simple_key_value_condition(context) s() <RSQUARE> { return c; }
[3876]431 |
[6560]432 e=expression() <RSQUARE> { return Condition.createExpressionCondition(e, context); }
[3856]433 )
434}
435
[3902]436String tag_key() :
437{
[6896]438 String s, s2;
[3902]439 Token t;
440}
441{
442 s=string() { return s; }
443 |
[6896]444 s=ident() ( <COLON> s2=ident() { s += ':' + s2; } )* { return s; }
[3902]445}
446
[4069]447Condition simple_key_condition(Context context) :
[3856]448{
[3848]449 boolean not = false;
[6547]450 Condition.KeyMatchType matchType = null;;
[3848]451 String key;
452}
453{
454 ( <EXCLAMATION> { not = true; } )?
[6547]455 (
456 { matchType = Condition.KeyMatchType.REGEX; } key = regex()
457 |
458 key = tag_key()
459 )
460 ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { matchType = Condition.KeyMatchType.FALSE; } )?
461 ( <QUESTION> { matchType = Condition.KeyMatchType.TRUE; } )?
[6560]462 { return Condition.createKeyCondition(key, not, matchType, context); }
[3848]463}
464
[4069]465Condition simple_key_value_condition(Context context) :
[3856]466{
467 String key;
468 String val;
[3876]469 float f;
[3911]470 int i;
[3876]471 Condition.Op op;
[6554]472 boolean considerValAsKey = false;
[3856]473}
474{
[3911]475 key=tag_key() s()
[3876]476 (
[6554]477 LOOKAHEAD(3)
478 (
479 <EQUAL> <TILDE> { op=Condition.Op.REGEX; }
480 |
481 <EXCLAMATION> <TILDE> { op=Condition.Op.NREGEX; }
482 )
483 s()
484 ( <STAR> { considerValAsKey=true; } )?
485 val=regex()
[3911]486 |
[3876]487 (
[3911]488 <EXCLAMATION> <EQUAL> { op=Condition.Op.NEQ; }
[3876]489 |
490 <EQUAL> { op=Condition.Op.EQ; }
491 |
[3912]492 <TILDE> <EQUAL> { op=Condition.Op.ONE_OF; }
[3876]493 |
[3912]494 <CARET> <EQUAL> { op=Condition.Op.BEGINS_WITH; }
[3876]495 |
[3912]496 <DOLLAR> <EQUAL> { op=Condition.Op.ENDS_WITH; }
[3876]497 |
[3912]498 <STAR> <EQUAL> { op=Condition.Op.CONTAINS; }
[3876]499 )
[3911]500 s()
[6554]501 ( <STAR> { considerValAsKey=true; } )?
[3911]502 (
503 LOOKAHEAD(2)
504 i=int_() { val=Integer.toString(i); }
505 |
506 f=float_() { val=Float.toString(f); }
507 |
508 val=string_or_ident()
509 )
[3876]510 |
511 (
512 <GREATER_EQUAL> { op=Condition.Op.GREATER_OR_EQUAL; }
513 |
514 <GREATER> { op=Condition.Op.GREATER; }
515 |
516 <LESS_EQUAL> { op=Condition.Op.LESS_OR_EQUAL; }
517 |
518 <LESS> { op=Condition.Op.LESS; }
519 )
[3911]520 s()
521 f=float_() { val=Float.toString(f); }
[3876]522 )
[6560]523 { return Condition.createKeyValueCondition(key, val, op, context, considerValAsKey); }
[3856]524}
525
[6560]526Condition class_or_pseudoclass(Context context) :
[3848]527{
[6896]528 String s;
[3848]529 boolean not = false;
[6560]530 boolean pseudo;
[3848]531}
532{
[3888]533 ( <EXCLAMATION> { not = true; } )?
[6560]534 (
535 <FULLSTOP> { pseudo = false; }
536 |
537 <COLON> { pseudo = true; }
538 )
[6896]539 s=ident()
[6560]540 { return pseudo
[6896]541 ? Condition.createPseudoClassCondition(s, not, context)
542 : Condition.createClassCondition(s, not, context); }
[3848]543}
544
545String subpart() :
546{
[6896]547 String s;
[3848]548}
549{
[3876]550 <DCOLON>
[6896]551 ( s=ident() { return s; } | <STAR> { return "*"; } )
[3848]552}
553
554List<Instruction> declaration() :
555{
556 List<Instruction> ins = new ArrayList<Instruction>();
557 Instruction i;
558 Token key;
[6560]559 Object val = null;
[3848]560}
561{
[3876]562 <LBRACE> w()
[3848]563 (
[6560]564 (
[6561]565 <SET> w()
566 (<FULLSTOP>)? // specification allows "set .class" to set "class". we also support "set class"
567 key=<IDENT> w()
568 ( <EQUAL> val=expression() )?
[6611]569 { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); }
[6561]570 ( <RBRACE> { return ins; } | <SEMICOLON> w() )
[6560]571 )
[6561]572 |
[3876]573 key=<IDENT> w() <COLON> w()
574 (
575 LOOKAHEAD( float_array() w() ( <SEMICOLON> | <RBRACE> ) )
576 val=float_array()
[6611]577 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
[3876]578 w()
579 ( <RBRACE> { return ins; } | <SEMICOLON> w() )
580 |
581 LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) )
582 val=expression()
[6611]583 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
[3876]584 ( <RBRACE> { return ins; } | <SEMICOLON> w() )
585 |
[6611]586 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
[3876]587 )
588 )*
589 <RBRACE>
590 { return ins; }
[3848]591}
592
593Expression expression():
594{
595 List<Expression> args = new ArrayList<Expression>();
596 Expression e;
597 String op = null;
598}
599{
600 (
[3876]601 <EXCLAMATION> { op = "not"; } w() e=primary() { args.add(e); } w()
[3867]602 |
[3876]603 <MINUS> { op = "minus"; } w() e=primary() { args.add(e); } w()
[3867]604 |
[3876]605
[3867]606 (
607 e=primary() { args.add(e); } w()
608 (
609 ( <PLUS> { op = "plus"; } w() e=primary() { args.add(e); } w() )+
610 |
611 ( <STAR> { op = "times"; } w() e=primary() { args.add(e); } w() )+
612 |
613 ( <MINUS> { op = "minus"; } w() e=primary() { args.add(e); } w() )+
614 |
615 ( <SLASH> { op = "divided_by"; } w() e=primary() { args.add(e); } w() )+
616 |
[3876]617 <GREATER_EQUAL> { op = "greater_equal"; } w() e=primary() { args.add(e); } w()
[3867]618 |
[3876]619 <LESS_EQUAL> { op = "less_equal"; } w() e=primary() { args.add(e); } w()
[3867]620 |
[3876]621 <GREATER> { op = "greater"; } w() e=primary() { args.add(e); } w()
[3867]622 |
[3876]623 <EQUAL> ( <EQUAL> )? { op = "equal"; } w() e=primary() { args.add(e); } w()
[3867]624 |
[3876]625 <LESS> { op = "less"; } w() e=primary() { args.add(e); } w()
[3867]626 |
[3876]627 <AMPERSAND> <AMPERSAND> { op = "and"; } w() e=primary() { args.add(e); } w()
[3867]628 |
[3876]629 <PIPE> <PIPE> { op = "or"; } w() e=primary() { args.add(e); } w()
[3867]630 |
[3876]631 <QUESTION> { op = "cond"; } w() e=primary() { args.add(e); } w() <COLON> w() e=primary() { args.add(e); } w()
[3867]632 )?
633 )
634 )
[3848]635 {
[3856]636 if (op == null)
[3848]637 return args.get(0);
[5705]638 return ExpressionFactory.createFunctionExpression(op, args);
[3848]639 }
640}
641
642Expression primary() :
643{
644 Expression nested;
[5705]645 Expression fn;
[3848]646 Object lit;
647}
648{
[3971]649 LOOKAHEAD(3) // both function and identifier start with an identifier (+ optional whitespace)
[3848]650 fn=function() { return fn; }
651 |
652 lit=literal() { return new LiteralExpression(lit); }
653 |
[3876]654 <LPAR> w() nested=expression() <RPAR> { return nested; }
[3848]655}
656
[5705]657Expression function() :
[3848]658{
659 Token tmp;
660 Expression arg;
661 String name;
662 List<Expression> args = new ArrayList<Expression>();
663}
664{
[6896]665 name=ident() w()
[3848]666 <LPAR> w()
[3856]667 (
668 arg=expression() { args.add(arg); }
669 ( <COMMA> w() arg=expression() { args.add(arg); } )*
670 )?
[3848]671 <RPAR>
[5705]672 { return ExpressionFactory.createFunctionExpression(name, args); }
[3848]673}
674
675Object literal() :
676{
[3967]677 String val;
[6740]678 Token t, t2;
[3848]679 float f;
680}
681{
[6740]682 LOOKAHEAD(2)
683 t2=<IDENT> t=<HEXCOLOR>
684 { return Main.pref.getColor("mappaint." + (sheet == null ? "MapCSS" : sheet.title) + "." + t2.image, ColorHelper.html2color(t.image)); }
685 |
[3967]686 t=<IDENT> { return new Keyword(t.image); }
[3848]687 |
[3967]688 val=string() { return val; }
689 |
[3876]690 <PLUS> f=ufloat() { return new Instruction.RelativeFloat(f); }
[3848]691 |
692 f=ufloat() { return f; }
693 |
[6740]694 t=<HEXCOLOR> { return ColorHelper.html2color(t.image); }
[3848]695}
696
697JAVACODE
[4069]698void error_skipto(int kind, MapCSSException me) {
[3893]699 if (token.kind == EOF)
700 throw new ParseException("Reached end of file while parsing");
[4069]701
702 Exception e = null;
703 ParseException pe = generateParseException();
704
705 if (me != null) {
706 me.setLine(pe.currentToken.next.beginLine);
707 me.setColumn(pe.currentToken.next.beginColumn);
708 e = me;
709 } else {
710 e = new ParseException(pe.getMessage()); // prevent memory leak
711 }
712
[6248]713 Main.error("Skipping to the next rule, because of an error:");
714 Main.error(e);
[3863]715 if (sheet != null) {
[4069]716 sheet.logError(e);
[3863]717 }
718 Token t;
719 do {
720 t = getNextToken();
[3867]721 } while (t.kind != kind && t.kind != EOF);
722 if (t.kind == EOF)
723 throw new ParseException("Reached end of file while parsing");
[3848]724}
725
[3876]726JAVACODE
727/**
728 * read everything to the next semicolon
729 */
730String readRaw() {
731 Token t;
732 StringBuilder s = new StringBuilder();
733 while (true) {
734 t = getNextToken();
[3893]735 if ((t.kind == S || t.kind == STRING || t.kind == UNEXPECTED_CHAR) &&
736 t.image.contains("\n")) {
737 ParseException e = new ParseException(String.format("Warning: end of line while reading an unquoted string at line %s column %s.", t.beginLine, t.beginColumn));
[6248]738 Main.error(e);
[3893]739 if (sheet != null) {
740 sheet.logError(e);
741 }
742 }
[3876]743 if (t.kind == SEMICOLON || t.kind == EOF)
744 break;
745 s.append(t.image);
746 }
747 if (t.kind == EOF)
748 throw new ParseException("Reached end of file while parsing");
749 return s.toString();
750}
751
Note: See TracBrowser for help on using the repository browser.