def parse_escape_sequence(source, buffer): if source.match(u"\\"): buffer.append(u"\\") return None elif source.match(u"&"): buffer.append(u"&") return None elif source.match(u"$"): return PositionalArg(0) n = parse_number(source) return PositionalArg(n)
def parse_insert_string(str): source = regexp.Source(str) buffer = rstring.UnicodeBuilder() result = [] while not source.at_end(): if source.match(u"\\"): escaped = parse_escape_sequence(source, buffer) if escaped is not None: if buffer.getlength(): result.append(StringLiteral(buffer.build())) buffer = rstring.UnicodeBuilder() result.append(escaped) else: ch = source.get() buffer.append(ch) if buffer.getlength(): result.append(StringLiteral(buffer.build())) return result