Skip to content

Commit 318eaca

Browse files
pekkaklarckyanne
authored andcommitted
Lexer: Avoid unnecessary EOS after comments
1 parent d21cb7a commit 318eaca

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/robot/parsing/lexer/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .context import TestCaseFileContext
1919
from .lexers import TestCaseFileLexer
2020
from .splitter import Splitter
21-
from .tokens import Token
21+
from .tokens import EOS, Token
2222

2323

2424
class RobotFrameworkLexer(object):
@@ -46,21 +46,19 @@ def get_tokens(self):
4646
else:
4747
ignore = {Token.IGNORE}
4848
for statement in self._handle_old_for(self.statements):
49-
name_eos = None
49+
name_token = last_token = None
5050
for token in statement:
5151
if token.type in ignore:
5252
continue
53-
if name_eos:
54-
yield name_eos
55-
name_eos = None
53+
if name_token:
54+
yield EOS.from_token(name_token)
55+
name_token = None
5656
if token.type == Token.NAME:
57-
name_eos = Token(Token.EOS,
58-
lineno=token.lineno,
59-
columnno=token.columnno + len(token.value))
57+
name_token = token
58+
last_token = token
6059
yield token
61-
yield Token(Token.EOS,
62-
lineno=token.lineno,
63-
columnno=token.columnno + len(token.value))
60+
if last_token:
61+
yield EOS.from_token(last_token)
6462

6563
def _handle_old_for(self, statements):
6664
end_statement = [Token(Token.END)]

src/robot/parsing/lexer/tokens.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ def __repr__(self):
8282

8383
Token.DATA_TOKENS = [t for t in Token.__dict__
8484
if t[0] != '_' and t not in Token.NON_DATA_TOKENS]
85+
86+
87+
class EOS(Token):
88+
89+
def __init__(self, lineno=-1, columnno=-1):
90+
Token.__init__(self, Token.EOS, '', lineno, columnno)
91+
92+
@classmethod
93+
def from_token(cls, token):
94+
return EOS(token.lineno, token.columnno + len(token.value))

0 commit comments

Comments
 (0)