Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If statement and "=>" #1

Open
Champii opened this issue Sep 7, 2018 · 4 comments
Open

If statement and "=>" #1

Champii opened this issue Sep 7, 2018 · 4 comments

Comments

@Champii
Copy link
Owner

Champii commented Sep 7, 2018

If/Else statements cannot have a "=>" into quotes anywhere if they are multilines because of the preprocessor that adds ';' after the predicate expression in order to disambiguate with the following block

if someStr == "=>" // That fails
  doSomething()

Temporary workaround: Put the incriminated string into a variable outside of the if/else statement

Even if its a very specific issue, we need to ignore what's in the quotes when doing that kind of changes

@skull-squadron
Copy link

skull-squadron commented Sep 14, 2018

This project is awesome. 👏😎

Most lexers change their token state (Anltr calls it "mode"; start lexing using different rules, returning only after reaching the matching ending terminal) once they encounter such a terminal. In this way, some lexing rules which apply to the starting lexing state don't apply in the string lexing state. It would mean factoring out some token recognition to a separate lexer-only grammar, but it's unfortunately necessary since ANTLR doesn't allow lexical modes in mixed lexer-parsers.

See Lexical Modes in https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md

Examples:

https://github.com/antlr/grammars-v4/blob/master/xml/XMLLexer.g4

https://stackoverflow.com/q/18243283/246672

Pseudocode:

  1. See a ".
  2. Push lexer state to become a string lexer.
  3. Lex inside of a string using string lexing rules until ".
  4. See an ending ".
  5. Pop lexer state back to whatever it was.

@Champii
Copy link
Owner Author

Champii commented Sep 14, 2018

Hi !

Actually it's more a dirty hack, as the preprocessor don't tokenize the input but rather naively analyze each line as raw text to match some input. I need to fix that using a more powerful parsing technic, obviously :)

Thank you for that piece of information !

@skull-squadron
Copy link

skull-squadron commented Sep 14, 2018

Hey. No prob. Check out the ANTLR XML, SmallTalk and esp. Python example parsers for the bits needed to do less hacks. Good luck, my friend.

@Champii
Copy link
Owner Author

Champii commented Sep 14, 2018

That's great material, thank you !
I might use Antlr's semantic predicate to mitigate this issue, also my grammar definition is poorly designed so I need to review all that to produce an efficient and reliable parser for these specific cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants