EMF + Xtext 2.4.3: Error in serialization of EObject [message #1219237] |
Mon, 02 December 2013 15:17  |
Eclipse User |
|
|
|
Dear all,
I have got one working DSL Text Editor, thanks to XText 2.4.3.
Now, when I want to add GUI support to this text editor, so that the user could use SWT/JFace components to edit the model, I have the following error while serializing an EObject back to the text editor resource. This EObject is the root of the modified tree after cloning a node EObject and inserting that clone back to the tree.
// Code that copies one EObject
AnnotatedElement original = new AnnotatedElement();
AnnotatedElement clone = EcoreUtil2.cloneWithProxies(original );
org.eclipse.emf.common.command.Command theCommand = AddCommand.createcreate(org.eclipse.emf.edit.domain.EditingDomain domain, Object original.getOwner(), Object feature, Object clone);
org.eclipse.emf.edit.domain.CommandStack.execute(theCommand);
// Code that serializes the EObject that is the root of the AST Tree
org.eclipse.emf.edit.domain.EditingDomain editingDomain = new EditingDomain();
final XtextDocument doc = (XtextDocument) xtextEditor.getDocument();
doc.modify(new IUnitOfWork.Void<XtextResource>()
{
@Override
public void process(XtextResource resource) throws Exception
{
Injector injector = Guice.createInjector(new ExampleRuntimeModule());
org.eclipse.xtext.serializer.impl.Serializer serializer = injector.getInstance(org.eclipse.xtext.serializer.impl.Serializer.class);
EObject rootEObj = editingDomain.getResourceSet().getResources().get(0).getContents().get(0);
String serializedDoc = serializer.serialize(eObj);
doc.set(serializedDoc);
}
}
The code above compiles (and what you see is the simplified version) and now for this model:
import BaseMath.*;
import BaseModel.*;
model Example uses BaseModel
{
version : "00.00.000.000";
root
{
variable TREEROOT
{
variable VARIABLE_1
{
datatype : string;
formula : If(1, 2, 3);
title : "Var title 1";
}
}
}
}
The error occurs when I copy VARIABLE_1 in that model
--------------------------------
No EObjectDescription could be found in Scope IdentifierExpression.declaration for FinancialModel.elements[0]->AnnotatedElement.element->LibraryDeclaration'BaseMath'.elements[117]->AnnotatedElement.element->FunctionDeclaration'If'
Semantic Object: FinancialModel.elements[0]->AnnotatedElement.element->Model'Example'.root->Root'Root'.elements[0]->AnnotatedElement.element->Variable'TREEROOT'.elements[1]->AnnotatedElement.element->Variable'VARIABLE_1_COPY'.statements[1]->AssignmentStatement.value->ValueList.valueItems[0]->ValueItem.value->IdentifierExpression'If'
--------------------------------
[Updated on: Tue, 03 December 2013 05:36] by Moderator
|
|
|
|
Re: The grammar, domain generic file [message #1219240 is a reply to message #1219239] |
Mon, 02 December 2013 15:24  |
Eclipse User |
|
|
|
grammar com.mydomain.ide.expression.Expression with org.eclipse.xtext.common.Terminals
hidden(WS, ML_COMMENT, SL_COMMENT)
generate expression "http://www.mydomain.com/ide/expression/Expression"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Expression:
ImpliesExpression
;
/*
* Operator precedence from lowest to highest:
*
* implies
* > | < | >= | <=
* = | <>
* + | - | &
* or
* * | / | mod
* and
* ^
* not | - | + << unary operators
* literals & function calls
*
*/
enum ImpliesOperator returns BinaryOperator:
IMPLIES='implies'
;
ImpliesExpression returns Expression:
RelationalExpression (
{BinaryExpression.left = current}
operator=ImpliesOperator
right=RelationalExpression
)*
;
enum RelationalOperator returns BinaryOperator:
GREATER='>' | SMALLER='<' | GREATEREQUAL='>=' | SMALLEREQUAL='<='
;
RelationalExpression returns Expression:
EqualityExpression (
{BinaryExpression.left=current}
operator=RelationalOperator
right=EqualityExpression
)*
;
enum EqualityOperator returns BinaryOperator:
EQUAL='=' | NOTEQUAL='<>'
;
EqualityExpression returns Expression:
AdditiveExpression (
{BinaryExpression.left=current}
operator=EqualityOperator
right=AdditiveExpression
)*
;
enum AdditiveOperator returns BinaryOperator:
PLUS='+' | MINUS='-' | CONCAT='&'
;
AdditiveExpression returns Expression:
OrExpression (
{BinaryExpression.left=current}
operator=AdditiveOperator
right=OrExpression
)*
;
enum OrOperator returns BinaryOperator:
OR='or'
;
OrExpression returns Expression:
MultiplicativeExpression (
{BinaryExpression.left=current}
operator=OrOperator
right=MultiplicativeExpression
)*
;
enum MultiplicativeOperator returns BinaryOperator:
MULTIPLY='*' | DIVIDE='/' | MODULO='mod'
;
MultiplicativeExpression returns Expression:
AndExpression (
{BinaryExpression.left=current}
operator=MultiplicativeOperator
right=AndExpression
)*
;
enum AndOperator returns BinaryOperator:
AND='and'
;
AndExpression returns Expression:
PowerExpression (
{BinaryExpression.left=current}
operator=AndOperator
right=PowerExpression
)*
;
enum PowerOperator returns BinaryOperator:
POWER='^'
;
PowerExpression returns Expression:
UnaryExpression (
{BinaryExpression.left=current}
operator=PowerOperator
right=UnaryExpression
)*
;
enum UnaryOperator:
NOT='not' | NEGATIVE='-' | POSITIVE='+'
;
UnaryExpression returns Expression:
({UnaryExpression}
operator=UnaryOperator expression=PrimaryExpression
)
| PrimaryExpression
;
PrimaryExpression returns Expression:
LiteralExpression
| IdentifierExpression
| ParenthesizedExpression
;
ParenthesizedExpression returns Expression:
{ParenthesizedExpression}
'(' innerExpression=Expression ')'
;
LiteralExpression returns Expression:
LiteralNumber
| LiteralPercentage
| LiteralString
| LiteralKeyword
;
LiteralPercentage:
value=Double '%'
;
LiteralNumber:
value=Double
;
LiteralString:
hasAmpersand?='&'? value=STRING
;
enum KeywordValue:
X='X'
| Y='Y'
| Z='Z'
| ROOT='ROOT'
;
LiteralKeyword:
(keyword=KeywordValue)
;
//An identifier expression can be a variable, function or a constant.
//It's not possible to define these in separate production rules,
//because the parser can't decide between rules that start with the
//same terminal or production rule; in this case the terminal 'ID',
//because the ampersand is optional.
IdentifierExpression:
hasAmpersand?='&'? name=ID extension=IdentifierExtension?
;
IdentifierExtension:
CellSpecifier | ArgumentList
;
CellSpecifier:
'[' column=Expression (',' tsy=Expression)? ']'
;
ArgumentList:
'(' arguments+=Argument (',' arguments+=Argument)* ')'
;
Argument:
itemList=CaseItemList | expression=Expression
;
CaseItemList:
'[' items+=CaseItem (( separators+=CaseItemSeparator ) items+=CaseItem)* ']'
;
enum CaseItemSeparator:
PIPELINE='|' | COLON=':'
;
enum CaseItemOperator returns BinaryOperator:
GREATER='>' | SMALLER='<' | GREATEREQUAL='>=' | SMALLEREQUAL='<=' | EQUAL='=' | NOTEQUAL='<>'
;
CaseItem:
operator=CaseItemOperator? expression=Expression
;
Double returns ecore::EDouble:
INT+('.'INT)?
;
//The standard ID terminal rule is overridden here, because of the
//power operator defined in the original ID terminal rule.
terminal ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
|
|
|
Powered by
FUDForum. Page generated in 0.04026 seconds