예제 #1
0
def parse_rule(text, start_pos, start_vals):
  while True:
    pos, vals = start_pos, start_vals
    pos, vals = parse_id(text, pos, vals)
    if pos is None: break
    m = re.match('=', text[pos:])
    if not m: break
    pos, vals = pos + m.end(), vals + m.groups()
    pos, vals = parse__(text, pos, vals)
    if pos is None: break
    vals += ('def parse_',)
    vals = metalib.swap(vals)
    vals += ('(text, start_pos, start_vals):',)
    vals = metalib.nl(vals)
    pos, vals = parse_alts(text, pos, vals)
    if pos is None: break
    m = re.match('\\.', text[pos:])
    if not m: break
    pos, vals = pos + m.end(), vals + m.groups()
    pos, vals = parse__(text, pos, vals)
    if pos is None: break
    vals += ('  return None, None',)
    vals = metalib.nl(vals)
    return pos, vals
  return None, None
예제 #2
0
def parse_token(text, start_pos, start_vals):
  while True:
    pos, vals = start_pos, start_vals
    m = re.match('{', text[pos:])
    if not m: break
    pos, vals = pos + m.end(), vals + m.groups()
    pos, vals = parse_qchars(text, pos, vals)
    if pos is None: break
    m = re.match('}', text[pos:])
    if not m: break
    pos, vals = pos + m.end(), vals + m.groups()
    pos, vals = parse__(text, pos, vals)
    if pos is None: break
    vals += ('    vals += (',)
    vals = metalib.swap(vals)
    vals = metalib.quote(vals)
    vals += (',)',)
    vals = metalib.nl(vals)
    return pos, vals
  while True:
    pos, vals = start_pos, start_vals
    m = re.match('\\/', text[pos:])
    if not m: break
    pos, vals = pos + m.end(), vals + m.groups()
    pos, vals = parse_xchars(text, pos, vals)
    if pos is None: break
    m = re.match('\\/', text[pos:])
    if not m: break
    pos, vals = pos + m.end(), vals + m.groups()
    pos, vals = parse__(text, pos, vals)
    if pos is None: break
    vals += ('    m = re.match(',)
    vals = metalib.swap(vals)
    vals = metalib.quote(vals)
    vals += (', text[pos:])',)
    vals = metalib.nl(vals)
    vals += ('    if not m: break',)
    vals = metalib.nl(vals)
    vals += ('    pos, vals = pos + m.end(), vals + m.groups()',)
    vals = metalib.nl(vals)
    return pos, vals
  while True:
    pos, vals = start_pos, start_vals
    pos, vals = parse_id(text, pos, vals)
    if pos is None: break
    vals += ('    pos, vals = parse_',)
    vals = metalib.swap(vals)
    vals += ('(text, pos, vals)',)
    vals = metalib.nl(vals)
    vals += ('    if pos is None: break',)
    vals = metalib.nl(vals)
    return pos, vals
  while True:
    pos, vals = start_pos, start_vals
    m = re.match(':', text[pos:])
    if not m: break
    pos, vals = pos + m.end(), vals + m.groups()
    pos, vals = parse_id(text, pos, vals)
    if pos is None: break
    vals += ('    vals = metalib.',)
    vals = metalib.swap(vals)
    vals += ('(vals)',)
    vals = metalib.nl(vals)
    return pos, vals
  return None, None