How to use the sparse.Q function in sparse

To help you get started, we’ve selected a few sparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rix0rrr / gcl / gcl / ast2.py View on Github external
def listMembers(t_sep, expr):
  return sparse.delimited_list(expr, sparse.Q(t_sep))
github rix0rrr / gcl / gcl / ast2.py View on Github external
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
github rix0rrr / gcl / gcl / ast2.py View on Github external
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()
github rix0rrr / gcl / gcl / ast2.py View on Github external
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