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 04:49  |
Eclipse User |
|
|
|
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 #1064507 is a reply to message #1064429] |
Wed, 19 June 2013 10:44   |
Eclipse User |
|
|
|
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 04:24  |
Eclipse User |
|
|
|
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!
|
|
|
Goto Forum:
Current Time: Tue Jul 22 20:05:45 EDT 2025
Powered by FUDForum. Page generated in 0.03981 seconds
|