def footnote_label(token): marker = token.value if marker == "+": token.value = Token.Builder(AutomaticFootnoteLabel()) elif marker == "-": token.value = Token.Builder(NoFootnoteLabel()) else: token.value = Token.Builder(CustomFootnoteLabel(marker)) token.lexer.begin("INITIAL") return token
def scale_inner(token): text = token.value match = re.search(r"[0-9]*$", text) if match is None: raise ValueError("Malformatted input: {}".format(token.value)) number_str = match.group() number = 1 if len(number_str) == 0 else int(number_str) token.value = Token.Builder(text).set_number(number) return token
def scale_and_rest_of_line_inner(token): line = token.value[:-1] rgx = r"{flag}([0-9]+)".format(flag=make_flag(flag, boundary=False)) number_match = re.match(rgx, line) if number_match is None: number = 1 else: number = int(number_match.group(1)) rest = drop_first_word(line) token.value = Token.Builder(rest).set_number(number) return token
def lex_open_footnote_inner(token): token.value = Token.Builder(token.value) token.lexer.begin("footnotelabel") return token
def t_text(self, token): text = token.value if len(text.strip()) == 0: return # ignore text that is purely whitespace token.value = Token.Builder(text) return token
def until_next_flag_inner(token): text = token.value token.value = Token.Builder(drop_first_word(text)) return token
def rest_of_line_inner(token): line = token.value[:-1] # ignore newline token.value = Token.Builder(drop_first_word(line)) return token
def one_arg_inner(token): token.value = Token.Builder(token.value.split()[1]) return token
def regex_inner(token): token.value = Token.Builder(token.value) # raise AssertionError() return token