Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Using the Xtext.xtext grammar in another DSL gives "Couldn't resolve reference to EClassifier&q
Using the Xtext.xtext grammar in another DSL gives "Couldn't resolve reference to EClassifier&q [message #1841797] Sun, 30 May 2021 05:39 Go to next message
Eclipse UserFriend
I'm developing a DSL that uses Xtext's own grammar. Thus, it is possible to define Xtext grammar rules in the DSL to use. Xtext grammar rules are defined in the rule "Rule", which is defined as follows.

Rule:
'{'
'"name"' ':' '{'
'"column"' ':' nameColumn = INT ','
'"row"' ':' nameRow = INT ','
'"value"' ':' name = STRING_WITH_TOKENS
'}' ','
'"rule"' ':' '{'
'"column"' ':' ruleColumn = INT ','
'"row"' ':' ruleRow = INT ','
'"value"' ':' '"' rule = AbstractRule '"'
'}'
'}'
;

AbstractRule: ParserRule | TerminalRule | EnumRule;

Thus, rule = AbstractRule is what starts the use of the Xtext grammar. This means the following is not included from the original Xtext grammar:

Grammar:
'grammar' name=GrammarID ('with' usedGrammars+=[Grammar|GrammarID] (',' usedGrammars+=[Grammar|GrammarID])*)?
(definesHiddenTokens?='hidden' '(' (hiddenTokens+=[AbstractRule|RuleID] (',' hiddenTokens+=[AbstractRule|RuleID])*)? ')')?
metamodelDeclarations+=AbstractMetamodelDeclaration*
(rules+=AbstractRule)+
;

GrammarID returns ecore::EString:
ValidID ('.' ValidID)*;

Only smalls things have been changed in the original Xtext grammar such as the RuleNameAndParams using name to cross-reference to a Rule instead of a cross-refrence to a ValidID.

fragment RuleNameAndParams returns ParserRule:
name=[Rule] ('<' (parameters+=Parameter (',' parameters+=Parameter)*)? '>')?
;

import "http://www.eclipse.org/2008/Xtext" is not included in the beginning as it gives error. And terminals is not imported, but defined directly in the grammar.

Right now it works defining basic Xtext grammar rules. But creating a rule such as "Exp returns Expression: Factor (('+' {Plus.left=current} | '-' {Minus.left=current}) right=Factor)*;" gives an "Couldn't resolve reference to EClassifier 'Expression'".

I do not know if any of this can cause the error. I'm a bit lost about what causes the error.

[Updated on: Sun, 30 May 2021 05:45] by Moderator

Re: Using the Xtext.xtext grammar in another DSL gives "Couldn't resolve reference to EClassifi [message #1841798 is a reply to message #1841797] Sun, 30 May 2021 05:54 Go to previous messageGo to next message
Eclipse UserFriend
i guess you need to look on how Xtext does ecore inference and have to adopt it to your usecase
Re: Using the Xtext.xtext grammar in another DSL gives "Couldn't resolve reference to EClassifi [message #1841800 is a reply to message #1841798] Sun, 30 May 2021 13:25 Go to previous message
Eclipse UserFriend
Okay, thanks!
Previous Topic:Cross-referencing two different rules?
Next Topic:Lexer mixes some inputs even though it is set to non-greedy?
Goto Forum:
  


Current Time: Tue Jul 08 05:34:10 EDT 2025

Powered by FUDForum. Page generated in 0.08206 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top