Home » Modeling » TMF (Xtext) » Howto integrate OCL in a grammar?
| | | | | |
Re: Howto integrate OCL in a grammar? [message #557721 is a reply to message #557701] |
Wed, 08 September 2010 15:23 |
Meinte Boersma Messages: 434 Registered: July 2009 Location: Leiden, Netherlands |
Senior Member |
|
|
A cross-reference like [Element] means that the attribute being defined (elt=[Element]) is an EReference (in the generated or re-used Ecore model) to something of type Element. The Xtext framework provides a default linking mechanism for initialized Element objects which happen to "be around" like your VariableDeclaration for 'a'. So, it might look like the [Element] cross-reference and the Element type rule belong together, but that's only through the generated/re-used Element type. As far as the generated parser is concerned, it is happy as long as it can consume some token (ID, by default; override with [Element|someOtherTokenDef]) at the position of the cross-reference. So, the actual linking is something which lives outside of the syntax. In fact, the word 'grammar' is a bit misleading as an Xtext grammar (partially) addresses a few other aspects as well, like defining the types for the AST nodes.
Let's say you want to re-use an OCL grammar. Then you'd need the grammar and extend from it using the with construct Alexander is hinting at. What you're trying to do now, is to re-use an OCL model, through the import construct. This means that you've only got the types but not the syntax and you'll have to create a grammar for the OCL sub-language yourself. So, it's not enough to say =[OCL::OCLExpression] to be able to write down an OCL expression: you'll actually need parser rules for that using the "returns OCL::OCLExpression" construct to define both the syntax as well as the way how that syntax corresponds to the re-used OCLExpression type.
Xtext blogs: executable models...again? | workshop material | custom scoping with Xtend
|
|
| | | | | | | | | | | |
Re: Howto integrate OCL in a grammar? [message #658322 is a reply to message #557734] |
Mon, 07 March 2011 21:11 |
Federico Wiecko Messages: 1 Registered: March 2011 |
Junior Member |
|
|
Hi,
I want to do exactly the same as Michael: to reuse OCL grammar into my DSL.
However I am getting a different error, so I will describe what I did.
1) I installed all the OCL support that are included under MDT/OCL 3.0.2
2) I imported into my workspace the following plugins:
org.eclipse.ocl.examples.xtext.base
org.eclipse.ocl.examples.xtext.essentialocl
3) I created my XText project in which I define the following trivial grammar as a prof of concept:
grammar org.xtext.example.mydsl9.MyDsl with org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCL
generate myDsl "http://www.xtext.org/example/mydsl9/MyDsl"
VarDef:
'var' name=ID type=TypeExpCS;
The XText editor recognizes that TypeExpCS is defined in EssentialOCL, so no error here.
4) I added a reference to the genmodel in the workflow file:
fragment = ecore.EcoreGeneratorFragment {
genModels = "platform:/resource/org.eclipse.ocl.examples.xtext.essentialocl/model/EssentialOCLCST.genmodel"
}
When I compile I get the following error:
...
949 [main] INFO ipse.xtext.generator.LanguageConfig - generating infrastructure for org.xtext.example.mydsl9.MyDsl with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, ParseTreeConstructorFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, FormatterFragment, LabelProviderFragment, TransformerFragment, OutlineNodeAdapterFactoryFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment
warning(200): ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDsl.g:1753:2: Decision can match input such as "'implies'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDsl.g:1870:2: Decision can match input such as "'xor'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDsl.g:1987:2: Decision can match input such as "'or'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDsl.g:2104:2: Decision can match input such as "'and'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
...
more similar errors here
......
error(211): ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDsl.g:3209:1: [fatal] rule ruleSubNavigatingExpCS has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2,3,4. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
warning(200): ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDsl.g:3209:1: Decision can match input such as "RULE_ID '::'" using multiple alternatives: 1, 2, 3, 4
As a result, alternative(s) 3,2,4 were disabled for that input
8776 [main] ERROR enerator.CompositeGeneratorFragment - java.io.FileNotFoundException: ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDslParser.java (No such file or directory)
org.eclipse.emf.common.util.WrappedException: java.io.FileNotFoundException: ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDslParser.java (No such file or directory)
at org.eclipse.xtext.util.Files.readFileIntoString(Files.java:134)
at org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGeneratorFragment.suppressWarningsImpl(AbstractAntlrGeneratorFragment.java:126)
at org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGeneratorFragment.suppressWarnings(AbstractAntlrGeneratorFragment.java:137)
at org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGeneratorFragment.suppressWarnings(AbstractAntlrGeneratorFragment.java:132)
at org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment.generate(XtextAntlrGeneratorFragment.java:47)
at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:81)
at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:69)
at org.eclipse.xtext.generator.Generator.generate(Generator.java:296)
at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:106)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:31)
at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:80)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: java.io.FileNotFoundException: ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9/parser/antlr/internal/InternalMyDslParser.java (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.eclipse.xtext.util.Files.readFileIntoString(Files.java:119)
... 17 more
It seems to me that the XText grammar definition of the EssentialOCL project has some ambiguities and that seems the reason why the parser file is not being created in my project. If this is the case, where I can get a working version of EssentialOCL ?
I know that CompleteOCL and OCLInEcore make grammar reusse of EssentialOCL, however I cannot test them since the workflow file is missing.
As a final test, I comment out from the EssentialOCL grammar rule definition the rules that produces conflicts and just left the definition of TypeExpCS as the main rule + other required grammar rules. Doing this my project is compiling fine.
I would appreciate if somebody can point me in the right direction.
Thanks in advance !
Federico Wiecko
|
|
|
Re: Howto integrate OCL in a grammar? [message #658386 is a reply to message #658322] |
Tue, 08 March 2011 09:13 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Just a guess: Maybe you have to enable backtracking?
Am 07.03.11 22:11, schrieb Federico Wiecko:
> Hi,
>
> I want to do exactly the same as Michael: to reuse OCL grammar into my DSL.
> However I am getting a different error, so I will describe what I did.
>
> 1) I installed all the OCL support that are included under MDT/OCL 3.0.2
> 2) I imported into my workspace the following plugins:
> org.eclipse.ocl.examples.xtext.base
> org.eclipse.ocl.examples.xtext.essentialocl
>
> 3) I created my XText project in which I define the following trivial
> grammar as a prof of concept:
>
>
> grammar org.xtext.example.mydsl9.MyDsl with
> org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCL
>
> generate myDsl "http://www.xtext.org/example/mydsl9/MyDsl"
>
> VarDef:
> 'var' name=ID type=TypeExpCS;
>
>
> The XText editor recognizes that TypeExpCS is defined in EssentialOCL,
> so no error here.
>
> 4) I added a reference to the genmodel in the workflow file:
>
> fragment = ecore.EcoreGeneratorFragment {
> genModels =
> " platform:/resource/org.eclipse.ocl.examples.xtext.essentialo cl/model/EssentialOCLCST.genmodel "
>
> }
>
>
> When I compile I get the following error:
>
>
> ..
> 949 [main] INFO ipse.xtext.generator.LanguageConfig - generating
> infrastructure for org.xtext.example.mydsl9.MyDsl with fragments :
> ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment,
> EcoreGeneratorFragment, ParseTreeConstructorFragment,
> ResourceFactoryFragment, XtextAntlrGeneratorFragment,
> JavaValidatorFragment, ImportNamespacesScopingFragment,
> QualifiedNamesFragment, BuilderIntegrationFragment, FormatterFragment,
> LabelProviderFragment, TransformerFragment,
> OutlineNodeAdapterFactoryFragment, QuickOutlineFragment,
> QuickfixProviderFragment, JavaBasedContentAssistFragment,
> XtextAntlrUiGeneratorFragment
> warning(200):
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDsl.g:1753:2:
> Decision can match input such as "'implies'" using multiple
> alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> warning(200):
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDsl.g:1870:2:
> Decision can match input such as "'xor'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> warning(200):
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDsl.g:1987:2:
> Decision can match input such as "'or'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> warning(200):
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDsl.g:2104:2:
> Decision can match input such as "'and'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> ..
> more similar errors here
> .....
> error(211):
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDsl.g:3209:1:
> [fatal] rule ruleSubNavigatingExpCS has non-LL(*) decision due to
> recursive rule invocations reachable from alts 1,2,3,4. Resolve by
> left-factoring or using syntactic predicates or using backtrack=true
> option.
> warning(200):
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDsl.g:3209:1:
> Decision can match input such as "RULE_ID '::'" using multiple
> alternatives: 1, 2, 3, 4
> As a result, alternative(s) 3,2,4 were disabled for that input
> 8776 [main] ERROR enerator.CompositeGeneratorFragment -
> java.io.FileNotFoundException:
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDslParser.java
> (No such file or directory)
> org.eclipse.emf.common.util.WrappedException:
> java.io.FileNotFoundException:
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDslParser.java
> (No such file or directory)
> at org.eclipse.xtext.util.Files.readFileIntoString(Files.java:1 34)
> at
> org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGenera torFragment.suppressWarningsImpl(AbstractAntlrGeneratorFragm ent.java:126)
>
> at
> org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGenera torFragment.suppressWarnings(AbstractAntlrGeneratorFragment. java:137)
>
> at
> org.eclipse.xtext.generator.parser.antlr.AbstractAntlrGenera torFragment.suppressWarnings(AbstractAntlrGeneratorFragment. java:132)
>
> at
> org.eclipse.xtext.generator.parser.antlr.XtextAntlrGenerator Fragment.generate(XtextAntlrGeneratorFragment.java:47)
>
> at
> org.eclipse.xtext.generator.CompositeGeneratorFragment.gener ate(CompositeGeneratorFragment.java:81)
>
> at
> org.eclipse.xtext.generator.LanguageConfig.generate(Language Config.java:69)
> at org.eclipse.xtext.generator.Generator.generate(Generator.jav a:296)
> at org.eclipse.xtext.generator.Generator.invokeInternal(Generat or.java:106)
> at
> org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invok e(AbstractWorkflowComponent.java:126)
>
> at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.ja va:34)
> at
> org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invok e(AbstractWorkflowComponent.java:201)
>
> at
> org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkf lowComponent.invoke(AbstractCompositeWorkflowComponent.java: 31)
>
> at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow. java:19)
> at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:80)
> at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:52)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Lau ncher.java:74)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2La uncher.java:35)
> Caused by: java.io.FileNotFoundException:
> ../org.xtext.example.mydsl9/src-gen/org/xtext/example/mydsl9 /parser/antlr/internal/InternalMyDslParser.java
> (No such file or directory)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.<init>(FileInputStream.java:106)
> at java.io.FileInputStream.<init>(FileInputStream.java:66)
> at org.eclipse.xtext.util.Files.readFileIntoString(Files.java:1 19)
> ... 17 more
>
>
>
> It seems to me that the XText grammar definition of the EssentialOCL
> project has some ambiguities and that seems the reason why the parser
> file is not being created in my project. If this is the case, where I
> can get a working version of EssentialOCL ?
>
> I know that CompleteOCL and OCLInEcore make grammar reusse of
> EssentialOCL, however I cannot test them since the workflow file is
> missing.
> As a final test, I comment out from the EssentialOCL grammar rule
> definition the rules that produces conflicts and just left the
> definition of TypeExpCS as the main rule + other required grammar rules.
> Doing this my project is compiling fine.
> I would appreciate if somebody can point me in the right direction.
>
> Thanks in advance !
> Federico Wiecko
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
| | |
Goto Forum:
Current Time: Thu Apr 25 23:09:02 GMT 2024
Powered by FUDForum. Page generated in 0.04753 seconds
|