def parse_nativequote(p, n): string = p[n][3:-3] # drop the quotation marks fields = string.split('`') bqs = [Atom(s) for idx, s in enumerate(fields) if idx % 2 == 1] text = "`".join([(s if idx % 2 == 0 else str(idx / 2)) for idx, s in enumerate(fields)]) eols = [ sum(1 for c in s if c == '\n') for idx, s in enumerate(fields) if idx % 2 == 0 ] seols = 0 loc = get_lineno(p, n) for idx, e in enumerate(eols[:-1]): seols += e bqs[idx].lineno = iu.Location(loc.filename, loc.line + seols) if len(fields) % 2 != 1: thing = Atom("") thing.lineno = loc report_error(IvyError(thing, "unterminated back-quote")) return NativeCode(text), bqs
def __init__(self, token): self.lineno = iu.Location(iu.filename, token.lineno)
def get_lineno(p, n): return iu.Location(iu.filename, p.lineno(n))