Is there a way to recursively parse the string to get the dict?
string:
string = 'a {\
b: text;\
c {\
d: text;\
}\
}';
out:
{
'a' : {
'b': 'text',
'c': {
'd' : 'text';
}
}
}
upd:
I’m new in Python, and I don’t have a ready solution in the form of a library and etc, I want to understand the logic (any code if it possible or theory) of the algorithm for this problem
You should have a look at the pyparsing module.
For a case like this, you would write the grammar that describes the string you are trying to parse, and avoid writing the parser.
Update (per comment): If one was interested in learning about the theoretical basis behind parsing strings such as these, then you need to understand what your goal is. This problem, in a more general form, is parsing a context-free language. You have a set of rules, known as a grammar that dictates the hierarchy of the data structure from the input. A good place to start reading (from an educational perspective) is the Backus–Naur Form.