Parse a text with selfdescribing rules [message #1733387] |
Thu, 26 May 2016 23:54  |
Eclipse User |
|
|
|
Hi,
How can I parse the content of the file when I have the structure of the following elements described in a header?
Let's say I want to have "person tables" where the first line contains :
- how many elements will follow
- the length of the FirstName field
- the length of the LastName field
- the length of Age field
- the length of Address field
To be more complicated, some elements might not have the full length (for example the Address field is missing or incomplete).
Here is an example of such file (there is one space between element's fields) :
2 FirstName 10 LastName 10 Age 3 Address 50
Jon Snow 28 Castle Black
Ayra Stark 15 Bravos
1 LastName 12 FirstName 12 Age 3 Address 50
Lannister Tyrion 30
Thank you
[Updated on: Thu, 26 May 2016 23:56] by Moderator Report message to a moderator
|
|
|
Re: Parse a text with selfdescribing rules [message #1733395 is a reply to message #1733387] |
Fri, 27 May 2016 08:35  |
Eclipse User |
|
|
|
Hi
There was a famous observation that regular expressions cannot count.
This extends to grammars. You need counts.
You have a simple problem. Solving it with Xtext is perhaps possible but
highly inappropriate.
I suggest that you have a small set of text acceptor classes and a state
machine to arbitrate bwetween them. It will be much quicker to develop
and you'll understand it.
If you want to use the benefits of an autogenerated Xtext editor, I
suggest defining a sensible grammar and a transformation from legacy to
sensible format.
Regards
Ed Willink
On 27/05/2016 00:54, Mihai Traistariu wrote:
> Hi,
> How can I parse the content of the file when I have the structure of
> the following elements described in a header? Let's say I want to have
> "person tables" where the first line contains :
> - how many elements will follow
> - the length of the FirstName field
> - the length of the LastName field
> - the length of Age field
> - the length of Address field
> To be more complicated, some elements might not have the full length
> (for example the Address field is missing or incomplete).
>
> Here is an example of such file (there is one space between element's
> fields) :
>
> 2 FirstName 10 LastName 10 Age 3 Address 50
> Jon Snow 28 Castle Black
> Ayra Stark 15 Bravos
> 1 FirstName 12 LastName 12 Age 3 Address 50
> Tyrion Lannister 30
>
> Thank you
|
|
|
Re: Parse a text with selfdescribing rules [message #1733409 is a reply to message #1733395] |
Fri, 27 May 2016 02:46  |
Eclipse User |
|
|
|
This is just part of a file which contains also other data definitions, but the implementation for those is not complex, straight forward xtext implementation. This is why I was thinking if I can do complete parsing using xtext (also, I have another parser already defined in my project, I'm using xtext already)
Can you please give me some details about your last suggestion?
Thank you.
|
|
|
Powered by
FUDForum. Page generated in 0.02586 seconds