How to create a Parser in Python?

1

For a file-driven project, I wanted to convert from "CFG" to "XML", and I believe Python does not support either of these types.

There was a colleague who did the modification manually, so we could study the XML. Here are the respective CFG and XML structures:

CFG: link

XML: link

Well I'm sort of a "go-between" in Python, but I have a problem with HOW I'm going to do it. I've read the source of ConfigParser and I saw that it used the re module, but how do I use this module.

Anyway, do I have to invent a parser for both? If you can not send me a code (of course you can not), but can you tell me the following idea?

I was thinking of doing this:

Identify in CFG the data types, what is Section and what is Given . < Create a sort of temporary dictionary with the received data.
Then rewrite the data in an XML file according to separate types. Creating an XML tree.

    
asked by anonymous 14.01.2017 / 14:22

1 answer

1

Probably ConfigParser can be adapted to read the type of CFG you are using. However, writing a parser is a great way to learn and practice Python. In my case, that's how I started learning Python.

How to create a parser in Python?

You can do this using pure Python, without importing any modules. Basically it is an exercise of string 's manipulation. Of course, there are more efficient ways of doing the same, for example, using that re (module that handles regex,

19.02.2017 / 16:04