Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Comments in the AST
Comments in the AST [message #640653] Mon, 22 November 2010 17:16 Go to next message
Sean McFee is currently offline Sean McFeeFriend
Messages: 2
Registered: November 2010
Junior Member
In my textual DSL it was necessary to capture single-line comments in the AST so that they could be brought into a model. This was accomplished in oAW 4.3.1 by moving the default rule into the grammar as a Native type, as follows:

Native SL_COMMENT
: "'//' ~('\n'|'\r')* '\r'? '\n'";

You then must account for the many places in your language a comment can occur, which is tedious but doable.

Migrating to the Eclipse Xtext, this rule was replaced with a terminal type:

terminal SL_COMMENT
: "'//' ~('\n'|'\r')* '\r'? '\n'";

Comments now no longer parse at all. The parser error for any line in which a comment is inserted (at the start or mid-way) is:

mismatched input '/' expecting EOF

Multi-line comments, which were not overridden in the grammar, continue to parse correctly (but do not end up in the AST obviously).

Any idea how I can get this working again?

EDIT: This issue is resolved. Instead of importing the default Xtext terminals I deep-copied them into my grammar and imported ecore directly, and changed the grammar definition to not hide the comments. The definition of SL_COMMENT had changed slightly in the last couple of years and adopting the current one resolved the parse errors.

[Updated on: Mon, 22 November 2010 19:02]

Report message to a moderator

Re: Comments in the AST [message #640700 is a reply to message #640653] Mon, 22 November 2010 20:40 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
If I understood correctly, you don't want SL_COMMENT to be a hidden rule
anymore.
Please see the documentation on hidden terminals.
You'll have to add hidden(WS, ML_COMMENT) to your grammar declaration.

Sven

Am 11/22/10 6:16 PM, schrieb Sean McFee:
> In my textual DSL it was necessary to capture single-line comments in
> the AST so that they could be brought into a model. This was
> accomplished in oAW 4.3.1 by moving the default rule into the grammar as
> a Native type, as follows:
>
> Native SL_COMMENT
> : "'//' ~('\n'|'\r')* '\r'? '\n'";
>
> You then must account for the many places in your language a comment can
> occur, which is tedious but doable.
>
> Migrating to the Eclipse Xtext, this rule was replaced with a terminal
> type:
>
> terminal SL_COMMENT : "'//' ~('\n'|'\r')* '\r'? '\n'";
>
> Comments now no longer parse at all. The parser error for any line in
> which a comment is inserted (at the start or mid-way) is:
>
> mismatched input '/' expecting EOF
>
> Multi-line comments, which were not overridden in the grammar, continue
> to parse correctly (but do not end up in the AST obviously).
>
> Any idea how I can get this working again?


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Previous Topic:Cross-reference change RuleCall
Next Topic:Language mix-ins?
Goto Forum:
  


Current Time: Wed Apr 24 14:43:30 GMT 2024

Powered by FUDForum. Page generated in 0.02859 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top