Python Forum
parsing text with ply (lex/yacc) tool - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: parsing text with ply (lex/yacc) tool (/thread-8530.html)



parsing text with ply (lex/yacc) tool - bb8 - Feb-24-2018

i need to parse a file which contains some kind of data. i've looked at tutorials but i'm a little bit confused how to apply it to my case.

so the file is going to contain something like this (i'm putting the types of the data):
string number
string
number number number date/time
string
char number number
number number
number number
number number
number number
string
# comment
...
these are the values. each mean something. but as you can see i don't have key-value pairs here. that is why i'm confused how to do it all.

please help!


RE: parsing text with ply (lex/yacc) tool - nilamo - Feb-24-2018

If the only keys you have for the values are which line they're on, then you probably can't use a tool. You'll need to open the file, and process it line-by-line into whatever format you want.


RE: parsing text with ply (lex/yacc) tool - bb8 - Feb-25-2018

the file consists of, say 1000 such records that have the same structure as above. what about that? can i give a structure as a rule?