aboutsummaryrefslogtreecommitdiff
path: root/mammoth/styles/parser/token_iterator.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-02-17 13:52:16 +0000
committerMichael Williamson <mike@zwobble.org>2024-02-17 13:52:16 +0000
commitfe41ddbc51b4b7c6ce7d958ea7622983d7805b7e (patch)
tree6a477e4a54657b5b89b87141ed85f088c2f03015 /mammoth/styles/parser/token_iterator.py
parentd037ef5cf7fc976047bed20859dbcd5c90f45d67 (diff)
Support attributes in HTML paths in style mappings
Diffstat (limited to 'mammoth/styles/parser/token_iterator.py')
-rw-r--r--mammoth/styles/parser/token_iterator.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/mammoth/styles/parser/token_iterator.py b/mammoth/styles/parser/token_iterator.py
index fded56d..931b419 100644
--- a/mammoth/styles/parser/token_iterator.py
+++ b/mammoth/styles/parser/token_iterator.py
@@ -8,13 +8,13 @@ class TokenIterator(object):
def __init__(self, tokens):
self._tokens = tokens
self._index = 0
-
+
def peek_token_type(self):
return self._tokens[self._index].type
-
+
def next_value(self, token_type=None):
return self._next(token_type).value
-
+
def _next(self, token_type=None):
token = self._tokens[self._index]
if token_type is None or token.type == token_type:
@@ -22,7 +22,7 @@ class TokenIterator(object):
return token
else:
raise self._unexpected_token_type(token_type, token)
-
+
def skip(self, token_type, token_value=None):
token = self._tokens[self._index]
if token.type == token_type and (token_value is None or token.value == token_value):
@@ -30,15 +30,14 @@ class TokenIterator(object):
return True
else:
raise self._unexpected_token_type(token_type, token)
-
+
def try_skip(self, token_type, token_value=None):
- token = self._tokens[self._index]
- if token.type == token_type and (token_value is None or token.value == token_value):
+ if self.is_next(token_type, token_value):
self._index += 1
return True
else:
return False
-
+
def try_skip_many(self, tokens):
start = self._index
for token_type, token_value in tokens:
@@ -48,9 +47,13 @@ class TokenIterator(object):
return False
else:
self._index += 1
-
+
return True
-
+
+ def is_next(self, token_type, token_value=None):
+ token = self._tokens[self._index]
+ return token.type == token_type and (token_value is None or token.value == token_value)
+
def _unexpected_token_type(self, token_type, token):
raise LineParseError()
-
+