XText cross-referencing: How to establish references between locally unique IDs, using their context as a qualifier? -
i have problem cross-referencing terminals locally unique (in block/scope), not globally. found tutorials describe, how can use qualified names or package declarations, case syntactically little bit different example , cannot change dsl support explicit qualified names or package declarations.
in dsl have 2 types of structured json resources:
- the instance contains data.
- a meta model, containing type information etc. data.
i can parse two, , emf model following java snippet:
new mydslstandalonesetup().createinjectoranddoemfregistration(); resourceset rs = new resourcesetimpl(); rs.getresource(uri.createplatformresourceuri("/foo/meta.json", true), true); resource instanceresource= rs.getresource(uri.createplatformresourceuri("/bar/instance.json", true), true); eobject eobject = instanceresource.getcontents().get(0);
simplyfied example:
meta.json
{ "toplevel_1": { "sublevels": { "sublevel_1": { "type": "int" }, "sublevel_2": { "type": "long" } } }, "toplevel_2": { "sublevels": { "sublevel_1": { "type": "float" }, "sublevel_2": { "type": "double" } } } }
instance.json
{ "toplevel_1": { "sublevel_1": "1", "sublevel_2": "2" }, "toplevel_2": { "sublevel_1": "3", "sublevel_2": "4" } }
from want infer that:
- toplevel_1:sublevel_1 has type int , value 1
- toplevel_1:sublevel_2 has type long , value 2
- toplevel_2:sublevel_1 has type float , value 3
- toplevel_2:sublevel_2 has type double , value 4
i able cross-reference unique toplevel-elements , iterate on sublevels until found ones looking for, use case quite inefficient , complicated. also, don't generated editor link between sublevels way.
i played around linking , scoping, i'm unsure need, , if have extend providers-classes abstractdeclarativescopeprovider and/or defaultdeclarativequalifiednameprovider.
what's best way go?
see also:
after trial , error solved problem scopeprovider. main issue didn't understand scope in xtext-terms, , have provide to.
looking @ signature documentation:
iscope scope_<refdeclaringeclass>_<reference>(<contexttype> ctx, ereference ref)
in example language:
- refdeclaringeclass refer sublevel instance.json,
- reference cross-reference sublevel meta.json, and
- contexttype match refdeclaringeclass.
using econtainer of ctx can toplevel instance.json. toplevel has cross-reference matching toplevel meta.json, can use sublevels meta.json. collection of sublevels scope within current sublevel should unique.
to iscope used scopes#scopefor(iterable).
i didn't post code here because actual grammar bigger/different, , therefore doesn't explanation.
Comments
Post a Comment