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 vyv
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 Dietrich
Messages: 6385
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.
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: Thu Oct 23 17:54:47 GMT 2014

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

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