def string_literal(): whitespace() quote = one_of('\'"') commit() st = u''.join(many1(p(string_char, quote))) one_of(quote) return ('str', st)
def end_element(name): whitespace() string("</") commit() if name != xml_name(): fail() whitespace() close_angle()
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)
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))
def bin_op(): left = term() op = operator() commit() right = expression() whitespace() n = BinaryNode(left, op) return n.merge(right)
def processing(parser=False): parser = parser or compose(build_string, partial(many, partial(not_one_of, "?"))) string("<?") commit() result = parser() whitespace() string("?>") return result
def parenthetical(): whitespace() one_of('(') commit() whitespace() v = expression() whitespace() one_of(')') whitespace() return ParentheticalNode(v)
def processing(parser = False): parser = parser or compose(build_string, partial(many, partial(not_one_of, '?'))) string('<?') commit() result = parser() whitespace() string('?>') return result
def _ParseParenthetical(self): """Consumes parenthetical expression.""" whitespace() one_of('(') commit() whitespace() node = self._expr_parser() whitespace() one_of(')') whitespace() return Parenthetical(self._schema, node)
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)
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
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
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
def doctype(): string("<!DOCTYPE") commit() many_until(any_token, close_angle)
def float_value(): whole_part = digits() one_of('.') commit() decimal_part = digits() return float('%s.%s' % (whole_part, decimal_part))
def comment(): string("<!--") commit() result, _ = many_until(any_token, tri(partial(string, "-->"))) return "COMMENT", build_string(result)
def doctype(): string('<!DOCTYPE') commit() many_until(any_token, close_angle)
def ident(): pico.hash() commit() return many1(any_token)
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))
def attribute(): name = xml_name() commit() lexeme(equals) return "ATTR", name, quoted()
def ident(): whitespace1() pico.hash() commit() return many1(any_token)
def ident(): whitespace1() one_of('#') commit() result['ident'] = "".join(many1(partial(not_one_of, ',')))