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 |
Wayne Campbell 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 #1064507 is a reply to message #1064429] |
Wed, 19 June 2013 14:44 |
Ed Willink Messages: 7670 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?
|
|
| |
Goto Forum:
Current Time: Mon Sep 23 02:04:42 GMT 2024
Powered by FUDForum. Page generated in 0.04029 seconds
|