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

failure when trying to parse expressions containing nested and-not in prefix notation #3

Open
michaelmera opened this issue Aug 27, 2022 · 1 comment
Assignees
Labels
bug Something isn't working medium Bugs/issues of medium importance parser ISLa-Parser related issues

Comments

@michaelmera
Copy link

Here is a file reproducing the problem:

# isla_and_not.py
from isla.language import parse_isla

if __name__ == "__main__":
    parse_isla('(and (= <isbn10> "a") (= <isbn10> "b"))')              # no not     -> ok
    parse_isla('(not (= <isbn10> "a")) and (not (= <isbn10> "b"))')    # infix and  -> ok
    parse_isla('(and (not (= <isbn10> "a")) (not (= <isbn10> "b")))')  # prefix and -> fails

Output:

$ python isla_and_not.py
line 1:6 no viable alternative at input 'not'
Traceback (most recent call last):
  File "/home/isla/isla/src/isla/isla_language/IslaLanguageParser.py", line 1398, in sexpr
    la_ = self._interp.adaptivePredict(self._input,21,self._ctx)
  File "/usr/local/lib/python3.10/site-packages/antlr4/atn/ParserATNSimulator.py", line 346, in adaptivePredict
    alt = self.execATN(dfa, s0, input, index, outerContext)
  File "/usr/local/lib/python3.10/site-packages/antlr4/atn/ParserATNSimulator.py", line 418, in execATN
    raise e
antlr4.error.Errors.NoViableAltException: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/isla/files/isla_isbn10.py", line 79, in <module>
    parse_isla('(and (not (= <isbn10> "a")) (not (= <isbn10> "b")))')
  File "/home/isla/isla/src/isla/language.py", line 2921, in parse_isla
    antlr4.ParseTreeWalker().walk(isla_emitter, parser.start())
  File "/home/isla/isla/src/isla/isla_language/IslaLanguageParser.py", line 226, in start
    self.formula(0)
  File "/home/isla/isla/src/isla/isla_language/IslaLanguageParser.py", line 971, in formula
    self.sexpr(0)
  File "/home/isla/isla/src/isla/isla_language/IslaLanguageParser.py", line 1521, in sexpr
    self.sexpr(0)
  File "/home/isla/isla/src/isla/isla_language/IslaLanguageParser.py", line 1515, in sexpr
    localctx.op = self.sexpr(0)
  File "/home/isla/isla/src/isla/isla_language/IslaLanguageParser.py", line 1623, in sexpr
    self._errHandler.recover(self, re)
  File "/home/isla/isla/src/isla/language.py", line 2099, in recover
    super().recover(recognizer, e)
  File "/usr/local/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py", line 697, in recover
    raise ParseCancellationException(e)
antlr4.error.Errors.ParseCancellationException: None
@rindPHI
Copy link
Owner

rindPHI commented Aug 29, 2022

Thanks for reporting this. For the record (Michael knows this already): Expressing the constraint in infix/prefix syntax (without S-expressions!) circumvents this problem.

@rindPHI rindPHI added bug Something isn't working medium Bugs/issues of medium importance parser ISLa-Parser related issues labels Aug 29, 2022
@rindPHI rindPHI self-assigned this Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working medium Bugs/issues of medium importance parser ISLa-Parser related issues
Projects
None yet
Development

No branches or pull requests

2 participants