Home » Modeling » TMF (Xtext) » Long (to infinitely) running parser with backtrack=true and non-recursive grammar
Long (to infinitely) running parser with backtrack=true and non-recursive grammar [message #657606] |
Thu, 03 March 2011 13:16 |
Florian Jakob Messages: 4 Registered: March 2011 |
Junior Member |
|
|
Hi all,
I am relatively new to the topics Xtext / parser generation / parsing / LL(*) grammars and have a problem with the following (stripped down) grammar:
Model:
topLevelDeclarations+=TopLevelDeclaration*
;
TopLevelDeclaration:
TemplateDeclaration
// | ...
;
TemplateDeclaration:
'template' name=SimpleName
'{' body+=TemplateBodyDeclaration* '}'
;
TemplateBodyDeclaration:
CompilationUnitMatcher
// | ...
;
CompilationUnitMatcher:
// ...
types+=TypeDeclarationMatcher*
;
TypeDeclarationMatcher:
ClassDeclarationMatcher
// | ...
;
ClassDeclarationMatcher:
(modifiersMatcher=ModifiersMatcher)?
'class'
// ...
;
Modifier:
'public'
| 'protected'
| 'private'
| 'static'
| 'abstract'
| 'final'
| 'native'
| 'synchronized'
| 'transient'
| 'volatile'
| 'strictfp'
;
ModifiersMatcher:
modifiers+=Modifier+
;
SimpleName:
ID
;
Not using backtrack = true yields the following warnings and errors when running mwe2:
Quote: |
warning(200): ...:193:1: Decision can match input such as "'}'..'strictfp'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(201): ...:193:1: The following alternatives can never be matched: 2
warning(200): ...:266:1: Decision can match input such as "'strictfp'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'volatile'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'public'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'static'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'abstract'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'protected'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'private'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'synchronized'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'class'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'transient'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'final'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:266:1: Decision can match input such as "'native'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
|
Using backtrack = true for the parser.antlr.XtextAntlrGeneratorFragment and parser.antlr.XtextAntlrUiGeneratorFragment fragments gets rid of the warnings and errors, but my Eclipse freezes as soon as I try to open the file with the following contents having the associated suffix:
template FirstClass {
class * {
* *(..) {
...
}
}
}
Freezing means running for a long time and finally dying with an OutOfMemoryException. I assume something is wrong with my grammar, I just don't get what is is. Trying to understand the code in the Interal*.g did also not help very much.
As this problem occured to me using Xtext 1.0.1 I updated to Xtext 2.0, but it still persists.
Would someone please explain the problem to me and point me to (or give me) a solution for it?
Kind Regards
Florian
|
|
|
Re: Long (to infinitely) running parser with backtrack=true and non-recursive grammar [message #657633 is a reply to message #657606] |
Thu, 03 March 2011 13:46 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Florian,
please try to enable memoization (memoize = true) for the parser
generator fragments.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 03.03.11 14:16, schrieb Florian Jakob:
> Hi all,
>
> I am relatively new to the topics Xtext / parser generation / parsing /
> LL(*) grammars and have a problem with the following (stripped down)
> grammar:
>
>
> Model:
> topLevelDeclarations+=TopLevelDeclaration*
> ;
>
> TopLevelDeclaration:
> TemplateDeclaration
> // | ...
> ;
>
> TemplateDeclaration:
> 'template' name=SimpleName
> '{' body+=TemplateBodyDeclaration* '}'
> ;
>
> TemplateBodyDeclaration:
> CompilationUnitMatcher
> // | ...
> ;
>
> CompilationUnitMatcher:
> // ...
> types+=TypeDeclarationMatcher*
> ;
>
> TypeDeclarationMatcher:
> ClassDeclarationMatcher
> // | ...
> ;
>
> ClassDeclarationMatcher:
> (modifiersMatcher=ModifiersMatcher)?
> 'class'
> // ...
> ;
>
> Modifier:
> 'public'
> | 'protected'
> | 'private'
> | 'static'
> | 'abstract'
> | 'final'
> | 'native'
> | 'synchronized'
> | 'transient'
> | 'volatile'
> | 'strictfp'
> ;
>
> ModifiersMatcher:
> modifiers+=Modifier+
> ;
>
> SimpleName:
> ID
> ;
>
>
> Not using backtrack = true yields the following warnings and errors when
> running mwe2:
> Quote:
>> warning(200): ...:193:1: Decision can match input such as
>> "'}'..'strictfp'" using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> error(201): ...:193:1: The following alternatives can never be matched: 2
>>
>> warning(200): ...:266:1: Decision can match input such as "'strictfp'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'volatile'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'public'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'static'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'abstract'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as
>> "'protected'" using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'private'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as
>> "'synchronized'" using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'class'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as
>> "'transient'" using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'final'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>> warning(200): ...:266:1: Decision can match input such as "'native'"
>> using multiple alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>
>
> Using backtrack = true for the parser.antlr.XtextAntlrGeneratorFragment
> and parser.antlr.XtextAntlrUiGeneratorFragment fragments gets rid of the
> warnings and errors, but my Eclipse freezes as soon as I try to open the
> file with the following contents having the associated suffix:
>
>
> template FirstClass {
> class * {
> * *(..) {
> ...
> }
> }
> }
>
>
> Freezing means running for a long time and finally dying with an
> OutOfMemoryException. I assume something is wrong with my grammar, I
> just don't get what is is. Trying to understand the code in the
> Interal*.g did also not help very much.
>
> As this problem occured to me using Xtext 1.0.1 I updated to Xtext 2.0,
> but it still persists.
>
> Would someone please explain the problem to me and point me to (or give
> me) a solution for it?
>
> Kind Regards
> Florian
>
|
|
|
Re: Long (to infinitely) running parser with backtrack=true and non-recursive grammar [message #657648 is a reply to message #657606] |
Thu, 03 March 2011 15:19 |
Florian Jakob Messages: 4 Registered: March 2011 |
Junior Member |
|
|
Sebastian Zarnekow wrote: | please try to enable memoization (memoize = true) for the parser
generator fragments.
|
Similar result. The UI is blocked, the process claims ~100% CPU time and after ~5mins I get the notification that the editor could not be loaded with the following trace:
Stacktrace | org.eclipse.xtext.parser.ParseException: java.lang.OutOfMemoryError: Java heap space
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(A bstractAntlrParser.java:104)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.parse(Abs tractAntlrParser.java:84)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(A bstractAntlrParser.java:62)
at org.eclipse.xtext.parser.AbstractParser.parse(AbstractParser .java:27)
at org.eclipse.xtext.resource.XtextResource.doLoad(XtextResourc e.java:150)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLoad(La zyLinkingResource.java:69)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1494)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.load Resource(XtextDocumentProvider.java:135)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.setD ocumentContent(XtextDocumentProvider.java:118)
at org.eclipse.ui.editors.text.StorageDocumentProvider.createDo cument(StorageDocumentProvider.java:229)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.crea teDocument(XtextDocumentProvider.java:87)
at org.eclipse.ui.editors.text.FileDocumentProvider.createEleme ntInfo(FileDocumentProvider.java:735)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.crea teElementInfo(XtextDocumentProvider.java:146)
at org.eclipse.ui.texteditor.AbstractDocumentProvider.connect(A bstractDocumentProvider.java:400)
at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(Abst ractTextEditor.java:4056)
at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(Status TextEditor.java:217)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.doSetI nput(AbstractDecoratedTextEditor.java:1444)
at org.eclipse.ui.editors.text.TextEditor.doSetInput(TextEditor .java:169)
at org.eclipse.xtext.ui.editor.XtextEditor.doSetInput(XtextEdit or.java:159)
at org.eclipse.ui.texteditor.AbstractTextEditor$19.run(Abstract TextEditor.java:3043)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.ja va:372)
at org.eclipse.jface.window.ApplicationWindow$1.run(Application Window.java:759)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWi ndow.java:756)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow. java:2600)
at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(Ab stractTextEditor.java:3061)
at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTe xtEditor.java:3088)
at org.eclipse.xtext.ui.editor.XtextEditor.init(XtextEditor.jav a:180)
at org.eclipse.ui.internal.EditorManager.createSite(EditorManag er.java:798)
at org.eclipse.ui.internal.EditorReference.createPartHelper(Edi torReference.java:647)
at org.eclipse.ui.internal.EditorReference.createPart(EditorRef erence.java:465)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:31 3)
at org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFo lder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrd er.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresen tation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelecti on(PartStack.java:1254)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.jav a:1207)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:16 06)
at org.eclipse.ui.internal.PartStack.add(PartStack.java:497)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103 )
at org.eclipse.ui.internal.PartStack.add(PartStack.java:483)
at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112 )
at org.eclipse.ui.internal.EditorSashContainer.addEditor(Editor SashContainer.java:63)
at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorA reaHelper.java:225)
at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAre aHelper.java:213)
at org.eclipse.ui.internal.EditorManager.createEditorTab(Editor Manager.java:778)
at org.eclipse.ui.internal.EditorManager.openEditorFromDescript or(EditorManager.java:677)
at org.eclipse.ui.internal.EditorManager.openEditor(EditorManag er.java:638)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched( WorkbenchPage.java:2860)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(Workben chPage.java:2768)
at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPag e.java:2760)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.j ava:2711)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2707)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2691)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2682)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:651)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:610)
at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInE ditor(EditorUtility.java:365)
at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInE ditor(EditorUtility.java:168)
at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:22 9)
at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:20 8)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchR un(SelectionDispatchAction.java:274)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(Selec tionDispatchAction.java:250)
at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActio nGroup.handleOpen(PackageExplorerActionGroup.java:373)
at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart$ 4.open(PackageExplorerPart.java:526)
at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener. open(OpenAndLinkWithEditorHelper.java:48)
at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredV iewer.java:845)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:17 5)
at org.eclipse.jface.viewers.StructuredViewer.fireOpen(Structur edViewer.java:843)
at org.eclipse.jface.viewers.StructuredViewer.handleOpen(Struct uredViewer.java:1131)
at org.eclipse.jface.viewers.StructuredViewer$6.handleOpen(Stru cturedViewer.java:1235)
at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrate gy.java:264)
at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.ja va:258)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrate gy.java:298)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3540)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3161)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 38)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.ArrayList.<init>(ArrayList.java:112)
at com.google.common.collect.Lists.newArrayList(Lists.java:82)
at org.eclipse.xtext.nodemodel.impl.NodeModelBuilder.compressAn dReturnParent(NodeModelBuilder.java:174)
at org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser.a fterParserOrEnumRuleCall(AbstractInternalAntlrParser.java:59 7)
at de.tu_darmstadt.stg.bt.gll.parser.antlr.internal.InternalGLL Parser.ruleTemplateDeclaration(InternalGLLParser.java:487)
at de.tu_darmstadt.stg.bt.gll.parser.antlr.internal.InternalGLL Parser.ruleTopLevelDeclaration(InternalGLLParser.java:298)
at de.tu_darmstadt.stg.bt.gll.parser.antlr.internal.InternalGLL Parser.ruleModel(InternalGLLParser.java:181)
at de.tu_darmstadt.stg.bt.gll.parser.antlr.internal.InternalGLL Parser.entryRuleModel(InternalGLLParser.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser.p arse(AbstractInternalAntlrParser.java:526)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(A bstractAntlrParser.java:101)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.parse(Abs tractAntlrParser.java:84)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(A bstractAntlrParser.java:62)
at org.eclipse.xtext.parser.AbstractParser.parse(AbstractParser .java:27)
at org.eclipse.xtext.resource.XtextResource.doLoad(XtextResourc e.java:150)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLoad(La zyLinkingResource.java:69)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1494)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.load Resource(XtextDocumentProvider.java:135)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.setD ocumentContent(XtextDocumentProvider.java:118)
at org.eclipse.ui.editors.text.StorageDocumentProvider.createDo cument(StorageDocumentProvider.java:229)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.crea teDocument(XtextDocumentProvider.java:87)
at org.eclipse.ui.editors.text.FileDocumentProvider.createEleme ntInfo(FileDocumentProvider.java:735)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.crea teElementInfo(XtextDocumentProvider.java:146)
at org.eclipse.ui.texteditor.AbstractDocumentProvider.connect(A bstractDocumentProvider.java:400)
at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(Abst ractTextEditor.java:4056)
at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(Status TextEditor.java:217)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.doSetI nput(AbstractDecoratedTextEditor.java:1444)
at org.eclipse.ui.editors.text.TextEditor.doSetInput(TextEditor .java:169)
at org.eclipse.xtext.ui.editor.XtextEditor.doSetInput(XtextEdit or.java:159)
|
[Updated on: Thu, 03 March 2011 15:23] Report message to a moderator
|
|
| | |
Re: Long (to infinitely) running parser with backtrack=true and non-recursive grammar [message #657763 is a reply to message #657733] |
Thu, 03 March 2011 21:58 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Florian,
in rule TemplateDeclaration you'll match an infinite number of
TemplateBodyDeclarations since such a body declaration may be parsed
without actually parsing any contents. Backtracking simply shadows the
issue that Antlr raises at this point. The OOM error occurs when the
number of instantiated empty nodes and empty model instances is larger
than the amount of available memory.
A minor change fixed the issue on for me.
CompilationUnitMatcher:
// ...
types+=TypeDeclarationMatcher+
;
However, please try to remove the need for backtracking or make sure
that your parser works as expected by means of good test coverage.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 03.03.11 19:25, schrieb Florian Jakob:
> The grammar GLL.xtext (still stripped down, as the original is rather
> large [~900 lines] and contains much bloat irrelevant for the problem)
> which is used as input for the workflow:
> grammar de.tu_darmstadt.stg.bt.gll.GLL hidden(WS, ML_COMMENT, SL_COMMENT)
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> generate gLL "http://www.tu_darmstadt.de/stg/bt/gll/GLL"
>
> Model:
> topLevelDeclarations+=TopLevelDeclaration*
> ;
>
> TopLevelDeclaration:
> TemplateDeclaration
> // | ...
> ;
>
> TemplateDeclaration:
> 'template' name=SimpleName
> '{' body+=TemplateBodyDeclaration* '}'
> ;
>
> TemplateBodyDeclaration:
> CompilationUnitMatcher
> // | ...
> ;
>
> CompilationUnitMatcher:
> // ...
> types+=TypeDeclarationMatcher*
> ;
>
> TypeDeclarationMatcher:
> ClassDeclarationMatcher
> // | ...
> ;
>
> ClassDeclarationMatcher:
> (modifiersMatcher=ModifiersMatcher)?
> 'class'
> // ...
> ;
>
> Modifier:
> 'public'
> | 'protected'
> | 'private'
> | 'static'
> | 'abstract'
> | 'final'
> | 'native'
> | 'synchronized'
> | 'transient'
> | 'volatile'
> | 'strictfp'
> ;
>
> ModifiersMatcher:
> modifiers+=Modifier+
> ;
>
> SimpleName:
> ID
> ;
>
> terminal ID:
> '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
> ;
>
> terminal ML_COMMENT:
> '/*' -> '*/'
> ;
>
> terminal SL_COMMENT:
> '//' !('\n'|'\r')* ('\r'? '\n')?
> ;
>
> terminal WS:
> (' '|'\t'|'\r'|'\n')+
> ;
> The workflow GenerateGLL.mwe2:
> module de.tu_darmstadt.stg.bt.gll.GLL
>
> import org.eclipse.emf.mwe.utils.*
> import org.eclipse.xtext.generator.*
> import org.eclipse.xtext.ui.generator.*
>
> var grammarURI = "classpath:/de/tu_darmstadt/stg/bt/gll/GLL.xtext"
> var file.extensions = "gll"
> var projectName = "de.tu_darmstadt.stg.bt.gll"
> var runtimeProject = "../${projectName}"
>
> Workflow {
> bean = StandaloneSetup {
> platformUri = "${runtimeProject}/.."
> }
>
> component = DirectoryCleaner {
> directory = "${runtimeProject}/src-gen"
> }
>
> component = DirectoryCleaner {
> directory = "${runtimeProject}.ui/src-gen"
> }
>
> component = Generator {
> pathRtProject = runtimeProject
> pathUiProject = "${runtimeProject}.ui"
> projectNameRt = projectName
> projectNameUi = "${projectName}.ui"
> language = {
> uri = grammarURI
> fileExtensions = file.extensions
>
> // Java API to access grammar elements (required by several other
> fragments)
> fragment = grammarAccess.GrammarAccessFragment {}
>
> // generates Java API for the generated EPackages fragment =
> ecore.EcoreGeneratorFragment {
> // referencedGenModels = "uri to genmodel, uri to next genmodel"
> }
>
> // the serialization component
> fragment = parseTreeConstructor.ParseTreeConstructorFragment {}
>
> // a custom ResourceFactory for use with EMF fragment =
> resourceFactory.ResourceFactoryFragment {
> fileExtensions = file.extensions
> }
>
> // The antlr parser generator fragment.
> fragment = parser.antlr.XtextAntlrGeneratorFragment {
> options = {
> backtrack = true
> memoize = true
> }
> }
>
> // java-based API for validation fragment =
> validation.JavaValidatorFragment {
> composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
> composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
> // registerForImportedPackages = true
> }
>
> // scoping and exporting API
> // fragment = scoping.ImportURIScopingFragment {}
> // fragment = exporting.SimpleNamesFragment {}
>
> // scoping and exporting API fragment =
> scoping.ImportNamespacesScopingFragment {}
> fragment = exporting.QualifiedNamesFragment {}
> fragment = builder.BuilderIntegrationFragment {}
>
> // formatter API fragment = formatting.FormatterFragment {}
>
> // labeling API fragment = labeling.LabelProviderFragment {}
>
> // outline API fragment = outline.OutlineTreeProviderFragment {}
> fragment = outline.QuickOutlineFragment {}
>
> // quickfix API fragment = quickfix.QuickfixProviderFragment {}
>
> // content assist API fragment =
> contentAssist.JavaBasedContentAssistFragment {}
>
> // generates a more lightweight Antlr parser and lexer tailored for
> content assist fragment = parser.antlr.XtextAntlrUiGeneratorFragment {
> options = {
> backtrack = true
> memoize = true
> }
> }
>
> // project wizard (optional) // fragment =
> projectWizard.SimpleProjectWizardFragment {
> // generatorProjectName = "${projectName}.generator" //
> modelFileExtension = file.extensions
> // }
> }
> }
> }
>
> and the file FirstClass.gll I try to open / parse:
> template FirstClass {
> class * {
> * *(..) {
> ...
> }
> }
> }
>
> Note that all *, .. and ... are part of the syntax, the file is provided
> as it is on my filesystem.
|
|
| |
Goto Forum:
Current Time: Fri May 10 22:35:24 GMT 2024
Powered by FUDForum. Page generated in 0.04000 seconds
|