Parsing strings and other various basic types


Maybe I don't know how to search for it exactly or I'm just unexperienced enough not to recognize it when I see it in other examples out there, but how to I make GrammarKit parse the example below properly:

/* demo */ package "demo" // Demo import "demo" import ab "demo" import (     "demo"     "demo2"     dm "demo3" )

My problem is trying to parse things like:

  • ab "demo"
  • "demo" should be ok but " demo" shouldn't be ok
  • "demo" should be ok but "demo _CR/LF_ another_line" shouldn't be ok (where _CR/LF_ means new line).

What I've got so far can be seen here:

Kind regards,

1 comment
Comment actions Permalink

There're different levels of problem reporting: lexer errors, parser errors and annotators/inspections reports.

String literal contents related problems belong to 1.lexer level or 2.semantic level, i.e. annotators/inspections in terms of IntelliJ API.

So in your case parser should handle all " demo" and "demoCRLF" (if lexer allows multiline strings and not treats this as bad token) and other strings the same way as the correct "demo".
Some inspection or annotator will then highlight incorrect/unresolved/etc. literals in editor in its turn.


Please sign in to leave a comment.