def parseText(text): outText = [] argProps = [] argLineNos = set() prv = (0, 0, None) cur = utilities.findToken(text, StartDefinition, EndDefinition) lineNo = 1 skippedNewlines = 0 while cur[0] != cur[1]: lineNo += appendText(outText, text[prv[1]:cur[0]]) if StartDefinition in cur[2]: raise Error("Definition seems to be missing a closing \"%s\"" % EndDefinition, lineNo) try: txt, props = parseDefinition(cur[2]) props["lineno"] = str(lineNo) except Error as ex: ex.lineNo = str(lineNo) raise ex if txt and isStartOfLine(outText): argLineNos.add(lineNo - skippedNewlines - 1) if ((not txt) and (not outText or outText[-1][-1] == "\n") and (cur[1] != len(text) and text[cur[1]] == "\n")): lineNo += 1 skippedNewlines += 1 cur = cur[0], cur[1] + 1, cur[2] appendText(outText, txt) lineNo += cur[2].count("\n") argProps.append(props) prv = cur cur = utilities.findToken(text, StartDefinition, EndDefinition, cur[1]) appendText(outText, text[prv[1]:]) return "".join(outText), argProps, argLineNos
def expandReferences(s, operator): text = [] references = set() prevEnd = 0 start, end, name = utilities.findToken(s, "$", "$") while start != end: text.append(s[prevEnd:start]) text.append("result" + operator) text.append(name) references.add(name) prevEnd = end start, end, name = utilities.findToken(s, "$", "$", end) text.append(s[prevEnd:]) return "".join(text), references