What are features of ANTLR that XText Does not pro

2019-02-16 09:18发布

问题:

I just came across very nice tool Xtext to create DSL as well as IDE for editing. I did some search on the web and found people saying it does not provide all the features of ANTLR. I am using ANTLR as my parser generator.

I am not even sure what features of ANTLR I will need to write complete parser for my language but ANTLR is around for quite a long time and probably supports more features than Xtext.

Can anyone please give some examples of what CANNOT be specified in a Xtext grammar?

回答1:

You cannot specify semantic predicates in an Xtext grammar. Furthermore it's not possible to include arbitrary actions (read: target language code blocks) with Xtext. The only supported target platform is Java.

The good news is, that Xtext gains great benefit by inducing these constraints, e.g. you'll get an unparser that allows to serialize arbitrary models / syntax graphs that match your grammar. Speaking about syntax graphs, with Xtext you'll get a typed AST for your language that you can edit in your IDE.

A grammar feature that is unique in Xtext's representation are unordered groups. That is, you can directly express that certain elements in your grammar may occur in arbitrary order but each one only once. If you think about the java modifiers, this may be very handy:

  visibility=('public'|'private') // this is a mandatory assignment
& abstractOrFinal=('abstract'|'final')? // this is optional
& static?='static'? // this will become a boolean value in your ast

Have a look at the Xtext docs for more details on the grammar language.