Reputation: 34071
I have the following text and would like to transform into a data structure.
The text is:
pcp-action:MESSAGE\npcp-channel:apc\:///\npcp-body-type:text\nPUBLIC:THISPK\nTOPIC:SEND\n\nHello Foo
I would like to know, if it makes sense to use Parser for it. To be honestly, I can not see the sense to use Parser
in this case, because the structure is not in BNF
like for example JSON
and it is not recursively enumerable.
When does it make sense to transform a text with Parser
into a data structure?
Update
I forget to mention the text above is based on the following description, that is written here https://blogs.sap.com/2015/07/27/specification-of-the-push-channel-protocol-pcp/.
It looks like, it is based on a grammar.
Upvotes: 0
Views: 76
Reputation: 15605
Like any tool, you should use a parser when it is suitable for the job. Turning strings into data structures is exactly what parsers are for.
This specific language is defined by a BNF and thus is also recursively enumerable (in fact, context-free) and so is a perfect candidate for parsing, but you can use a parser for all sorts of things. For example, log files may not have a defined BNF grammar but are often structured well enough in practice for parsing to be useful.
Upvotes: 4