How to get the list of classes for scope [message #1803009] |
Wed, 20 February 2019 12:37  |
Eclipse User |
|
|
|
Hi all, I have the grammar(see it below) and there is the following rule.
DotValue:
varRef=VariableDeclarationRef '.' (dotPart=DotValue?);
....
VariableDeclaration:
name=ValuableID ((COLON type=TypeReference)?)
...
VariableDeclarationRef:
decl=[VariableDeclaration|ValuableID];
As you can see, sometimes we don't specify the type of variable and get it from context. So the question is: in what way I can to get the ClassDefinition instance by className what I have in the variable?
Regards,
Vladimir
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)* ')';
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];
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
| {DotValue} value=DotValue
| {VariableRef} value=VariableDeclarationRef;
DotValue:
varRef=VariableDeclarationRef '.' (dotPart=DotValue?);
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:
'/';
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* '"'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.51689 seconds