Esempio n. 1
0
def string_literal():
  whitespace()
  quote = one_of('\'"')
  commit()
  st = u''.join(many1(p(string_char, quote)))
  one_of(quote)
  return ('str', st)
Esempio n. 2
0
def end_element(name):
    whitespace()
    string("</")
    commit()
    if name != xml_name():
        fail()
    whitespace()
    close_angle()
Esempio n. 3
0
def identifier():
  whitespace()
  not_followed_by(p(choice, *[p(reserved, rw) for rw in reserved_words]))
  first = identifier_char1()
  commit()
  rest = many(identifier_char)
  name = u''.join([first] + rest)
  return ('ident', name)
Esempio n. 4
0
def end_element(name):
    whitespace()
    string("</")
    commit()
    if name != xml_name():
        fail()
    whitespace()
    close_angle()
Esempio n. 5
0
def number():
  whitespace()
  lead = u''.join(many1(digit))
  commit()
  if optional(p(one_of, '.')):
    trail = u''.join(many1(digit))
    return ('float', float(lead + '.' + trail))
  else:
    return ('int', int(lead))
Esempio n. 6
0
def bin_op():
    left = term()
    op = operator()
    commit()
    right = expression()
    whitespace()

    n = BinaryNode(left, op)
    return n.merge(right)
Esempio n. 7
0
def bin_op():
    left = term()
    op = operator()
    commit()
    right = expression()
    whitespace()
    
    n = BinaryNode(left, op)
    return n.merge(right) 
Esempio n. 8
0
def processing(parser=False):
    parser = parser or compose(build_string, partial(many, partial(not_one_of, "?")))

    string("<?")
    commit()
    result = parser()
    whitespace()

    string("?>")
    return result
Esempio n. 9
0
def parenthetical():
    whitespace()
    one_of('(')
    commit()
    whitespace()
    v = expression()
    whitespace()
    one_of(')')
    whitespace()
    return ParentheticalNode(v)
Esempio n. 10
0
def parenthetical():
    whitespace()
    one_of('(')
    commit()
    whitespace()
    v = expression()
    whitespace()
    one_of(')')
    whitespace()
    return ParentheticalNode(v)
Esempio n. 11
0
def processing(parser = False):
    parser = parser or compose(build_string, partial(many, partial(not_one_of, '?')))

    string('<?')
    commit()
    result = parser()
    whitespace()
    
    string('?>')
    return result
Esempio n. 12
0
 def _ParseParenthetical(self):
   """Consumes parenthetical expression."""
   whitespace()
   one_of('(')
   commit()
   whitespace()
   node = self._expr_parser()
   whitespace()
   one_of(')')
   whitespace()
   return Parenthetical(self._schema, node)
Esempio n. 13
0
 def _ParseOp(self):
   """Consumes one operation, defined by left term and right
   expression, which may be either another term or another ParseOp().
   """
   left = self._term_parser()
   op = self._operator()
   commit()
   right = self._expr_parser()
   whitespace()
   node = self._op_classes[op](self._schema, left)
   return node.Merge(right)
Esempio n. 14
0
 def _ParsePhrase(self):
   """Consumes a key range specification of the form <table>.<column>=<maybe
   quoted value>.
   """
   whitespace()
   table = self._token().lower()
   one_of('.')
   commit()
   column = self._token().lower()
   whitespace()
   one_of('=')
   whitespace()
   phrase = self._param_parser()
   node = PhraseNode(self._schema, table, column, phrase)
   whitespace()
   return node
Esempio n. 15
0
 def _ParsePhrase(self):
   """Reads one attribute col_name=value. Creates a DB update
   in self._updates.
   """
   col_name = self._token().lower()
   col_def = self._table.GetColumn(col_name)
   one_of('=')
   commit()
   phrase = self._phrase()
   if phrase:
     value = eval(phrase)
     if col_def.value_type == 'N':
       value = int(value)
     if self._raw:
       self._updates[col_def.key] = db_client.UpdateAttr(value, 'PUT')
     else:
       self._updates[col_name] = value
   else:
     if self._raw:
       self._updates[col_def.key] = db_client.UpdateAttr(None, 'DELETE')
     else:
       self._updates[col_name] = None
   return None
Esempio n. 16
0
 def _ParsePhrase(self):
     """Reads one attribute col_name=value. Creates a DB update
 in self._updates.
 """
     col_name = self._token().lower()
     col_def = self._table.GetColumn(col_name)
     one_of('=')
     commit()
     phrase = self._phrase()
     if phrase:
         value = eval(phrase)
         if col_def.value_type == 'N':
             value = int(value)
         if self._raw:
             self._updates[col_def.key] = db_client.UpdateAttr(value, 'PUT')
         else:
             self._updates[col_name] = value
     else:
         if self._raw:
             self._updates[col_def.key] = db_client.UpdateAttr(
                 None, 'DELETE')
         else:
             self._updates[col_name] = None
     return None
Esempio n. 17
0
def doctype():
    string("<!DOCTYPE")
    commit()
    many_until(any_token, close_angle)
Esempio n. 18
0
def float_value():
    whole_part = digits()
    one_of('.')
    commit()
    decimal_part = digits()
    return float('%s.%s' % (whole_part, decimal_part))
Esempio n. 19
0
def comment():
    string("<!--")
    commit()
    result, _ = many_until(any_token, tri(partial(string, "-->")))
    return "COMMENT", build_string(result)
Esempio n. 20
0
def doctype():
    string('<!DOCTYPE')
    commit()
    many_until(any_token, close_angle)
Esempio n. 21
0
 def ident():
     pico.hash()
     commit()
     return many1(any_token)
Esempio n. 22
0
def element():
    open_angle()
    name = xml_name()
    commit()
    attributes = lexeme(partial(sep, attribute, whitespace1))
    return "NODE", name, attributes, choice(closed_element, partial(open_element, name))
Esempio n. 23
0
def attribute():
    name = xml_name()
    commit()
    lexeme(equals)
    return "ATTR", name, quoted()
Esempio n. 24
0
def float_value():
    whole_part = digits()
    one_of('.')
    commit()
    decimal_part = digits()
    return float('%s.%s' % (whole_part, decimal_part))
Esempio n. 25
0
def attribute():
    name = xml_name()
    commit()
    lexeme(equals)
    return "ATTR", name, quoted()
Esempio n. 26
0
def comment():
    string("<!--")
    commit()
    result, _ = many_until(any_token, tri(partial(string, "-->")))
    return "COMMENT", build_string(result)
Esempio n. 27
0
 def ident():
     whitespace1()
     pico.hash()
     commit()
     return many1(any_token)
Esempio n. 28
0
def element():
    open_angle()
    name = xml_name()
    commit()
    attributes = lexeme(partial(sep, attribute, whitespace1))
    return "NODE", name, attributes, choice(closed_element, partial(open_element, name))
Esempio n. 29
0
 def ident():
     whitespace1()
     one_of('#')
     commit()
     result['ident'] = "".join(many1(partial(not_one_of, ',')))