XText: use custom terminals definitions

点点圈 提交于 2019-12-06 00:48:15
Sebastian Zarnekow

You have plenty of options (all of them are documented in the online help):

  1. Define your terminal rules right in the grammar that your are currently working with.
  2. Create a new dedicated grammar for terminal symbols similar to what we did with the common.Terminals. Use that one instead of the common Terminals.
  3. Create a new dedicated grammar for terminal symbols, reuse the common.Terminals in that grammar and use your own terminal grammar in your actual language.

I'd recommend to just override the terminals that you want to change right in your language (option 1) or if your want to define multiple languages with the same set of terminals I'd use (option 3) or combine both options, e.g.

grammar org.mycompany.MyTerminals with org.eclipse.xtext.common.Terminals

terminal ID: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal SL_COMMENT: '--' !('\n'|'\r')* ('\r'? '\n')?;

==

grammar org.mycompany.MyLanguage with org.mycompany.MyTerminals

MyModel: name=ID other=ANOTHER;

terminal ANOTHER: '/#' -> '#/'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!