Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » scoping for typedef element(scoping for typedef element)
scoping for typedef element [message #1044789] Fri, 19 April 2013 10:51 Go to next message
vyv vyv is currently offline vyv vyvFriend
Messages: 3
Registered: April 2013
Junior Member
Hi,

I am stuck with supporting of below syntax.

comapny1 {
employee1{
day Tuesday {
date = 2nd march ;
}
}
}

FOREACH X IN company1 [FIRST : LAST] {
X.employee1 = 2 ;
}
In FOREACH loop after typing X. if I do ctrl+space employee1 should pop up automatically. If I write X.employee2 = 2 in FOREACH loop it should show error. Because employee2 is not an element of comapany. How to implement this ? Please can anyone provide the solution for my problem..?

The xtext grammer is to support the above syntax is:
Model:
(greetings=node)
(operationss=operation)
;


node:
(( name=ID ) "{"
( fields=employee_definition1 )
"}"
)
;



employee_definition1:
name=ID '{'
(days+=dayDef+)
'}'
;

dayDef:
(fldname="day" name3=ID '{' date=datedef '}' )
;

datedef:
id1="date" "=" no="2nd" month=ID ';'
;

FieldType:
node
;

Head:
headable=[FieldType]
;

udf:
employee_definition1
;

Tail:
tailable=[udf]
;

operation:
name="FOREACH" '(' foreach_conds1=foreach_conds ')' '{'
(operations1+=operationsforeach)+ '}'
;
foreach_conds:
name=ID in="IN" id2=Head '[' rangeBegin1="FIRST" ':' rangeEnd1="LAST" ']'
;

operationsforeach :
name=ID "." id4=ID '=' intdef=INT ';'
;

Re: scoping for typedef element [message #1044924 is a reply to message #1044789] Fri, 19 April 2013 14:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi there are tons of threads on this (scoping)

you basically

(1) use refs and not IDs
(2)collect the stuff and put it into scope
Model:
	entities+=Entity*
	uses+=Use*
	;

Entity:
	"entity" name=ID "{"
		attributes+=Attribute*
	"}"
;

Attribute:
	name=ID
;

Use:
	"use" var=Var "{"
		"whatever" varref=[Var] "." attr=[Attribute]
	"}"
;

Var:
	entity=[Entity] "as" name=ID
;

 */
class MyDslScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider {

	def IScope scope_Use_attr(Use ctx, EReference ref) {
		return Scopes::scopeFor(ctx.varref.entity.attributes)
	}
	def IScope scope_Use_varref(Use ctx, EReference ref) {
		return Scopes::scopeFor(newArrayList(ctx.^var))
	}

}


btw your naming conventions are aweful.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:A couple of questions about Scope
Next Topic:Compile Xbase expression at arbitrary position using JvmModelInferrer and XbaseCompiler in Xtext 2.4
Goto Forum:
  


Current Time: Fri Apr 26 15:56:42 GMT 2024

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

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

Back to the top