diff --git a/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java b/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java index 8886531a..f4290efd 100644 --- a/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java +++ b/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java @@ -19,6 +19,8 @@ public class PreviewParser extends GrammarParserInterpreter { protected int lastSuccessfulMatchState = ATNState.INVALID_STATE_NUMBER; // not sure about error nodes + private boolean warnedAboutPredicates = false; + public PreviewParser(Grammar g, ATN atn, TokenStream input) { super(g, atn, input); lexerWatchdog = new LexerWatchdog(input, this); @@ -33,6 +35,7 @@ public void reset() { super.reset(); if ( inputTokenToStateMap!=null ) inputTokenToStateMap.clear(); lastSuccessfulMatchState = ATNState.INVALID_STATE_NUMBER; + warnedAboutPredicates = false; } @Override @@ -75,4 +78,23 @@ public Token matchWildcard() throws RecognitionException { lastSuccessfulMatchState = getState(); return super.matchWildcard(); } + + @Override + public void action(RuleContext _localctx, int ruleIndex, int actionIndex) { + warnAboutPredicatesAndActions(); + } + + @Override + public boolean sempred(RuleContext _localctx, int ruleIndex, int actionIndex) { + warnAboutPredicatesAndActions(); + return super.sempred(_localctx, ruleIndex, actionIndex); + } + + private void warnAboutPredicatesAndActions() { + if (!warnedAboutPredicates) { + notifyErrorListeners("WARNING: predicates and actions are not run by this interpreter. " + + "Results may vary from the actual generated parser!"); + warnedAboutPredicates = true; + } + } } diff --git a/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.form b/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.form index 0e977610..3f2f8b43 100644 --- a/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.form +++ b/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.form @@ -49,6 +49,16 @@ + + + + + + + + + + diff --git a/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java b/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java index 4abe043d..5e642034 100644 --- a/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java +++ b/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java @@ -17,6 +17,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComponentWithBrowseButton; +import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.ui.TextComponentAccessor; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.Key; @@ -70,13 +71,7 @@ public class InputPanel { private JPanel startRuleAndInputPanel; private TextFieldWithBrowseButton fileChooser; private JPanel outerMostPanel; - - /** - * switchToGrammar() was seeing an empty slot instead of a previous - * editor or placeHolder. Figured it was an order of operations thing - * and synchronized add/remove ops. Works now w/o error. - */ - private final Object swapEditorComponentLock = new Object(); + private Splitter editorSplitter; private final PreviewPanel previewPanel; @@ -266,17 +261,7 @@ public void switchToGrammar(PreviewState previewState, VirtualFile grammarFile) } public void setEditorComponent(JComponent editor) { - BorderLayout layout = (BorderLayout) outerMostPanel.getLayout(); - String EDITOR_SPOT_COMPONENT = BorderLayout.CENTER; - // atomically remove old - synchronized (swapEditorComponentLock) { - Component editorSpotComp = layout.getLayoutComponent(EDITOR_SPOT_COMPONENT); - if ( editorSpotComp!=null ) { - editorSpotComp.setVisible(false); - outerMostPanel.remove(editorSpotComp); // remove old editor if it's there - } - outerMostPanel.add(editor, EDITOR_SPOT_COMPONENT); - } + editorSplitter.setFirstComponent(editor); } public Editor getInputEditor() {