You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, whenever the user presses tab to request completion, I parse the currently edited string according to a grammar and upon the occurence of the injected TAB token I inspect the current state of the parser.
This way I get all the terminals and rules that apply at the specific point where the user pressed TAB. This information can then be used collect the potential completions, making it pretty easy to implement tab completion for LALR(1) grammars.
Right now, "state" is not published anywhere, it is a local variable within the parse() function, which I look up using sys._getframe(). This is of course fragile and was recently broken due as the part that called the error handler function was extracted into a separate function in ply 3.6.
I see that statestack is published in the parser and its last element should be equal to the current state, however I am not entirely sure.
If I got some help I would be willing to contribute a patch.
Thanks.
The text was updated successfully, but these errors were encountered:
Modified the parser to set a "state" attribute before calling any production or error function. You'll need to keep a reference to the parser to get it.
The yacc implementation we are using (ply), didn't publish its state
variable, requiring us to look that up using sys._getframe() calls, which
was pretty fragile.
@dabeaz was nice enough to add this function to ply in 2016 (version 3.9),
which has now trickled into various distributions, so the hack can be removed.
dabeaz/ply#65
Signed-off-by: Balazs Scheidler <balazs.scheidler@balabit.com>
I have a use-case where I am using ply generated grammar for a programmable tab-completion infrastructure.
This is the one: https://github.com/balabit/syslog-ng/blob/master/modules/python/pylib/syslogng/debuggercli/completerlang.py
Basically, whenever the user presses tab to request completion, I parse the currently edited string according to a grammar and upon the occurence of the injected TAB token I inspect the current state of the parser.
This way I get all the terminals and rules that apply at the specific point where the user pressed TAB. This information can then be used collect the potential completions, making it pretty easy to implement tab completion for LALR(1) grammars.
Right now, "state" is not published anywhere, it is a local variable within the parse() function, which I look up using sys._getframe(). This is of course fragile and was recently broken due as the part that called the error handler function was extracted into a separate function in ply 3.6.
I see that statestack is published in the parser and its last element should be equal to the current state, however I am not entirely sure.
If I got some help I would be willing to contribute a patch.
Thanks.
The text was updated successfully, but these errors were encountered: