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've been having a bit of trouble getting the current string-value of a lex token. Here is what I'm currently doing:
from ExprGenerator import ExprGenerator
from grammarinator.runtime import *
import random
class MyExprGenerator(ExprGenerator):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def Int(self, parent=None):
with RuleContext(self, UnlexerRule(name='Int', parent=parent)) as current:
UnlexerRule(src=str(random.random()), parent=current)
# such a hackish way to get the current value?
_current_val = "{}".format(current)
if float(_current_val) < 0.5: return self.Int(parent=parent)
return current
Is there a better way to get current ? I tried a few things, but I was basically getting a parent/child node or None, for example:
What's the suggested way to get the current value? What I'm trying to do is validation, for example, make sure a number is > 0.5, which is pretty difficult to do directly from the antlr grammar, so I'm doing some additional validation in the listeners/generators. Thanks so much for your time and help!
David
The text was updated successfully, but these errors were encountered:
@renatahodovan thanks so much that works. By the way, I sent you an email to your contact on Github about a few questions if that's ok -- thanks again for your help!
I've been having a bit of trouble getting the current string-value of a lex token. Here is what I'm currently doing:
Is there a better way to get
current
? I tried a few things, but I was basically getting a parent/child node orNone
, for example:What's the suggested way to get the
current
value? What I'm trying to do is validation, for example, make sure a number is > 0.5, which is pretty difficult to do directly from the antlr grammar, so I'm doing some additional validation in the listeners/generators. Thanks so much for your time and help!David
The text was updated successfully, but these errors were encountered: