Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parse a text with selfdescribing rules
Parse a text with selfdescribing rules [message #1733387] Thu, 26 May 2016 23:54 Go to next message
Mihai Traistariu is currently offline Mihai TraistariuFriend
Messages: 6
Registered: March 2016
Junior Member
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]

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 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6514
Registered: July 2009
Senior Member
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 Go to previous message
Mihai Traistariu is currently offline Mihai TraistariuFriend
Messages: 6
Registered: March 2016
Junior Member
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.
Previous Topic:Using Names from a text file inside the DSL
Next Topic:How to combine to different plugins
Goto Forum:
  


Current Time: Thu Nov 21 00:23:33 GMT 2019

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

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

Back to the top