2

I use ANTLRWorks for a simple grammar:

grammar boolean;

// [...]
lowercase_string
        :   ('a'..'z')+ ;

However, the lowercase_string doesn't match foobar according to the Interpreter (MismatchedSetException(10!={}). Ideas?

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
Reactormonk
  • 21,472
  • 14
  • 74
  • 123

1 Answers1

5

You can't use the .. operator inside parser rules like that. To match the range 'a' to 'z', create a lexer rule for it (lexer rules start with a capital).

Try it like this:

lowercase_string
  :  Lower+ 
  ;

Lower
  :  'a'..'z'
  ;

or:

lowercase_string
  :  Lower
  ;

Lower
  :  'a'..'z'+
  ;

Also see this previous Q&A: Practical difference between parser rules and lexer rules in ANTLR?

Community
  • 1
  • 1
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288