Skip to content

Live preview crashes due to not processing semantic predicates #732

Open
@SteveHere

Description

@SteveHere

Issue: As explained in the title, live preview will crash when given the following setup:

Setup

(Lexer file)

lexer grammar PlaygroundScriptLexer;

channels {
    ERROR
}

options {
    superClass = PlaygroundScriptLexerBase;
}

CURLY_L             : '{' { this.DeepenDepth(); };
TemplateCloseBrace  : {this.IsInTemplateString()}? '}' {this.ProcessTemplateCloseBrace();} -> popMode;
CURLY_R             : '}' { this.ExitDepth(); };

# Hidden unrelated lexer rules

BackTick: '`' -> pushMode(TEMPLATE);


mode TEMPLATE;

BackTickInside                : '`' -> type(BackTick), popMode;
TemplateStringStartExpression : '@{' {this.ProcessTemplateOpenBrace();} -> pushMode(DEFAULT_MODE);
TemplateStringAtom            : (~[`@{]|'\\@{'|'@Name')+;

(Grammar file)

parser grammar PlaygroundScriptParser;


options {
    tokenVocab = PlaygroundScriptLexer;
    superClass = PlaygroundScriptParserBase;
}

// The program would be the root node for everything
program
    : tempstat+ EOF ;

tempstat
    : CURLY_L tableEntries? CURLY_R
    ;

tableEntries
    : tableEntry (',' tableEntry)* ','?
    ;

tableEntry
    : WORD '=' yieldable ','?
    | {this.isNamedFunction()}? func
    ;

And input a single opening curly brace ({) into Live Preview with start rule: program.

Errors

  1. Upon entering } , the Parse Tree display freezes and doesn't update. This will always happen.
    1.1. Upon removing the closing curly brace }, the Parse Tree display properly refreshes.

  2. Upon entering }, the plugin will sometimes crash & the following stack trace will be printed:

java.util.EmptyStackException
	at org.antlr.v4.runtime.Lexer.popMode(Lexer.java:192)
	at org.antlr.v4.runtime.atn.LexerPopModeAction.execute(LexerPopModeAction.java:58)
	at org.antlr.v4.runtime.atn.LexerActionExecutor.execute(LexerActionExecutor.java:168)
	at org.antlr.v4.runtime.atn.LexerATNSimulator.accept(LexerATNSimulator.java:366)
	at org.antlr.v4.runtime.atn.LexerATNSimulator.failOrAccept(LexerATNSimulator.java:299)
	at org.antlr.v4.runtime.atn.LexerATNSimulator.execATN(LexerATNSimulator.java:230)
	at org.antlr.v4.runtime.atn.LexerATNSimulator.matchATN(LexerATNSimulator.java:156)
	at org.antlr.v4.runtime.atn.LexerATNSimulator.match(LexerATNSimulator.java:111)
	at org.antlr.v4.runtime.Lexer.nextToken(Lexer.java:141)
	at org.antlr.v4.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:169)
	at org.antlr.v4.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:152)
	at org.antlr.v4.runtime.BufferedTokenStream.consume(BufferedTokenStream.java:136)
	at org.antlr.v4.runtime.Parser.consume(Parser.java:571)
	at org.antlr.v4.runtime.Parser.match(Parser.java:205)
	at org.antlr.intellij.plugin.parsing.PreviewParser.match(PreviewParser.java:62)
	at org.antlr.v4.runtime.ParserInterpreter.visitState(ParserInterpreter.java:246)
	at org.antlr.v4.runtime.ParserInterpreter.parse(ParserInterpreter.java:194)
	at org.antlr.intellij.plugin.parsing.ParsingUtils.parseText(ParsingUtils.java:249)
	at org.antlr.intellij.plugin.parsing.ParsingUtils.parseText(ParsingUtils.java:217)
	at org.antlr.intellij.plugin.ANTLRv4PluginController.lambda$parseText$3(ANTLRv4PluginController.java:480)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$computeInBackgroundAndTryWait$6(BackgroundTaskUtil.java:164)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:229)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.use(trace.kt:43)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:228)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$14(CoreProgressManager.java:680)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:755)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:711)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:679)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:77)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:209)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$computeInBackgroundAndTryWait$7(BackgroundTaskUtil.java:163)
	at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:265)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
	at com.intellij.util.concurrency.ContextCallable.lambda$call$1(ContextCallable.java:86)
	at com.intellij.util.concurrency.ContextCallable.call(ContextCallable.java:95)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at com.intellij.util.concurrency.ChildContext$runInChildContext$1.invoke(propagation.kt:102)
	at com.intellij.util.concurrency.ChildContext$runInChildContext$1.invoke(propagation.kt:102)
	at com.intellij.util.concurrency.ChildContext.runInChildContext(propagation.kt:108)
	at com.intellij.util.concurrency.ChildContext.runInChildContext(propagation.kt:102)
	at com.intellij.util.concurrency.ContextRunnable.run(ContextRunnable.java:27)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:735)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:732)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:732)
	at java.base/java.lang.Thread.run(Thread.java:1583)

This crash is effectively random and unpredictable, but does happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions