Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » String without quotes - alternative to ugly datatype rules?
String without quotes - alternative to ugly datatype rules? [message #1064429] Wed, 19 June 2013 08:49 Go to next message
Wayne Campbell is currently offline Wayne CampbellFriend
Messages: 11
Registered: June 2013
Junior Member
Hey folks,

I am quite new to Xtext, so perhaps there is a quite simple solution for the following problem:

The file format I want to read in contains lines like
1,C1001,"100A_50B_0805_10%",C0805__Some_Text,2952,2480,3600,T;
735,U$10,"",MENTOR-DESC-4__Some_Text,2677,3543,3600,T;
740,X1001,"MSTBVA_2,5/4-G-5,08",MSTBVA_2_5/4-G-5_08__Some_Text,562,295,1800,T;


My problem is, that these lines can contain strings without quotes. For example, the last line should be interpreted like this:
lineID=740
name="X1001"
description="MSTBVA_2,5/4-G-5,08"
detailedDescription="MSTBVA_2_5/4-G-5_08__Some_Text"
x=562
y=295
z=1800
parameter="T"

At the moment, I try to achieve this by a datatype rule:
PartString:
	STRING | (INT | ID | ('ä' | 'Ä'| 'ö' | 'Ö' | 'ü' | 'Ü' | 'a..z' |'A..Z' | '.' | '$' | '-') )*
;


For this specific line, the parser throws the following exception:
message=no viable alternative at input '/'


Okay, no problem, I could just add | '/' to my rule and be happy. But this way, my datatype rule gets more and more ugly the more special cases I find in my source files.


Is there a way to do this in a more pretty way?
Re: String without quotes - alternative to ugly datatype rules? [message #1064506 is a reply to message #1064429] Wed, 19 June 2013 14:36 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

there may be simpler ways to instantiate a model from a csv-file than Xtext. But apart from that, you might want to reduce the terminals to an absolute minimum and use the ANY_OTHER rule in PartString (instead of a list of single character "keywords"). By the way, 'a..z' in PartString will really be that String not "any character between a and z". Those will be picked up by the ID rule already

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: String without quotes - alternative to ugly datatype rules? [message #1064507 is a reply to message #1064429] Wed, 19 June 2013 14:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You are misdiagnosing your problem. You do not have strings without
quotes. There is no such thing in CSV.

Your have comma-separated character sequences, and quoted character
sequences. Your terminal tokens should reflect this. Using the default
Xtext terminals will be very very hard.

Regards

Ed Willink


On 19/06/2013 15:15, Master Ofdesaster wrote:
> Hey folks,
>
> I am quite new to Xtext, so perhaps there is a quite simple solution
> for the following problem:
>
> The file format I want to read in contains lines like
>
> 1,C1001,"100A_50B_0805_10%",C0805__Some_Text,2952,2480,3600,T;
> 735,U$10,"",MENTOR-DESC-4__Some_Text,2677,3543,3600,T;
> 740,X1001,"MSTBVA_2,5/4-G-5,08",MSTBVA_2_5/4-G-5_08__Some_Text,562,295,1800,T;
>
>
>
> My problem is, that these lines can contain strings without quotes.
> For example, the last line should be interpreted like this:
> lineID=740
> name="X1001"
> description="MSTBVA_2,5/4-G-5,08"
> detailedDescription="MSTBVA_2_5/4-G-5_08__Some_Text"
> x=562
> y=295
> z=1800
> parameter="T"
>
> At the moment, I try to achieve this by a datatype rule:
>
> PartString:
> STRING | (INT | ID | ('ä' | 'Ä'| 'ö' | 'Ö' | 'ü' | 'Ü' | 'a..z'
> |'A..Z' | '.' | '$' | '-') )*
> ;
>
>
> For this specific line, the parser throws the following exception:
> message=no viable alternative at input '/'
>
> Okay, no problem, I could just add | '/' to my rule and be happy. But
> this way, my datatype rule gets more and more ugly the more special
> cases I find in my source files.
>
>
> Is there a way to do this in a more pretty way?
Re: String without quotes - alternative to ugly datatype rules? [message #1066569 is a reply to message #1064507] Wed, 03 July 2013 08:24 Go to previous message
Wayne Campbell is currently offline Wayne CampbellFriend
Messages: 11
Registered: June 2013
Junior Member
Thank you very much for your answers.

Indeed, if I just wanted to read comma separated values, there are much simpler ways to do so. Unfortunately the document I want to read in consists of some kind of a hierarchical structure, combined with those comma separated lines mentioned above. So, Xtext seems to be the right choice, even if parsing the csv parts is a pain-in-the-ass...

However, I will overthink the default terminal rules, as this seems to be the nicest way.

Thank you very much!
Previous Topic:Xtext: Referencing a Subpart of another DSL (and maybe scoping)
Next Topic:XBase path is unmapped
Goto Forum:
  


Current Time: Wed Apr 24 14:02:26 GMT 2024

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

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

Back to the top