0beron wrote: > Is there any way I can mess with the internals of an existing parser > object to 'prime' it to be in a different starting state? Ie let PLY > load the cached tables, create a parser, and then just tweak the > existing instance?
I don't know about parser internals, but maybe you don't need to. You can make a new start symbol, and introduce new tokens that select a rule to 'jump' to the right rule, eg begin: FORTRAN top | EXPRESSION expression ; now you just need to inject the right token to select a part of the grammar, ahead of the real tokens. One way would be to make a new token getter function that wraps the normal lexer. Another way can be to use lexer states, ie put the lexer in some unique state, and the one that happens is to emit a token, and jump to the 'normal' lexing state. The former is definitely possible, in the past I have made custom lexers and hooked them up to the ply parser by making a token getter function. I don't have a standard way of doing that. Note that I always wrap ply parsers and scanners in a class (which is non-standard for ply), so it may be a lot of work. About the second alternative, I have never used lexer states in ply, so I cannot say whether it is really feasible, and/or how much work that is going to be. Albert --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ply-hack" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/ply-hack?hl=en -~----------~----~----~----~------~----~------~--~---
