Fix scanning of multiline operators with '<' or '/'
This commit is contained in:
parent
58b45e6cac
commit
4098c0e25a
@ -175,7 +175,6 @@ class Lexer:
|
|||||||
|
|
||||||
return Token.HEREDOC, pos, out.getvalue()
|
return Token.HEREDOC, pos, out.getvalue()
|
||||||
|
|
||||||
# TODO: scan multi-char operators like ==
|
|
||||||
def _scan_operator(self, char) -> tuple[Token, ast.Position, str]:
|
def _scan_operator(self, char) -> tuple[Token, ast.Position, str]:
|
||||||
pos = dataclasses.replace(self.pos)
|
pos = dataclasses.replace(self.pos)
|
||||||
with io.StringIO() as out:
|
with io.StringIO() as out:
|
||||||
@ -183,7 +182,6 @@ class Lexer:
|
|||||||
out.write(char)
|
out.write(char)
|
||||||
char = self._read()
|
char = self._read()
|
||||||
self._unread(char)
|
self._unread(char)
|
||||||
val = out.getvalue()
|
|
||||||
return Token.OPERATOR, pos, out.getvalue()
|
return Token.OPERATOR, pos, out.getvalue()
|
||||||
|
|
||||||
def scan(self) -> tuple[Token, ast.Position, str]:
|
def scan(self) -> tuple[Token, ast.Position, str]:
|
||||||
@ -208,7 +206,7 @@ class Lexer:
|
|||||||
# If the next character is not another less than symbol,
|
# If the next character is not another less than symbol,
|
||||||
# this is probably a less than operator.
|
# this is probably a less than operator.
|
||||||
if self._peek(1) != '<':
|
if self._peek(1) != '<':
|
||||||
return Token.OPERATOR, self.pos, char
|
return self._scan_operator(char)
|
||||||
return self._scan_heredoc(char)
|
return self._scan_heredoc(char)
|
||||||
case '/':
|
case '/':
|
||||||
next = self._peek(1)
|
next = self._peek(1)
|
||||||
@ -224,7 +222,7 @@ class Lexer:
|
|||||||
# If the next character is not another slash
|
# If the next character is not another slash
|
||||||
# or an asterisk, this is probably a division
|
# or an asterisk, this is probably a division
|
||||||
# operator.
|
# operator.
|
||||||
return Token.OPERATOR, self.pos, char
|
return self._scan_operator(char)
|
||||||
case '#':
|
case '#':
|
||||||
# Ignore comments and return next token
|
# Ignore comments and return next token
|
||||||
self._scan_comment(char)
|
self._scan_comment(char)
|
||||||
|
Loading…
Reference in New Issue
Block a user