Skip to content

Commit 68edf3f

Browse files
committed
lex error sections better
1 parent 1ae9596 commit 68edf3f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/robot/parsing/lexer/lexers.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ class CommentSectionHeaderLexer(SectionHeaderLexer):
143143
token_type = Token.COMMENT_HEADER
144144

145145

146+
class ErrorSectionHeaderLexer(SectionHeaderLexer):
147+
148+
def lex(self, ctx):
149+
self.statement[0].type = Token.ERROR
150+
self.statement[0].error = (
151+
"Unrecognized table header '%s'. Available headers for data: "
152+
"'Setting(s)', 'Variable(s)', 'Test Case(s)', 'Task(s)' and "
153+
"'Keyword(s)'. Use 'Comment(s)' to embedded additional data."
154+
% self.statement[0].value.strip('*').strip()
155+
)
156+
for token in self.statement[1:]:
157+
token.type = Token.COMMENT
158+
159+
146160
class CommentSectionLexer(SectionLexer):
147161
markers = ('Comment', 'Comments')
148162

@@ -171,11 +185,7 @@ def handles(cls, statement):
171185
return statement[0].value.startswith('*')
172186

173187
def lexer_classes(self):
174-
return (ErrorLexer,)
175-
176-
177-
class ErrorLexer(StatementLexer):
178-
token_type = Token.ERROR
188+
return (ErrorSectionHeaderLexer, CommentLexer)
179189

180190

181191
class SettingSectionLexer(SectionLexer):

0 commit comments

Comments
 (0)