Exemple #1
0
        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
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
 def lex_open_footnote_inner(token):
     token.value = Token.Builder(token.value)
     token.lexer.begin("footnotelabel")
     return token
Exemple #5
0
 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
Exemple #6
0
 def until_next_flag_inner(token):
     text = token.value
     token.value = Token.Builder(drop_first_word(text))
     return token
Exemple #7
0
 def rest_of_line_inner(token):
     line = token.value[:-1]  # ignore newline
     token.value = Token.Builder(drop_first_word(line))
     return token
Exemple #8
0
 def one_arg_inner(token):
     token.value = Token.Builder(token.value.split()[1])
     return token
Exemple #9
0
 def regex_inner(token):
     token.value = Token.Builder(token.value)
     # raise AssertionError()
     return token