Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parsing error:coudn't reslolve reference
Parsing error:coudn't reslolve reference [message #1802125] Fri, 01 February 2019 15:27 Go to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Hi all, I have validation error on the following string (see my grammar bellow)

class test {a: text; b: text; c : text; key a; index b; }
			operation createTest() {
			    create test(a = 'akey', b = 'btext', c = 'ctext');
			}


Quote:
java.lang.AssertionError: Expected no errors, but got :ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Linking) 'Couldn't resolve reference to VariableDeclaration 'a'.' on CreateWhatPart, offset 99, length 1
ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Linking) 'Couldn't resolve reference to VariableDeclaration 'b'.' on CreateWhatPart, offset 111, length 1
ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Linking) 'Couldn't resolve reference to VariableDeclaration 'c'.' on CreateWhatPart, offset 124, length 1


But why as I really have the variable declarations?

My grammar is

grammar org.blockchain.rell.Rell with org.eclipse.xtext.common.Terminals

generate rell "http://www.blockchain.org/rell/Rell"

Model:
	entities+=(ClassDefinition )*
	operations+=(Operation )*;

ClassDefinition:
	'class' name=ID ('extends' superType=[ClassDefinition])? '{'
	attributeListField+=AttributeListField*
	'}';



AttributeListField:
	mutable=Mutable? key=Key? index=Index? attributeList+=RelAttrubutesList ';';

Operation:
	"operation" name=ID "(" parameters=RelAttrubutesList? ")" "{" statements+=Statement* "}";



Statement:
	(relation=Relational | variable=OperationVariable|varInitiation=VarInitiation) ';';

VarInitiation:
	VariableDeclarationRef ('=' expression=Expression)?
;

OperationVariable:
	assessModificator=(Var | Val) variable=Variable;

Variable:
	name=VariableDeclaration (('=' expression=Expression)?);

Relational:
	 Create ;





Create:
	'create' (entity=[ClassDefinition]) '(' (createWhatPart+=CreateWhatPart (','
	createWhatPart+=CreateWhatPart)*)? ')';



CreateWhatPart:
	(varDeclRef=[VariableDeclaration|ValuableID] '=')?
	condition+=Expression;





TupleValue:
	'(' members+=TupleValueMember (',' tuplePart+=TupleValueMember)* ')';

ListCreation:
	'[' arguments=Arguments ']' ('.' LIST_METHOD listMethodArguments+=ArgumentsInBrackets)*;

MapCreation:
	'[' mapPart+=MapCreationPart (',' mapPart+=MapCreationPart)* ']' ('.' MAP_METHOD listMethodArguments+=ArgumentsInBrackets)*
;

NewListCreation:
	List {NewListCreation} (specification=ListSpecification?) 
	'(' 
		(
			(
				listCreation=ListCreation|
				newListCreation=NewListCreation|
				newSetCreation=NewSetCreation
			)?
		) 
		')' ('.' LIST_METHOD arguments+=ArgumentsInBrackets)*;

NewMapCreation:
	Map {NewMapCreation	}specification=MapSpecification? '(' (creation=ListCreation?) ')' ('.' MAP_METHOD arguments+=Arguments )*;

NewSetCreation:
	Set {NewSetCreation} (specification=ListSpecification?) 
	'(' 
		(
			(listCreation=ListCreation|newListCreation=NewListCreation|newSetCreation=NewSetCreation)?
		) 
	')' 
	('.' LIST_METHOD arguments+=ArgumentsInBrackets )*;


TupleValueMember:
	(name=ValuableID '=')? value=Expression;

ClassMemberDefinition:
	(classRef=ClassRef)? "." variableDeclarationRef=VariableDeclarationRef;

ClassRef:
	value=[TableNameWithAlias];

TableNameWithAlias:
	{ClassRefDecl} (name=ID COLON classDef=[ClassDefinition]) |
	{JustNameDecl} name=[ClassDefinition];

VariableDeclarationRef:
	decl=[VariableDeclaration|ValuableID];

Arguments:listPart+=Expression (','  listPart+=Expression)*;

ArgumentsInBrackets: '(' {ArgumentsInBrackets} arguments=Arguments? ')';


Expression:
	or=Or;

Or returns Expression:
	And ({Or.left=current} "or" right=And)*;

And returns Expression:
	Equality ({And.left=current} "and" right=Equality)*;

Equality returns Expression:
	Comparison ({Equality.left=current} op=(EQUALS | NOT_EQUALS|EQUALSS|NOT_EQUALSS)
	right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} op=(MORE_EQUAL | LESS_EQUAL | MORE | LESS)
	right=PlusOrMinus)*;

PlusOrMinus returns Expression:
	MulOrDiv (({Plus.left=current} PlusChar | {Minus.left=current} MinusChar)
	right=MulOrDiv)*;

MulOrDiv returns Expression:
	Primary ({MulOrDiv.left=current} op=(MulChar | DivChar)
	right=Primary)*;

Primary returns Expression:
	'(' Expression ')' |
	{Not} "not" expression=Primary |
	Atomic;

Atomic returns Expression:
	{IntConstant} value=IntWithMinus |
	{StringConstant} value=STRING |
	{ByteArrayConstant} value=BYTE_ARRAY_VALUE |
	{BoolConstant} value=('true' | 'false') |
	{MemberDefinition} value=ClassMemberDefinition |
	{CreateAtom} value=Create 
	| {TupleRes} value=TupleValue
	| {ListCreation} value=ListCreation
	| {MapCreation} value=MapCreation
	| {NewLCreation} value=NewListCreation
	| {NewSCreation} value=NewSetCreation
	| {NewMCreation} value=NewMapCreation
	| {TheNull} value=NULL
	|{VariableRef} value=VariableDeclarationRef;


MapCreationPart:exprKey=Expression COLON exprValue=Expression;

RelAttrubutesList:
	value+=Variable (',' value+=Variable)*;

VariableDeclaration:
	name=ValuableID ((COLON type=TypeReference)?);
	
TupleVarDeclaration:
	(name=ValuableID COLON)? type=TypeReference;

TypeReference:
	primitive=PrimitiveType | entityType=ClassType | tuple=TupleType | list=ListType|set=SetType|map=MapType;

ListType:
	List ListSpecification;
SetType:
	Set ListSpecification;

MapType:
	Map MapSpecification;
ListSpecification:
	LESS listType=TypeReference (QuestionChar?) MORE;
	
MapSpecification:
	LESS keySpec=TypeReference (QuestionChar?) ',' valSpec=TypeReference (QuestionChar?) MORE;

TupleType:
	'(' varDecl+=TupleVarDeclaration (',' varDecl+=TupleVarDeclaration)* ')';

ClassType:
	type=[ClassDefinition];

PrimitiveType:
	Text | Tuid | Pubkey | Name | Timestamp | Integer | Json | ByteArray | Boolean;

ValuableID:
	PrimitiveType | ID;

AmpersandModificator:
	PlusChar | MulChar | QuestionChar;

IntWithMinus:MinusChar? INT;

Name:
	'name';

Pubkey:
	'pubkey';

Timestamp:
	'timestamp';

 Tuid:
	'tuid';

Boolean:
	'boolean';

Json:
	'json';

Integer:
	'integer';

Text:
	'text';

ByteArray:
	'byte_array';

List:
	'list';

Map:'map';

Set:
	'set';

Key:
	'key';

Index:
	'index';

Mutable:
	'mutable';

Var:
	'var';

Val:
	'val';

Ampersand:
	'@';

QuestionChar:
	'?';

PlusChar:
	'+';

MinusChar:
	'-';

MulChar:
	'*';

DivChar:
	'/';
	
LIST_METHOD:
	"add"|"addAll"|"contains"|"containsAll"|"removeAll"|"calculate"|"sub"|"size"|"str"|"remove"|"removeAt"|"clear"|"empty"
	;
	
MAP_METHOD:"empty"|"size"|"contains"|"get"|"str"|"clear"|"put"|"putAll"|"remove"|"keys"|"values";	
//terminal SET_METHOD:LIST_METHOD;
	
terminal EQUALS:
	'==';
terminal EQUALSS:
	'===';

terminal NOT_EQUALS:
	'!=';
	
terminal NOT_EQUALSS:
	'!==';

terminal MORE_EQUAL:
	'>=';

terminal LESS_EQUAL:
	'<=';

terminal MORE:
	'>';

terminal LESS:
	'<';

terminal COLON:
	':'
;


terminal NULL:
	'null';

terminal BYTE_ARRAY_CHAR:
	'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D'
	| 'E' | 'F';

terminal BYTE_ARRAY_PAIR:
	BYTE_ARRAY_CHAR BYTE_ARRAY_CHAR;

terminal BYTE_ARRAY_VALUE:
	'x' (('\'' BYTE_ARRAY_PAIR* '\'') | ('"' BYTE_ARRAY_PAIR* '"'));


Re: Parsing error:coudn't reslolve reference [message #1802127 is a reply to message #1802125] Fri, 01 February 2019 15:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you should implement scoping to get this running

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parsing error:coudn't reslolve reference [message #1802194 is a reply to message #1802127] Sun, 03 February 2019 18:23 Go to previous messageGo to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Ok, so without scoping it will not work?
Re: Parsing error:coudn't reslolve reference [message #1802197 is a reply to message #1802194] Sun, 03 February 2019 21:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Yes and no. You can implement name provider eg binding SimpleNameProvider and thus affect scoping indirectly but the result may not be as expected if you have many classes

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:NoSuchMethodError when running Maven
Next Topic:Xtext & Xtend 2.17.0.M2 + MWE 2.10.M2
Goto Forum:
  


Current Time: Fri Apr 26 09:55:13 GMT 2024

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

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

Back to the top