简体   繁体   中英

Referring to generated types in Xtext/Xbase grammar

I am working on an Xtext grammar using Xbase. The grammar permits the user to create a set of Java classes with supertypes from one DSL file. I therefore created a rule like the following:

javaClass:
  name=ID ':' supertype=JvmParameterizedTypeReference

My generator for the class files works very well as long as the type does not refer to a class file that is being created by the DSL. When a class ClassA is created for example in line 3, and another class ClassB with supertype=ClassA defined in line 4, the parser does not accept the file.

I know this is because ClassA is not a known type when ClassB is parsed, because the generator is started after the whole file have been parsed.

Is it nevertheless possible to solve my problem and enable users to refer to classes that were declared earlier in the same DSL file?

Do you infer a JVM model? It allows first index available classes and then infers JVM models for them when all classes are known. See: https://eclipse.org/Xtext/documentation/305_xbase.html#xbase-inferred-type

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM