0

我有以下语法。它应该接受标题中注释中显示的字符串。它不是。我一定错过了一些基本的东西。关于如何调试的提示也将不胜感激。

/*
  Should accept:
    b
    a:b
    a:b^10
    b^10
  Should not accept:
    :b
    a:
    a:^10
*/
grammar test;

filter:
  boostedField EOF
  ;

boostedField
  : qualifiedField (CARET NUMBER)?
  ;

qualifiedField
  : (FIELDNAME COLON)? term
  ;

term
  : TERM 
  ;

FIELDNAME: (LETTER | UNDERSCORE) (ALPHANUM | UNDERSCORE)* ;
NUMBER : NUM_CHAR+ ('.' NUM_CHAR+)? ;
COLON : ':' ;
CARET : '^' ;
WS  : (' ' | '\t' | '\n' | '\r' | '\u3000') -> skip ;
UNDERSCORE: '_' ;

// a term may not have a colon or a caret (unless escaped)
TERM : TERM_START_CHAR TERM_CHAR*;
fragment TERM_START_CHAR
  : ~( ' '  | '\t' | '\n' | '\r' | '\u3000' | ':'  | '^'  ) ;  
fragment TERM_CHAR : (TERM_START_CHAR | ESCAPED_CHAR) ;
fragment ESCAPED_CHAR :  ( '\\' . ) ;
fragment NUM_CHAR: '0'..'9';
fragment LETTER: 'a'..'z' | 'A'..'Z' ;
fragment ALPHANUM: LETTER | NUM_CHAR;
4

0 回答 0