pyebnf/primitive.py
def _get_repetition(extractor, text, *, bounds=(0, None), ignore_whitespace=False):
  """Tries to pull text with extractor repeatedly.

  Bounds is a 2-tuple of (lbound, ubound) where lbound is a number and ubound is a number or None.
  If the ubound is None, this method will execute extractor on text until extrator raises DeadEnd.
  Otherwise, extractor will be called until it raises DeadEnd, or it has extracted ubound times.

  If the number of children extracted is >= lbound, then a ParseNode with type repetition is
  returned. Otherwise, DeadEnd is raised.

  Bounds are interpreted as (lbound, ubound]

  This method is used to implement:
  - option (0, 1)
  - zero_or_more (0, None)
  - one_or_more (1, None)
  - exact_repeat (n, n)
  """
  minr, maxr = bounds
  children = []

  while maxr is None or len(children) <= maxr:
    ignored_ws, use_text = _split_ignored(text, ignore_whitespace)
    try:
      child = _call_extractor(extractor, use_text)
      child.add_ignored(ignored_ws)
    except DeadEnd:
      break

    if child.is_empty:
      break

    children.append(child)
    text = text[child.consumed:]


  if len(children) >= minr:
    return ParseNode(ParseNodeType.repetition,
                      children=children)
  else:
    raise DeadEnd()
def _get_repetition(extractor, text, *, bounds=(0, None), ignore_whitespace=False):
  minr, maxr = bounds
  children = []

  while maxr is None or len(children) <= maxr:
    ignored_ws, use_text = _split_ignored(text, ignore_whitespace)
    try:
      child = _call_extractor(extractor, use_text)
      child.add_ignored(ignored_ws)
    except DeadEnd:
      break

    if child.is_empty:
      break

    children.append(child)
    text = text[child.consumed:]


  if len(children) >= minr:
    return ParseNode(ParseNodeType.repetition,
                      children=children)
  else:
    raise DeadEnd()
def _get_repetition ( extractor , text , * , bounds = ( 0 , None ) , ignore_whitespace = False ) : minr , maxr = bounds children = [ ] while maxr is None or len ( children ) <= maxr : ignored_ws , use_text = _split_ignored ( text , ignore_whitespace ) try : child = _call_extractor ( extractor , use_text ) child . add_ignored ( ignored_ws ) except DeadEnd : break if child . is_empty : break children . append ( child ) text = text [ child . consumed : ] if len ( children ) >= minr : return ParseNode ( ParseNodeType . repetition , children = children ) else : raise DeadEnd ( )
Tries to pull text with extractor repeatedly.

  Bounds is a 2-tuple of (lbound, ubound) where lbound is a number and ubound is a number or None.
  If the ubound is None, this method will execute extractor on text until extrator raises DeadEnd.
  Otherwise, extractor will be called until it raises DeadEnd, or it has extracted ubound times.

  If the number of children extracted is >= lbound, then a ParseNode with type repetition is
  returned. Otherwise, DeadEnd is raised.

  Bounds are interpreted as (lbound, ubound]

  This method is used to implement:
  - option (0, 1)
  - zero_or_more (0, None)
  - one_or_more (1, None)
  - exact_repeat (n, n)
Tries to pull text with extractor repeatedly .