pyebnf/util.py
def esc_split(text, delimiter=" ", maxsplit=-1, escape="\\", *, ignore_empty=False):
  """Escape-aware text splitting:

  Split text on on a delimiter, recognizing escaped delimiters."""
  is_escaped = False
  split_count = 0
  yval = []

  for char in text:
    if is_escaped:
      is_escaped = False
      yval.append(char)
    else:
      if char == escape:
        is_escaped = True
      elif char in delimiter and split_count != maxsplit:
        if yval or not ignore_empty:
          yield "".join(yval)
          split_count += 1
        yval = []
      else:
        yval.append(char)

  yield "".join(yval)
def esc_split(text, delimiter=" ", maxsplit=-1, escape="\\", *, ignore_empty=False):
  """Escape-aware text splitting:

  Split text on on a delimiter, recognizing escaped delimiters."""
  is_escaped = False
  split_count = 0
  yval = []

  for char in text:
    if is_escaped:
      is_escaped = False
      yval.append(char)
    else:
      if char == escape:
        is_escaped = True
      elif char in delimiter and split_count != maxsplit:
        if yval or not ignore_empty:
          yield "".join(yval)
          split_count += 1
        yval = []
      else:
        yval.append(char)

  yield "".join(yval)
Escape-aware text splitting:

  Split text on on a delimiter, recognizing escaped delimiters.