0

I have the following Grammar. It should recognize a string delimited by the single quote character ('). However, this does not work as intended. In ANTLWorks, the console window shows the following warning:

[10:46:50] error(139): Test.g:9:15: set complement is empty

Why is that and how can I match a string which can contain any charcters but the delimiter?

grammar Test;
options 
{

    language=CSharp3;
    output=AST;
    ASTLabelType=CommonTree;
}
string: '\'' (~('\''))* '\'';
Seki
  • 10,763
  • 6
  • 47
  • 68
user1691896
  • 105
  • 6

1 Answers1

0

You must realize there's a strict separation between tokenizing and parsing in ANTLR. Your string rule should be a lexer rule, which should then be used in a parser rule:

grammar Test;

parse  : STRING EOF;

STRING : '\'' (~('\''))* '\'';

Also see: Practical difference between parser rules and lexer rules in ANTLR?

Community
  • 1
  • 1
Bart Kiers
  • 161,100
  • 35
  • 287
  • 281