Hey folks! I'm working on a new xtext2-based project to describe basic scripted actions and workflows and I've been looking all over for a pattern to model scope access of subproperties through variable references. Think objects with attributes and functions. So I might have an object called "Database" that has a child object called "Table" that has some actions that can be performed on it.

My question is how to get the ActionStatement to behave how you'd expect in an object-oriented kind of way using the variable as a reference. As it sits in the grammar now, the editor will allow things like

Database.listTables()
Database.Table.selectAll()

Instead, I'd like it to do things like

db.listTables()
db.Table.selectAll()

I've been reading the documentation and the forums looking for examples of doing this with the scope API, and I briefly tried changing ActionStatement to the following:

I implemented the methods "scope_ActionStatement_variable(...)" and scope_ActionStatement_action(...)" to only offer actions visible as children under defined variables. This allowed "db.listTables()", but did not allow for arbitrarily traversing child resources to get to an action lower down in the tree.

So the short of it: using the scope API or grammar changes, how do I get the editor to treat variable declarations like the resource itself in resolving qualified references to children or actions? As always, thanks so much for the help!

I initially tried to use '.' as my separator for everything for a more Java-like path style, but I couldn't seem to resolve the ambiguities in the grammar between that and the method call itself and the qualified names. This is fine for my purposes though - thanks for the help!

First of all, there's contention between QualifiedName (a datatype rule) and any rule which is allowed to gobble up an ID after a '.'. You could resolve this but in the process you'll probably be promoting each path element to a separate model element instead of gobbling them all up into one String - this could even be a good thing if you need a hook to exert some control/validation over the path elements themselves. Otherwise, the parser just has no way to know whether a following ".yaddaYadda" should be part of a QualifiedName or whether it corresponds to some nested Resource or ActionDeclaration.

I have to do the similar task. For learing purpose I have pasted your code and tried to execute the grammer. But a function ScopeFor() is missing and I have no idea how to implement it. If you can, can you give that function?