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

Ambiguity with regular expressions and comments #2029

Open
sungshik opened this issue Sep 9, 2024 · 1 comment
Open

Ambiguity with regular expressions and comments #2029

sungshik opened this issue Sep 9, 2024 · 1 comment

Comments

@sungshik
Copy link
Contributor

sungshik commented Sep 9, 2024

Describe the bug

This is not ambiguous:

if (
//  /0  := [1,2,3]
    /0 !:= [1,2,3]
) {
    println("foo");
} else {
    println("bar");
}

But, this is ambiguous:

if (
    /0  := [1,2,3]
//  /0 !:= [1,2,3]
) {
    println("foo");
} else {
    println("bar");
}

The parser seems to be in doubt about whether:

  • /0 := [1,2,3]\n/ is a regular expression, or
  • // /0 !:= [1,2,3] is a comment.

Stack traces

rascal>if (
>>>>>>>    /0  := [1,2,3]
>>>>>>>//  /0 !:= [1,2,3]
>>>>>>>) {
>>>>>>>    println("foo");
>>>>>>>} else {
>>>>>>>    println("bar");
>>>>>>>}
Unexpected failure during parsing of current command:
Ambiguous code (internal error), if (
    /0  := [1,2,3]
//  /0 !:= [1,2,3]
) {
    println("foo");
} else {
    println("bar");
}
org.rascalmpl.interpreter.asserts.Ambiguous: Ambiguous code (internal error), if (
    /0  := [1,2,3]
//  /0 !:= [1,2,3]
) {
    println("foo");
} else {
    println("bar");
}
        at org.rascalmpl.parser.uptr.UPTRNodeFactory.buildAmbiguityNode(UPTRNodeFactory.java:76)
        at org.rascalmpl.parser.uptr.UPTRNodeFactory.createAmbiguityNode(UPTRNodeFactory.java:85)
        at org.rascalmpl.parser.uptr.UPTRNodeFactory.createAmbiguityNode(UPTRNodeFactory.java:23)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.convertToUPTR(SortContainerNodeFlattener.java:183)
        at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:63)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.buildAlternative(SortContainerNodeFlattener.java:90)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:65)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherAlternatives(SortContainerNodeFlattener.java:53)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.convertToUPTR(SortContainerNodeFlattener.java:166)
        at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:63)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.buildAlternative(SortContainerNodeFlattener.java:90)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:65)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:71)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:71)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherAlternatives(SortContainerNodeFlattener.java:53)
        at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.convertToUPTR(SortContainerNodeFlattener.java:166)
        at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:63)
        at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:79)
        at org.rascalmpl.parser.gtd.SGTDBF.buildResult(SGTDBF.java:1306)
        at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1245)
        at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1249)
        at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1261)
        at org.rascalmpl.interpreter.Evaluator.parseCommand(Evaluator.java:1052)
        at org.rascalmpl.interpreter.Evaluator.parseCommand(Evaluator.java:1042)
        at org.rascalmpl.repl.RascalInterpreterREPL.isStatementComplete(RascalInterpreterREPL.java:176)
        at org.rascalmpl.repl.BaseRascalREPL.handleInput(BaseRascalREPL.java:119)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL$1.handleInput(LSPTerminalREPL.java:246)
        at org.rascalmpl.repl.BaseREPL.handleInput(BaseREPL.java:179)
        at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:346)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL.main(LSPTerminalREPL.java:333)
@jurgenvinju
Copy link
Member

Good catch!

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

No branches or pull requests

2 participants