Skip to content

Commit

Permalink
[doctools/ul_table] Finish migrating away from TagLexer.
Browse files Browse the repository at this point in the history
It works!  The code looks nice.
  • Loading branch information
Andy C committed Jan 18, 2025
1 parent 1c57d02 commit 33c3e8c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions doctools/ul_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def RemoveComments(s):

class UlTableParser(object):

def __init__(self, lexer, tag_lexer):
# type: (htm8.Lexer, htm8.TagLexer) -> None
def __init__(self, lexer):
# type: (htm8.Lexer) -> None
self.lexer = lexer
self.tag_lexer = tag_lexer
self.attr_lexer = htm8.AttrLexer(lexer.s)

self.tok_id = h8_id.Invalid
self.start_pos = 0
Expand Down Expand Up @@ -210,11 +210,12 @@ def _ListItem(self):
balance = 0
while True:
if self.tok_id == h8_id.StartEndTag:
self.tag_lexer.Reset(self.start_pos, self.end_pos)
self.attr_lexer.Init(self.tok_id, self.lexer.TagNamePos(),
self.end_pos)
# TODO: remove td-attrs backward compat
if self.tag_name in ('td-attrs', 'cell-attrs'):
td_attrs_span = self.start_pos, self.end_pos
td_attrs = self.tag_lexer.AllAttrsRaw()
td_attrs = htm8.AllAttrsRaw(self.attr_lexer)
#log('CELL ATTRS %r', self._CurrentString())

elif self.tok_id == h8_id.StartTag:
Expand Down Expand Up @@ -347,11 +348,12 @@ def _ParseTr(self):

tr_attrs = None
if self.tok_id == h8_id.StartEndTag:
self.tag_lexer.Reset(self.start_pos, self.end_pos)
self.attr_lexer.Init(self.tok_id, self.lexer.TagNamePos(),
self.end_pos)
if self.tag_name != 'row-attrs':
raise htm8.ParseError('Expected row-attrs, got %r' %
self.tag_name)
tr_attrs = self.tag_lexer.AllAttrsRaw()
tr_attrs = htm8.AllAttrsRaw(self.attr_lexer)
self._Next()
self._WhitespaceOk()

Expand Down Expand Up @@ -480,10 +482,9 @@ def ReplaceTables(s, debug_out=None):
f = StringIO()
out = htm8.Output(s, f)

tag_lexer = htm8.TagLexer(s)
lexer = htm8.Lexer(s)

p = UlTableParser(lexer, tag_lexer)
p = UlTableParser(lexer)

while True:
ul_start = p.FindUlTable()
Expand Down

0 comments on commit 33c3e8c

Please sign in to comment.