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
I use a transformer to get callblacks whenever a rule finishes. I use an interactive parser. When I check for the next tokens that can be parsed, the callbacks are triggered several times:
from lark import Lark, Token, Transformer
grammar ="""
sentence: noun verb noun
| noun verb "like" noun
noun: adj? NOUN
verb: VERB
adj: ADJ
NOUN: "flies" | "bananas" | "fruit"
VERB: "like" | "flies"
ADJ: "yummy"
"""
class MyTransformer(Transformer):
def adj(self, children):
print("Callback for adj:", children)
return children
def noun(self, children):
print("Callback for noun:", children)
return children
def verb(self, children):
print("Callback for verb:", children)
return children
parser = Lark(grammar, parser='lalr', start='sentence', transformer=MyTransformer())
interactive = parser.parse_interactive()
#parser.parse('yummy')
#interactive.accepts()
interactive.feed_token(Token('ADJ', 'yummy'))
interactive.feed_token(Token('NOUN', 'fruit'))
print("----FROM HERE ON NO CALLBACKS SHOULD HAPPEN----")
interactive.accepts()
Is this a bug?
The text was updated successfully, but these errors were encountered:
which seems to be the newest version. If I run
$ pip install --upgrade lark-parser
I get:
Requirement already satisfied: lark-parser in c:\users\daniel\anaconda3\envs\musicml\lib\site-packages (0.12.0)
Code output is:
Callback for adj: [Token('ADJ', 'yummy')]
----FROM HERE ON NO CALLBACKS SHOULD HAPPEN----
Callback for noun: [[Token('ADJ', 'yummy')], Token('NOUN', 'fruit')]
Callback for noun: [[Token('ADJ', 'yummy')], Token('NOUN', 'fruit')]
{'VERB'}
I use a transformer to get callblacks whenever a rule finishes. I use an interactive parser. When I check for the next tokens that can be parsed, the callbacks are triggered several times:
Is this a bug?
The text was updated successfully, but these errors were encountered: