Skip to content

ANTLR backend: malformed lexer file when using subtraction in regular expression #276

Closed

Description

@andreasabel
Start. S ::= Name ;
token Name (char - [ "(){};.@\" \n\t" ]) + ;

This yields a ANTLR lexer file containing:

// This Antlr4 file was machine-generated by the BNF converter
lexer grammar testLexer;
// Predefined regular expressions in BNFC
fragment LETTER  : CAPITAL | SMALL ;
fragment CAPITAL : [A-Z\u00C0-\u00D6\u00D8-\u00DE] ;
fragment SMALL   : [a-z\u00DF-\u00F6\u00F8-\u00FF] ;
fragment DIGIT   : [0-9] ;


Name : ~[
 "().;@{}]+;





// Whitespace
WS : (' ' | '\r' | '\t' | '\n' | '\f')+ ->  skip;
// Escapable sequences
fragment
Escapable : ('"' | '\\' | 'n' | 't' | 'r' | 'f');
ErrorToken : . ;

This raises the following errors:

java  org.antlr.v4.Tool -lib test -package test test/testLexer.g4
error(50): testLexer.g4:10:8: syntax error: '[' came as a complete surprise to me
error(50): testLexer.g4:11:1: syntax error: '"' came as a complete surprise to me
error(50): testLexer.g4:11:3: syntax error: ')' came as a complete surprise to me while looking for lexer rule element
error(50): testLexer.g4:11:6: syntax error: '@' came as a complete surprise to me
error(50): testLexer.g4:11:9: syntax error: ']' came as a complete surprise to me

Activity

  1. added this to the 2.8.4 milestone on Dec 15, 2019
  2. self-assigned this
    on Dec 15, 2019
  3. added a commit that references this issue on Dec 15, 2019
  4. added
    lexer
    on Dec 15, 2019
  5. added a commit that references this issue on Jan 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Java/ANTLRbuglexer

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions