Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def listMembers(t_sep, expr):
return sparse.delimited_list(expr, sparse.Q(t_sep))
def braced_expression(t_l, inner, t_r, allow_missing_close=False):
opener = sparse.Q(t_l)
closer = sparse.Q(t_r) if not allow_missing_close else sparse.Optional(sparse.Q(t_r))
return opener - inner + closer
def make_grammar(allow_errors):
"""Make the part of the grammar that depends on whether we swallow errors or not."""
T = sparse.T
Q = sparse.Q
p = sparse
Rule = sparse.Rule
if allow_errors in GRAMMAR_CACHE:
return GRAMMAR_CACHE[allow_errors]
consume_parse_failures = Rule('consume_parse_failures') >> sparse.OneOrMore(sparse.AnythingExcept(';', '}')) >> UnparseableNode
def recoverable(inner):
if not allow_errors:
return inner
return sparse.RecoverFailure(inner, consume_parse_failures)
class Grammar:
expression = p.Forward()
def braced_expression(t_l, inner, t_r, allow_missing_close=False):
opener = sparse.Q(t_l)
closer = sparse.Q(t_r) if not allow_missing_close else sparse.Optional(sparse.Q(t_r))
return opener - inner + closer