Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar for ignore string(xtext grammar )
grammar for ignore string [message #1855515] Wed, 19 October 2022 07:49 Go to next message
vikash singh is currently offline vikash singhFriend
Messages: 6
Registered: September 2019
Junior Member
FeatureList:
        (elements+=Feature)*;
        
    Feature:
        name= ID';' selection=BooleanConstant ';' *;
    
    BooleanConstant:
        val=BooleanValue;
    
    enum BooleanValue:
        FALSE='FALSE' | TRUE='TRUE';
        
   

this is my grammar to parse a file where format is
ActSrv;TRUE;123;
xyz;TRUE;12av;
xyz1;TRUE;abc12;
xyz2;FALSE;123abc;34gh;
xyz3;FALSE;@cb98;xyp;
xyz4;TRUE;;


my requirement is to ignore all string after 2nd ';' or end the matcher and start from new row. but with the current code if there is anything after second column start with string getting stored in new name variable
Re: grammar for ignore string [message #1855546 is a reply to message #1855515] Thu, 20 October 2022 07:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7663
Registered: July 2009
Senior Member
Hi

Surely this is easily handled by emulating the single line comment?

terminal SL_COMMENT:
'--' !('\n' | '\r')* ('\r'? '\n')?;

You can just use ';' as the comment character.

Regards

Ed Willink
Re: grammar for ignore string [message #1855639 is a reply to message #1855546] Tue, 25 October 2022 07:03 Go to previous messageGo to next message
vikash singh is currently offline vikash singhFriend
Messages: 6
Registered: September 2019
Junior Member
Hi
thanks for your reply . with the single comment logic its commenting the 2nd column too.

1st column : ActSrv;
2nd column: TRUE;

if i mention ";" as comment character it will comment 2nd column( True) too . but i need to comment every thing after TRUE.

[Updated on: Tue, 25 October 2022 07:03]

Report message to a moderator

Re: grammar for ignore string [message #1855651 is a reply to message #1855639] Tue, 25 October 2022 18:29 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7663
Registered: July 2009
Senior Member
Hi

It should work, but since you don't share your code with us we cannot see if you have done something stupid.

I suggest debugging the traditional SL_COMMENT which works and gradually evolve it to what you want.

Regards

Ed Willink
Re: grammar for ignore string [message #1855663 is a reply to message #1855651] Wed, 26 October 2022 04:42 Go to previous messageGo to next message
vikash singh is currently offline vikash singhFriend
Messages: 6
Registered: September 2019
Junior Member
grammar com.contiautomotive.featurebase.FeatureReader with org.eclipse.xtext.common.Terminals

generate featureReader "http://www.contiautomotive.com/featurebase/FeatureReader"

FeatureList:
(elements+=Feature)*;

Feature:
name=ID ';' selection=BooleanConstant;

BooleanConstant:
val=BooleanValue;


enum BooleanValue:
FALSE='FALSE' | TRUE='TRUE';



@Override
terminal SL_COMMENT : ';' !('\n'|'\r')* ('\r'? '\n')?;
Re: grammar for ignore string [message #1855664 is a reply to message #1855663] Wed, 26 October 2022 04:59 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7663
Registered: July 2009
Senior Member
Hi

Firstly, since you are replacing SL_COMMENT, you must replace it else run the risk of allowing Xtext's built-in functionality to confuse.

Secondly, the traditional SL_COMMENT as shown in terminal is hidden. As a non-hidden token there may be a different whitespace interaction.

You should start by copying and pasting Terminais.xtext at the top of your grammar, then change the grammar name, then adjust the SL_COMMENT..

Regards

Ed Willink

[Updated on: Wed, 26 October 2022 05:11]

Report message to a moderator

Previous Topic:Xtext 2.29.0.M2 is out
Next Topic:Trying to resolve all cross-references of an EObject model from an .aadl file.
Goto Forum:
  


Current Time: Mon Jul 15 05:43:35 GMT 2024

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

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

Back to the top