text
stringlengths
0
828
result = self.text[start:end]
self.index = end
if result.endswith('\n'):
self.colno = 0
self.lineno += 1
else:
self.colno += end - start
return result"
894,"def match(self, regex, flags=0):
""""""
Matches the specified *regex* from the current character of the *scanner*
and returns the result. The Scanners column and line numbers are updated
respectively.
# Arguments
regex (str, Pattern): The regex to match.
flags (int): The flags to use when compiling the pattern.
""""""
if isinstance(regex, str):
regex = re.compile(regex, flags)
match = regex.match(self.text, self.index)
if not match:
return None
start, end = match.start(), match.end()
lines = self.text.count('\n', start, end)
self.index = end
if lines:
self.colno = end - self.text.rfind('\n', start, end) - 1
self.lineno += lines
else:
self.colno += end - start
return match"
895,"def getmatch(self, regex, group=0, flags=0):
""""""
The same as #Scanner.match(), but returns the captured group rather than
the regex match object, or None if the pattern didn't match.
""""""
match = self.match(regex, flags)
if match:
return match.group(group)
return None"
896,"def restore(self, cursor):
"" Moves the scanner back (or forward) to the specified cursor location. ""
if not isinstance(cursor, Cursor):
raise TypeError('expected Cursor object', type(cursor))
self.index, self.lineno, self.colno = cursor"
897,"def update(self):
""""""
Updates the #rules_map dictionary and #skippable_rules list based on the
#rules list. Must be called after #rules or any of its items have been
modified. The same rule name may appear multiple times.
# Raises
TypeError: if an item in the `rules` list is not a rule.
""""""
self.rules_map = {}
self.skippable_rules = []
for rule in self.rules:
if not isinstance(rule, Rule):
raise TypeError('item must be Rule instance', type(rule))
self.rules_map.setdefault(rule.name, []).append(rule)
if rule.skip:
self.skippable_rules.append(rule)"
898,"def expect(self, *names):
""""""
Checks if the current #token#s type name matches with any of the specified
*names*. This is useful for asserting multiple valid token types at a
specific point in the parsing process.
# Arguments
names (str): One or more token type names. If zero are passed,
nothing happens.
# Raises
UnexpectedTokenError: If the current #token#s type name does not match
with any of the specified *names*.
""""""
if not names:
return
if not self.token or self.token.type not in names:
raise UnexpectedTokenError(names, self.token)"
899,"def accept(self, *names, **kwargs):
""""""
Extracts a token of one of the specified rule names and doesn't error if
unsuccessful. Skippable tokens might still be skipped by this method.
# Arguments
names (str): One or more token names that are accepted.
kwargs: Additional keyword arguments for #next().
# Raises
ValueError: if a rule with the specified name doesn't exist.
""""""
return self.next(*names, as_accept=True, **kwargs)"