Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Assign parts of input to string property(Ways to ignore but save parts of the input)
Assign parts of input to string property [message #636472] Mon, 01 November 2010 14:03 Go to next message
Marc Hamilton is currently offline Marc HamiltonFriend
Messages: 11
Registered: July 2009
Junior Member
I'm defining a grammar for an existing language.
For several reasons (one is to limit my grammar to my interest in the input), I want to ignore part of the input, and assign it as a string to a property wthin a rule, e.g.:

Example:
trial TestSection {
   // here's a lot of stuff that I don't need
   Type field <field properties>;
  OtherType otherfield;
  YetAnotherType yetanotherfield <default=[22/#7 + @3]>;
}


should result into an EObject like:

TrialDeclaration {
    name = "TestSection";
    trialContent = "// here's a lot....  @3]>;"
}

Using a terminal rule like
terminal ignoreText : '{' -> '}';

is not working while it will also apply this terminal rule to other parts that should be parsed, like class XX { ...};
So I need a solution that limits to the context of the rule.

I'm trying to define rules in a pattern like
TrialDeclaration:
'trial' name = ID '{'
   tryContent=InputAsText
'}';

but all my attempts to define 'InputAsText' do not have the desired result. It feels like I'm overlooking something trivial... Confused

Is there a general applicable solution to do this kind of 'partial' syntax parsing?

I'd prefer to have the input in a property, so it could later perhaps be fed into another language interpreter.
Re: Assign parts of input to string property [message #636512 is a reply to message #636472] Mon, 01 November 2010 16:13 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

it is unlikely that a terminal rule will help you here. Rather use a datatype rule (note the non-existing "terminal" before the rule name)

InputAsText hidden():
(WS|INT|ID|ML_COMMENT|SL_COMMENT|...)*;
/*List of all terminal rules and keywords in your grammar that may appear within that section*/

Alex
Previous Topic:Lexer/Parser issue
Next Topic:Referencing other models in other files
Goto Forum:
  


Current Time: Fri Apr 26 07:11:11 GMT 2024

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

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

Back to the top