问题
i am very lost with how importing global scope is working. I am writing a parser with xtext for a well structure language and I cannot depend on workspace or project concepts. In my language I have include statements which can have relative or absoloute paths of another file. I need to be able to reference objects defined in this other file. I tried using importURI but it doesn't work. All I tried was to add this rule:
Include:
'INCLUDE' '=' importURI=STRING ';'
;
and changed the MWE2 file in these parts:
// scoping and exporting API
fragment = scoping.ImportURIScopingFragment {}
// fragment = exporting.SimpleNamesFragment {}
// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment {}
fragment = exporting.QualifiedNamesFragment {}
But this doesn't make any effect in my editor. I still can refer to objects defined in every file with the same extension without having the include statements, and I still cannot include files outside of the project.
回答1:
You have to remove the ImportNamespacesScopingFragment. It configures your language to use name based scopes rather than file-based.
You may also want to dig into the IContainer.Manager which is configured with an implementation based on the Eclipse workspace and project concept, by default.
回答2:
the solution was to remove these two from workflow.
// provides the necessary bindings for java types integration
// fragment = types.TypesGeneratorFragment {}
// generates the required bindings only if the grammar inherits from Xbase
//fragment = xbase.XbaseGeneratorFragment {}
来源:https://stackoverflow.com/questions/17034734/xtext-importuri-external-file