本文介绍了XText 不提供的 ANTLR 有哪些功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到了非常好的工具 Xtext 来创建 DSL 以及用于编辑的 IDE.我在网上进行了一些搜索,发现有人说它没有提供 ANTLR 的所有功能.我使用 ANTLR 作为我的解析器生成器.

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.

我什至不确定 ANTLR 的哪些功能我需要为我的语言编写完整的解析器,但 ANTLR 已经存在了很长时间,并且可能支持比 Xtext 更多的功能.

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.

谁能举例说明不能在 Xtext 语法中指定的内容?

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

推荐答案

您不能在 Xtext 语法中指定语义谓词.此外,不可能在 Xtext 中包含任意操作(阅读:目标语言代码块).唯一支持的目标平台是 Java.

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.

好消息是,Xtext 通过引入这些约束获得了巨大的好处,例如您将获得一个解析器,它允许序列化与您的语法匹配的任意模型/语法图.说到语法图,使用 Xtext,您将获得您的语言的类型化 AST,您可以在 IDE 中对其进行编辑.

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.

Xtext 表示中唯一的语法特征是无序组.也就是说,您可以直接表示语法中的某些元素可能以任意顺序出现,但每个元素只出现一次.如果您考虑使用 java 修饰符,这可能非常方便:

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

查看 Xtext 文档,了解有关语法语言的更多详细信息.

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

这篇关于XText 不提供的 ANTLR 有哪些功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 09:39