@@ -147,13 +147,13 @@ private String getText() {
147147
148148 // abnf: placeholder = expression / markup
149149 // abnf: expression = literal-expression
150- // abnf: / variable-expression
151- // abnf: / annotation-expression
150+ // abnf: / variable-expression
151+ // abnf: / annotation-expression
152152 // abnf: literal-expression = "{" [s] literal [s annotation] *(s attribute) [s] "}"
153153 // abnf: variable-expression = "{" [s] variable [s annotation] *(s attribute) [s] "}"
154154 // abnf: annotation-expression = "{" [s] annotation *(s attribute) [s] "}"
155155 // abnf: markup = "{" [s] "#" identifier *(s option) *(s attribute) [s] ["/"] "}" ; open and standalone
156- // abnf: / "{" [s] "/" identifier *(s option) *(s attribute) [s] "}" ; close
156+ // abnf: / "{" [s] "/" identifier *(s option) *(s attribute) [s] "}" ; close
157157 private MFDataModel .Expression getPlaceholder () throws MFParseException {
158158 int cp = input .peekChar ();
159159 if (cp != '{' ) {
@@ -168,9 +168,7 @@ private MFDataModel.Expression getPlaceholder() throws MFParseException {
168168 result = getMarkup ();
169169 } else if (cp == '$' ) {
170170 result = getVariableExpression ();
171- } else if (StringUtils .isFunctionSigil (cp )
172- || StringUtils .isPrivateAnnotationSigil (cp )
173- || StringUtils .isReservedAnnotationSigil (cp )) {
171+ } else if (StringUtils .isFunctionSigil (cp )) {
174172 result = getAnnotationExpression ();
175173 } else {
176174 result = getLiteralExpression ();
@@ -214,16 +212,8 @@ private MFDataModel.Annotation getAnnotation(boolean whitespaceRequired) throws
214212 checkCondition (identifier != null , "Annotation / function name missing" );
215213 Map <String , MFDataModel .Option > options = getOptions ();
216214 return new MFDataModel .FunctionAnnotation (identifier , options );
217- default : // reserved && private
218- if (StringUtils .isReservedAnnotationSigil (cp )
219- || StringUtils .isPrivateAnnotationSigil (cp )) {
220- cp = input .readCodePoint ();
221- // The sigil is part of the body.
222- // Safe to cast to char, the code point is in BMP
223- identifier = (char ) cp + getIdentifier ();
224- String body = getReservedBody ();
225- return new MFDataModel .UnsupportedAnnotation (identifier + body );
226- }
215+ default :
216+ // OK to continue and return null, it is an error.
227217 }
228218 input .gotoPosition (position );
229219 return null ;
@@ -246,7 +236,7 @@ private MFDataModel.Annotation getMarkupAnnotation() throws MFParseException {
246236 Map <String , MFDataModel .Option > options = getOptions ();
247237 return new MFDataModel .FunctionAnnotation (identifier , options );
248238 default :
249- // reserved, private, function, something else,
239+ // function or something else,
250240 return null ;
251241 }
252242 }
@@ -290,17 +280,14 @@ private MFDataModel.Expression getAnnotationExpression() throws MFParseException
290280 if (annotation instanceof MFDataModel .FunctionAnnotation ) {
291281 return new MFDataModel .FunctionExpression (
292282 (MFDataModel .FunctionAnnotation ) annotation , attributes );
293- } else if (annotation instanceof MFDataModel .UnsupportedAnnotation ) {
294- return new MFDataModel .UnsupportedExpression (
295- (MFDataModel .UnsupportedAnnotation ) annotation , attributes );
296283 } else {
297284 error ("Unexpected annotation : " + annotation );
298285 }
299286 return null ;
300287 }
301288
302289 // abnf: markup = "{" [s] "#" identifier *(s option) *(s attribute) [s] ["/"] "}" ; open and standalone
303- // abnf: / "{" [s] "/" identifier *(s option) *(s attribute) [s] "}" ; close
290+ // abnf: / "{" [s] "/" identifier *(s option) *(s attribute) [s] "}" ; close
304291 private MFDataModel .Markup getMarkup () throws MFParseException {
305292 int cp = input .peekChar (); // consume the '{'
306293 checkCondition (cp == '#' || cp == '/' , "Should not happen. Expecting a markup." );
@@ -370,39 +357,6 @@ private MFDataModel.Attribute getAttribute() throws MFParseException {
370357 return null ;
371358 }
372359
373- // abnf: reserved-body = *([s] 1*(reserved-char / reserved-escape / quoted))
374- // abnf: reserved-escape = backslash ( backslash / "{" / "|" / "}" )
375- private String getReservedBody () throws MFParseException {
376- int spaceCount = skipWhitespaces ();
377- StringBuilder result = new StringBuilder ();
378- while (true ) {
379- int cp = input .readCodePoint ();
380- if (StringUtils .isReservedChar (cp )) {
381- result .appendCodePoint (cp );
382- } else if (cp == '\\' ) {
383- cp = input .readCodePoint ();
384- checkCondition (
385- cp == '{' || cp == '|' || cp == '}' ,
386- "Invalid escape sequence. Only \\ {, \\ | and \\ } are valid here." );
387- result .append (cp );
388- } else if (cp == '|' ) {
389- input .backup (1 );
390- MFDataModel .Literal quoted = getQuotedLiteral ();
391- result .append (quoted .value );
392- } else if (cp == EOF ) {
393- return result .toString ();
394- } else {
395- if (result .length () == 0 ) {
396- input .backup (spaceCount + 1 );
397- return "" ;
398- } else {
399- input .backup (1 );
400- return result .toString ();
401- }
402- }
403- }
404- }
405-
406360 // abnf: identifier = [namespace ":"] name
407361 // abnf: namespace = name
408362 // abnf: name = name-start *name-char
@@ -650,7 +604,7 @@ private MFDataModel.SelectMessage getMatch(List<MFDataModel.Declaration> declara
650604 // abnf: key = literal / "*"
651605 private MFDataModel .Variant getVariant () throws MFParseException {
652606 List <MFDataModel .LiteralOrCatchallKey > keys = new ArrayList <>();
653- // abnf variant = key *(s key) [s] quoted-pattern
607+ // abnf: variant = key *(s key) [s] quoted-pattern
654608 while (true ) {
655609 // Space is required between keys
656610 MFDataModel .LiteralOrCatchallKey key = getKey (!keys .isEmpty ());
@@ -705,8 +659,6 @@ private static class MatchDeclaration implements MFDataModel.Declaration {
705659
706660 // abnf: input-declaration = input [s] variable-expression
707661 // abnf: local-declaration = local s variable [s] "=" [s] expression
708- // abnf: reserved-statement = reserved-keyword [s reserved-body] 1*([s] expression)
709- // abnf: reserved-keyword = "." name
710662 private MFDataModel .Declaration getDeclaration () throws MFParseException {
711663 int position = input .getPosition ();
712664 skipOptionalWhitespaces ();
@@ -745,32 +697,8 @@ private MFDataModel.Declaration getDeclaration() throws MFParseException {
745697 break ;
746698 case "match" :
747699 return new MatchDeclaration ();
748- default : // abnf: reserved-statement = reserved-keyword [s reserved-body] 1*([s] expression)
749- skipOptionalWhitespaces ();
750- String body = getReservedBody ();
751- List <MFDataModel .Expression > expressions = new ArrayList <>();
752- while (true ) {
753- skipOptionalWhitespaces ();
754- // Look ahead to detect the end of the unsupported statement
755- // (next token either begins a placeholder or begins a complex body)
756- cp = input .readCodePoint ();
757- int cp1 = input .readCodePoint ();
758- if (cp == '{' && cp1 == '{' ) {
759- // End of unsupported statement
760- input .backup (2 );
761- break ;
762- } else {
763- input .backup (2 );
764- }
765- expression = getPlaceholder ();
766- // This also covers != null
767- if (expression instanceof MFDataModel .VariableExpression ) {
768- expressions .add (expression );
769- } else {
770- break ;
771- }
772- }
773- return new MFDataModel .UnsupportedStatement (declName , body , expressions );
700+ default :
701+ // OK to continue and return null, it is an error.
774702 }
775703 return null ;
776704 }
0 commit comments