How can I describe a grammar using regex (or pyparsing is better?) for a script languge presented below (Backus–Naur Form):
<root> := <tree> | <leaves>
<tree> := <group> [* <group>]
<group> := "{" <leaves> "}" | <leaf>;
<leaves> := {<leaf>;} leaf
<leaf> := <name> = <expression>{;}
<name> := <string_without_spaces_and_tabs>
<expression> := <string_without_spaces_and_tabs>
Example of the script:
{
stage = 3;
some.param1 = [10, 20];
} *
{
stage = 4;
param3 = [100,150,200,250,300]
} *
endparam = [0, 1]
I use python re.compile and want to divide everything in groups, something like this:
[ [ 'stage', '3'],
[ 'some.param1', '[10, 20]'] ],
[ ['stage', '4'],
['param3', '[100,150,200,250,300]'] ],
[ ['endparam', '[0, 1]'] ]
Updated: I've found out that pyparsing is much better solution instead of regex.