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

LivePreview problem with meta rules #254

Closed
rgobbel opened this issue Dec 1, 2020 · 3 comments
Closed

LivePreview problem with meta rules #254

rgobbel opened this issue Dec 1, 2020 · 3 comments

Comments

@rgobbel
Copy link

rgobbel commented Dec 1, 2020

This BNF generates an OutOfBoundsException in LivePreview, given an input that starts with a left parenthesis.

{
    generate=[tokenAccessors="no"]
    tokens=[
        LPAR='('
        RPAR=')'
        DOT='.'
        number='regexp:\d+'
        identifier='regexp:\w+'
        whitespace='regexp:\s+'
        comment='regexp:;.*'
    ]
}
root ::= sexpr *

sexpr ::= atom | cons

atom ::= identifier | number

cons ::= list

private meta items ::= <<items_entry <<recover>> <<param>>>> * {recoverWhile="<<recover>>"}
private meta items_entry ::= <<recover>> <<param>> {pin=1}
private list_body ::= <<items !')' sexpr>>
list ::= '(' list_body ')'

This is the line of code that throws the exception, line 476 of LivePreviewParser.java:

        nested = metaParameters.get(metaIdx + 1);

metaParameters is initialized to Collections.emptyList() and not referenced beyond that until the offending line. It looks like this bug has been there for several years (the code that set metaParameters was commented out in 2013).

Stack trace:

java.lang.IndexOutOfBoundsException: Index: 1
	at java.base/java.util.Collections$EmptyList.get(Collections.java:4483)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateExternalCall(LivePreviewParser.java:476)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateNodeCall(LivePreviewParser.java:376)
	at org.intellij.grammar.livePreview.LivePreviewParser.expression(LivePreviewParser.java:267)
	at org.intellij.grammar.livePreview.LivePreviewParser.rule(LivePreviewParser.java:131)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateExternalCall(LivePreviewParser.java:513)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateNodeCall(LivePreviewParser.java:376)
	at org.intellij.grammar.livePreview.LivePreviewParser.expression(LivePreviewParser.java:166)
	at org.intellij.grammar.livePreview.LivePreviewParser.rule(LivePreviewParser.java:131)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateNodeCall(LivePreviewParser.java:357)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateTokenSequenceCall(LivePreviewParser.java:396)
	at org.intellij.grammar.livePreview.LivePreviewParser.expression(LivePreviewParser.java:243)
	at org.intellij.grammar.livePreview.LivePreviewParser.rule(LivePreviewParser.java:131)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateNodeCall(LivePreviewParser.java:357)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateTokenSequenceCall(LivePreviewParser.java:396)
	at org.intellij.grammar.livePreview.LivePreviewParser.expression(LivePreviewParser.java:222)
	at org.intellij.grammar.livePreview.LivePreviewParser.rule(LivePreviewParser.java:131)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateNodeCall(LivePreviewParser.java:357)
	at org.intellij.grammar.livePreview.LivePreviewParser.expression(LivePreviewParser.java:217)
	at org.intellij.grammar.livePreview.LivePreviewParser.rule(LivePreviewParser.java:131)
	at org.intellij.grammar.livePreview.LivePreviewParser.generateNodeCall(LivePreviewParser.java:357)
	at org.intellij.grammar.livePreview.LivePreviewParser.expression(LivePreviewParser.java:267)
	at org.intellij.grammar.livePreview.LivePreviewParser.rule(LivePreviewParser.java:131)
	at org.intellij.grammar.livePreview.LivePreviewParser.parse(LivePreviewParser.java:77)
	at com.intellij.psi.tree.ILazyParseableElementType.doParseContents(ILazyParseableElementType.java:81)
	at com.intellij.psi.tree.IFileElementType.parseContents(IFileElementType.java:53)
	at com.intellij.psi.impl.source.tree.LazyParseableElement.lambda$ensureParsed$0(LazyParseableElement.java:192)
	at com.intellij.psi.impl.DebugUtil.performPsiModification(DebugUtil.java:567)
	at com.intellij.psi.impl.source.tree.LazyParseableElement.ensureParsed(LazyParseableElement.java:191)
	at com.intellij.psi.impl.source.tree.LazyParseableElement.getFirstChildNode(LazyParseableElement.java:242)
	at com.intellij.psi.impl.source.tree.CompositeElement.findLeafElementAt(CompositeElement.java:126)
	at com.intellij.psi.impl.source.tree.CompositeElement.findLeafElementAt(CompositeElement.java:33)
	at com.intellij.psi.AbstractFileViewProvider.findElementAt(AbstractFileViewProvider.java:248)
	at com.intellij.psi.SingleRootFileViewProvider.findElementAt(SingleRootFileViewProvider.java:229)
	at com.intellij.psi.impl.source.PsiFileImpl.findElementAt(PsiFileImpl.java:526)
	at com.intellij.psi.util.PsiUtilCore.getElementAtOffset(PsiUtilCore.java:406)
	at com.intellij.psi.util.PsiUtilBase.getLanguageInEditor(PsiUtilBase.java:55)
	at com.intellij.psi.util.PsiUtilBase.getPsiFileInEditor(PsiUtilBase.java:90)
	at com.intellij.psi.util.PsiUtilBase.getPsiFileInEditor(PsiUtilBase.java:75)
	at com.intellij.codeInsight.lookup.impl.LookupTypedHandler.execute(LookupTypedHandler.java:47)
	at com.intellij.codeInsight.template.emmet.EmmetPreviewTypedHandler.execute(EmmetPreviewTypedHandler.java:39)
	at com.intellij.execution.impl.ConsoleViewImpl$MyTypedHandler.execute(ConsoleViewImpl.java:1236)
	at com.intellij.openapi.editor.impl.DefaultRawTypedHandler$1.run(DefaultRawTypedHandler.java:55)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1000)
	at com.intellij.openapi.editor.impl.DefaultRawTypedHandler.execute(DefaultRawTypedHandler.java:49)
	at com.intellij.openapi.editor.impl.EditorFactoryImpl$MyRawTypedHandler.execute(EditorFactoryImpl.java:275)
	at com.intellij.openapi.editor.actionSystem.TypedAction.lambda$actionPerformed$2(TypedAction.java:183)
	at com.intellij.reporting.FreezeLoggerImpl.runUnderPerformanceMonitor(FreezeLoggerImpl.java:28)
	at com.intellij.openapi.editor.actionSystem.TypedAction.actionPerformed(TypedAction.java:183)
	at com.intellij.openapi.editor.impl.EditorImpl.processKeyTypedNormally(EditorImpl.java:1320)
	at com.intellij.openapi.editor.impl.EditorImpl.processKeyTyped(EditorImpl.java:1302)
	at com.intellij.openapi.editor.impl.EditorImpl.processKeyTyped(EditorImpl.java:3410)
	at com.intellij.openapi.editor.impl.EditorImpl$8.keyTyped(EditorImpl.java:1143)
	at java.desktop/java.awt.Component.processKeyEvent(Component.java:6607)
	at java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2852)
	at java.desktop/java.awt.Component.processEvent(Component.java:6429)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4859)
	at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1961)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:878)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1148)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1017)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:843)
	at com.intellij.ide.IdeKeyboardFocusManager.dispatchEvent(IdeKeyboardFocusManager.java:41)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4908)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4859)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:976)
	at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:896)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:837)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:454)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:773)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:453)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:822)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:507)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
@gregsh
Copy link
Collaborator

gregsh commented Dec 31, 2020

Thanks, fixed.

@gregsh gregsh closed this as completed Dec 31, 2020
@rgobbel
Copy link
Author

rgobbel commented Jan 1, 2021

Thanks for the fix! It would be great if you could expand on how meta rules work in the README. I was playing around with them at one point, and had the impression that the variable names for multiple levels of meta rules had to be the same, which didn't make sense--but the rules didn't seem to work unless I did that. Take a look at the BNF for the Clojure-Kit plugin, which is what I started with (actually, just look at the example I submitted, which came straight from Clojure-Kit).

@gregsh
Copy link
Collaborator

gregsh commented Jan 2, 2021

Each meta rule is like a function with its own set of parameters. Parameters are uniquely identified by their names and enumerated in order of appearance, thus I've skipped the formal parameter list declaration, i.e. meta rule(A, B) ::= A B has become meta rule ::= <<A>> <<B>>, which is not very convenient in case one wants to swap A and B occurrences, as all usages must be updated.

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