Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2014
    Location
    Lynnwood, WA
    Posts
    46

    Question ANTLR String Lexer Rule

    I have spent the last hour going batty trying to find what I had missed in the lecture of video "Chapter 9 - Building CGS: Finishing our Combined ANTLR Grammar" ~@ 42:30. I finally figured out that in my not parens, i was missing the quote tick.

    When I read this lexer rule, i dont understand it, can someone explain in more detail:
    Code:
    STRING	:	'\'' ( ~('\n' | '\r' | '\'') )* '\'';
    I read this as: find a single quote, then exclude zero to many CR, LF or single quotes (while saving everything else as part of the string), then find another single quote.

    But when i read this, i dont understand how it knows to dump single quotes inside a string, then not dump the one on the end..? when i dont have i the quote in, i get a mismatched token error that is so vague i could not debug it to save my life.

    in short, why is this not acceptable:
    Code:
    STRING	:	'\'' ( ~('\n' | '\r') )* '\'';

  2. #2
    Join Date
    Jan 2014
    Location
    Lynnwood, WA
    Posts
    46
    nothing like typing up a question to make you think about what you're asking.

    I've solved my question, so ill leave it up incase anyone else is/gets confused on it:

    anything inside the ~() is considered the 'end of string' symbol. so in my case, without the ', i never know when to stop my string, unless of course i used \n or \r as the stop points.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •