【问题标题】:Xtext - Multiline String like in YAMLXtext - YAML 中的多行字符串
【发布时间】:2018-04-15 17:49:17
【问题描述】:

我正在尝试在 Xtext 中为类似 YAML 的 DSL 建模。在这个 DSL 中,我需要一些 YAML 中的多行字符串。

description: | Line 1 line 2 ... 我的第一次尝试是这样的:

terminal BEGIN: 'synthetic:BEGIN'; // increase indentation terminal END: 'synthetic:END'; // decrease indentation terminal MULTI_LINE_STRING: "|" BEGIN ANY_OTHER END;

我的第二次尝试是 terminal MULTI_LINE_STRING: "|" BEGIN ((!('\n'))+ '\n')+ END; 但他们俩都没有成功。在 Xtext 中有没有办法做到这一点?

更新 1:

我也尝试过这种替代方法。

terminal MULTI_LINE_STRING: "|" BEGIN ->END

当我触发“Generate Xtext Artifacts”过程时,我得到了这个错误:

3492 [main] INFO nerator.ecore.EMFGeneratorFragment2 - Generating EMF model code 3523 [main] INFO clipse.emf.mwe.utils.GenModelHelper - Registered GenModel 'http://...' from 'platform:/resource/.../model/generated/....genmodel' error(201): ../.../src-gen/.../parser/antlr/lexer/Internal..Lexer.g:236:71: The following alternatives can never be matched: 1 error(3): cannot find tokens file ../.../src-gen/.../parser/antlr/internal/Internal...Lexer.tokens error(201): ../....idea/src-gen/.../idea/parser/antlr/internal/PsiInternal....g:4521:71: The following alternatives can never be matched: 1

【问题讨论】:

  • 你试过| BEGIN -> END;吗?

标签: yaml xtext emf


【解决方案1】:

This slide deck 展示了我们如何在 Xtext DSL 中实现空白块范围。

我们使用名为 BEGIN 的合成标记对应一个缩进,END 对应一个外缩。

(注意:该语言随后被重命名为 RAPID-ML,作为 RepreZen API Studio 的一个功能。)

【讨论】:

    【解决方案2】:

    我认为您的主要问题是,您尚未定义多行标记何时结束。在您找到解决方案之前,您必须在脑海中明确算法应如何确定令牌的结束。没有任何工具可以减轻您的这种精神负担。

    问题:没有结束标记字符。您必须定义这样的字符(与 YAML 不同)或以另一种方式定义标记的结尾。例如通过某种语义空白(我认为 YAML 就是这样做的)。

    第一种方法会使事情变得非常简单。只需阅读内容,直到找到结束字符。第二种方法可能可以使用自定义词法分析器进行管理。基本上,您将生成的词法分析器替换为您自己实现的能够计算空格或类似内容的解决方案。

    这里有一些关于如何做到这一点的起点(可以考虑不同的方法):

    【讨论】:

      猜你喜欢
      • 2014-01-20
      • 1970-01-01
      • 2017-07-22
      • 2016-10-22
      • 2020-01-27
      • 1970-01-01
      • 2011-04-16
      相关资源
      最近更新 更多