parglare
parglare copied to clipboard
Question on AST generation and actions with side effects
- parglare version: 0.12
- Python version: 3.9
- Operating System: Windows x64 10
Description
- I have a big ebnf dictionary (with many rules) and I configured several actions which have side effect.
Could you suggest me how can I have parsing output in the format
not
['token_value']
but( token_name, 'token_value' )
I wrote the action:
def make_token(context, nodes):
if len(nodes) == 1:
nodes = (context.production.rhs[0].name, nodes[0])
return nodes
Example:
[('register', 'al'), ('INTEGER', '0')]]
But I want it to be a generic for all rules. I mean I don't want to define this action for all rules.
Since I want to do additional processing after parsing. Am I doing it wrong? Should all the processing done in the actions? I saw it will be actions with side effect added to parglare later. Do you see the parglare as alive project or you are going to develop something new?
-
As I understand parsing tree is similar to what I want. But it's structure is complex and if I enable building parse tree and call actions during the parsing the actions called in random order and sometimes twice. Probably twice is a bug, right?
-
Parglare is doing some magic to resolve recursions. Can it produce resulting human readable EBNF?
- If I understand you correctly, you could get (non)terminal names from the Grammar object and make a dictionary where keys would be those names and the value would be your
make_token
. Then, you can use the dict asactions
in Parser construction to attach your action to all rules. Yes, parglare is alive project. I'm using it actively and intend to maintain it for the foreseeable future. The development pace is slower at the moment as it has more or less all the features I need at the moment. Currently, with textX/Arpeggio and this project I don't plan to make another parsing framework for Python. Maybe in some other language :) - Not sure about that. With GLR parsing I think it is quite possible. That's why you shouldn't use actions with side effects with GLR. Or, you can first create the parse tree and then call action over that parse tree.
- What do you mean by
magic to resolve recursions
?