Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ANTLR4 lexer yielding 'chars used multiple times in set' error

I’m adding a rule to my ANTLR4 lexer that looks like [/a-zA-Z0-9_?+-.*\u005B-\u005E\u007B-\u007D]+ and it lexes just fine. However, when I add \u002C to it, regardless of where I add that character, or when I add a literal , to it, I get the same error:

chars ',' used multiple times in set [/a-zA-Z0-9_?+-.*\u005B-\u005E\u007B-\u007D\u002C]

There is only one , in the set regardless, so I’m unsure what might be causing the error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The - in +-. sequence is interpreted in the same way as in A-Z, i.e. as a meta-character that designates a range, not literally as a dash character. The range between + and . includes ,:

2B: +
2C: ,
2D: -
2E: .

If you would like to interpret the dash literally, include it as the last character, right before the closing square bracket.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading