18 from .tokens
import Token
25 _space_splitter = re.compile(
r'(\s{2,}|\t)', re.UNICODE)
29 _pipe_splitter = re.compile(
r'((?:\A|\s+)\|(?:\s+|\Z))', re.UNICODE)
33 for lineno, line
in enumerate(data.splitlines(
not data_only), start=1):
34 tokens = self.
_tokenize_line_tokenize_line(line, lineno,
not data_only)
35 tokens, starts_new = self.
_cleanup_tokens_cleanup_tokens(tokens, data_only)
41 current.extend(tokens)
47 append = tokens.append
49 if line[:1] ==
'|' and line[:2].strip() ==
'|':
53 for value, is_data
in splitter(line.rstrip()):
55 append(
Token(
None, value, lineno, offset))
56 elif include_separators:
57 append(
Token(Token.SEPARATOR, value, lineno, offset))
59 if include_separators:
60 trailing_whitespace = line[len(line.rstrip()):]
61 append(
Token(Token.EOL, trailing_whitespace, lineno, offset))
72 _, separator, rest = splitter.split(line, 1)
73 yield separator,
False
74 while splitter.search(rest):
75 token, separator, rest = splitter.split(rest, 1)
77 yield separator,
False
92 return tokens, starts_new
99 if token.type
is None:
102 value = token.value.lstrip()
104 token.type = Token.COMMENT
107 token.type = Token.COMMENT
110 if value ==
'...' and not continues:
111 token.type = Token.CONTINUATION
115 return has_data, continues
118 for token
in reversed(tokens):
119 if not token.value
and token.type != Token.EOL:
121 elif token.type
is None:
125 data_or_continuation = (
None, Token.CONTINUATION)
126 for token
in list(tokens):
129 elif token.type
in data_or_continuation:
134 token =
Token(lineno=cont.lineno, col_offset=cont.end_col_offset)
135 tokens.insert(tokens.index(cont) + 1, token)
139 if token.type == Token.CONTINUATION:
143 return [t
for t
in tokens
if t.type
is None]
def _handle_comments_and_continuation(self, tokens)
def _cleanup_tokens(self, tokens, data_only)
def _find_continuation(self, tokens)
def _ensure_data_after_continuation(self, tokens)
def _remove_trailing_empty(self, tokens)
def _split_from_pipes(self, line)
def tokenize(self, data, data_only=False)
def _split_from_spaces(self, line)
def _tokenize_line(self, line, lineno, include_separators=True)
def _remove_leading_empty(self, tokens)
def _remove_non_data(self, tokens)
Token representing piece of Robot Framework data.