Can Lark parse rpm spec file format?
What is your question?
Can Lark parse files like this one? How?
I've tried implementing the grammar, but can't figure out how to do these two things:
- Parse until the next section
- Parse based on current state
Spec file's "sections" (like%description, %build, %prep, etc.) don't have concrete begin and end markers (like { and } in Java). I couldn't figure out how to parse until the next known section either.
Thanks in advance! 🩵
I also couldn't find a way to store the current state during the lexing stage. This is how PLY does it, for example: "4.19 Conditional lexing and start conditions".
Lark by default switches the lexer context automatically, so usually you won't need to do any manual changes like in PLY.
But if you need more control over the parsing process, you should be able to get everything you need by using the interactive parser (see Lark.parse_interactive())
So, do you suggest that interactive mode is the only viable option to parse such file format?
Input:
%foo
12345
%bar
67890
Output:
result = {
"foo": 12345,
"bar": 67890,
}
The example in this reply is something lark can handle easily, without any special techniques.