18 from .tokens
import Token
19 from .statementlexers
import (Lexer,
20 SettingSectionHeaderLexer, SettingLexer,
21 VariableSectionHeaderLexer, VariableLexer,
22 TestCaseSectionHeaderLexer,
23 TaskSectionHeaderLexer,
24 KeywordSectionHeaderLexer,
25 CommentSectionHeaderLexer, CommentLexer, ImplicitCommentLexer,
26 ErrorSectionHeaderLexer,
27 TestOrKeywordSettingLexer,
29 IfHeaderLexer, ElseIfHeaderLexer, ElseHeaderLexer,
30 InlineIfHeaderLexer, EndLexer,
31 TryHeaderLexer, ExceptHeaderLexer, FinallyHeaderLexer,
32 ForHeaderLexer, WhileHeaderLexer,
33 ContinueLexer, BreakLexer, ReturnLexer)
48 lexer = self.
lexerslexers[-1]
50 lexer = self.
lexer_forlexer_for(statement)
51 self.
lexerslexers.append(lexer)
52 lexer.input(statement)
58 lexer = cls(self.
ctxctx)
60 raise TypeError(f
"{type(self).__name__} does not have lexer for "
61 f
"statement {statement}.")
67 for lexer
in self.
lexerslexers:
71 for lexer
in self.
lexerslexers:
72 if isinstance(lexer, priority):
74 for lexer
in self.
lexerslexers:
75 if not isinstance(lexer, priority):
85 return (SettingSectionLexer, VariableSectionLexer,
86 TestCaseSectionLexer, TaskSectionLexer,
87 KeywordSectionLexer, CommentSectionLexer,
88 ErrorSectionLexer, ImplicitCommentSectionLexer)
94 return not statement[0].value.startswith(
'*')
101 return ctx.setting_section(statement)
104 return (SettingSectionHeaderLexer, SettingLexer)
111 return ctx.variable_section(statement)
114 return (VariableSectionHeaderLexer, VariableLexer)
121 return ctx.test_case_section(statement)
124 return (TestCaseSectionHeaderLexer, TestCaseLexer)
131 return ctx.task_section(statement)
134 return (TaskSectionHeaderLexer, TestCaseLexer)
141 return ctx.keyword_section(statement)
144 return (KeywordSectionHeaderLexer, KeywordLexer)
151 return ctx.comment_section(statement)
154 return (CommentSectionHeaderLexer, CommentLexer)
164 return (ImplicitCommentLexer,)
171 return statement
and statement[0].value.startswith(
'*')
174 return (ErrorSectionHeaderLexer, CommentLexer)
178 name_type = NotImplemented
185 return not statement[0].value
190 super().
input(statement)
194 token = statement.pop(0)
197 token._add_eos_after =
True
200 while statement
and not statement[0].value:
201 statement.pop(0).type =
None
204 return (TestOrKeywordSettingLexer, BreakLexer, ContinueLexer,
205 ForLexer, InlineIfLexer, IfLexer, ReturnLexer, TryLexer,
206 WhileLexer, KeywordCallLexer)
210 name_type = Token.TESTCASE_NAME
214 super().
__init__(ctx.test_case_context())
221 name_type = Token.KEYWORD_NAME
224 super().
__init__(ctx.keyword_context())
237 lexer = super().
input(statement)
238 if isinstance(lexer, (ForHeaderLexer, IfHeaderLexer, TryHeaderLexer,
241 if isinstance(lexer, EndLexer):
249 return ForHeaderLexer.handles(statement, ctx)
252 return (ForHeaderLexer, InlineIfLexer, IfLexer, TryLexer, WhileLexer, EndLexer,
253 ReturnLexer, ContinueLexer, BreakLexer, KeywordCallLexer)
260 return WhileHeaderLexer.handles(statement, ctx)
263 return (WhileHeaderLexer, ForLexer, InlineIfLexer, IfLexer, TryLexer, EndLexer,
264 ReturnLexer, ContinueLexer, BreakLexer, KeywordCallLexer)
271 return IfHeaderLexer.handles(statement, ctx)
274 return (InlineIfLexer, IfHeaderLexer, ElseIfHeaderLexer, ElseHeaderLexer,
275 ForLexer, TryLexer, WhileLexer, EndLexer, ReturnLexer, ContinueLexer,
276 BreakLexer, KeywordCallLexer)
283 if len(statement) <= 2:
285 return InlineIfHeaderLexer.handles(statement, ctx)
291 return (InlineIfHeaderLexer, ElseIfHeaderLexer, ElseHeaderLexer,
292 ReturnLexer, ContinueLexer, BreakLexer, KeywordCallLexer)
295 for part
in self.
_split_split(statement):
302 expect_condition =
False
303 for token
in statement:
305 if token
is not statement[-1]:
306 token._add_eos_after =
True
307 current.append(token)
310 expect_condition =
False
311 elif token.value ==
'IF':
312 current.append(token)
313 expect_condition =
True
315 token._add_eos_before =
True
318 expect_condition =
True
319 elif token.value ==
'ELSE':
320 token._add_eos_before =
True
321 if token
is not statement[-1]:
322 token._add_eos_after =
True
327 current.append(token)
338 return (TryHeaderLexer, ExceptHeaderLexer, ElseHeaderLexer, FinallyHeaderLexer,
339 ForLexer, InlineIfLexer, IfLexer, WhileLexer, EndLexer, ReturnLexer,
340 BreakLexer, ContinueLexer, KeywordCallLexer)
def _lex_with_priority(self, priority)
def __init__(self, ctx)
:type ctx: :class:robot.parsing.lexer.context.FileContext
def accepts_more(self, statement)
def lexer_for(self, statement)
def input(self, statement)
def handles(cls, statement, ctx)
def handles(cls, statement, ctx)
def handles(cls, statement, ctx)
def handles(cls, statement, ctx)
def input(self, statement)
def accepts_more(self, statement)
def _split(self, statement)
def __init__(self, ctx)
:type ctx: :class:robot.parsing.lexer.context.FileContext
def handles(cls, statement, ctx)
def accepts_more(self, statement)
def __init__(self, ctx)
:type ctx: :class:robot.parsing.lexer.context.FileContext
def input(self, statement)
def accepts_more(self, statement)
def handles(cls, statement, ctx)
def handles(cls, statement, ctx)
def __init__(self, ctx)
:type ctx: :class:robot.parsing.lexer.context.TestCaseFileContext
def handles(cls, statement, ctx)
def _handle_name_or_indentation(self, statement)
def accepts_more(self, statement)
def input(self, statement)
def handles(cls, statement, ctx)
def handles(cls, statement, ctx)
def handles(cls, statement, ctx)
def handles(cls, statement, ctx)
def normalize_whitespace(string)