Exemple #1
0
 def __init__(self, variables, flavor, values, body=None, _header='FOR'):
     self.variables = variables
     self.flavor = normalize_whitespace(flavor)
     self.values = values
     self.body = body or []
     self._header = _header
     self._end = 'END'
Exemple #2
0
 def _split(self, statement):
     current = []
     expect_condition = False
     for token in statement:
         if expect_condition:
             token._add_eos_after = True
             current.append(token)
             yield current
             current = []
             expect_condition = False
         elif token.value == 'IF':
             current.append(token)
             expect_condition = True
         elif normalize_whitespace(token.value) == 'ELSE IF':
             token._add_eos_before = True
             yield current
             current = [token]
             expect_condition = True
         elif token.value == 'ELSE':
             token._add_eos_before = True
             token._add_eos_after = True
             yield current
             current = []
             yield [token]
         else:
             current.append(token)
     yield current
 def lex(self):
     self.statement[0].type = Token.FOR
     separator_seen = False
     for token in self.statement[1:]:
         if separator_seen:
             token.type = Token.ARGUMENT
         elif normalize_whitespace(token.value) in self.separators:
             token.type = Token.FOR_SEPARATOR
             separator_seen = True
         else:
             token.type = Token.VARIABLE
Exemple #4
0
 def lex(self, statement):
     setting = statement[0]
     orig = self._format_name(setting.value)
     name = normalize_whitespace(orig).title()
     name = self.languages.translate_setting(name)
     if name in self.aliases:
         name = self.aliases[name]
     try:
         self._validate(orig, name, statement)
     except ValueError as err:
         self._lex_error(setting, statement[1:], err.args[0])
     else:
         self._lex_setting(setting, statement[1:], name)
 def lex(self, statement):
     name_token = statement[0]
     name = self._format_name(normalize_whitespace(name_token.value))
     normalized = self._normalize_name(name)
     try:
         self._validate(name, normalized, statement)
     except ValueError as err:
         name_token.type = Token.ERROR
         name_token.error = err.args[0]
     else:
         name_token.type = getattr(Token, normalized.replace(' ', '_'))
         self.settings[normalized] = statement[1:]
     for token in statement[1:]:
         token.type = Token.ARGUMENT
Exemple #6
0
 def lex(self, statement):
     name_token = statement[0]
     name = self._format_name(normalize_whitespace(name_token.value))
     normalized = self._normalize_name(name)
     try:
         self._validate(name, normalized, statement)
     except ValueError as err:
         name_token.type = Token.ERROR
         name_token.error = err.args[0]
     else:
         name_token.type = getattr(Token, normalized.replace(' ', '_'))
         self.settings[normalized] = statement[1:]
     for token in statement[1:]:
         token.type = Token.ARGUMENT
     if name_token.type in (Token.DOCUMENTATION, Token.METADATA) \
             and self._data_only:
         doc_index = 1 if name_token.type == Token.DOCUMENTATION else 2
         self._merge_doc_tokens_on_same_line(statement[doc_index:])
Exemple #7
0
 def _is_separator(self, value, arguments_seen, separator_seen):
     if separator_seen or not arguments_seen:
         return False
     return normalize_whitespace(value) in self._separators
Exemple #8
0
 def name(self):
     token = self.get_token(*self.handles_types)
     return normalize_whitespace(token.value).strip('* ')
Exemple #9
0
 def flavor(self):
     value = self.get_value(Token.FOR_SEPARATOR)
     return normalize_whitespace(value) if value is not None else None
Exemple #10
0
 def tasks(self):
     header = normalize_whitespace(self.header.data_tokens[0].value)
     return header.strip('* ').upper() in ('TASKS', 'TASK')
Exemple #11
0
 def flavor(self):
     separator = self.get_token(Token.FOR_SEPARATOR)
     return normalize_whitespace(separator.value) if separator else None
Exemple #12
0
 def handles(self, statement):
     return normalize_whitespace(statement[0].value) == 'ELSE IF'
Exemple #13
0
 def __init__(self, tests, header):
     self.tests = tests
     section_name = normalize_whitespace(header[0]).strip('* ')
     self.tasks = section_name.upper() in ('TASKS', 'TASK')
Exemple #14
0
 def _split_alias(self, args):
     if len(args) > 1 and normalize_whitespace(args[-2]) == 'WITH NAME':
         return args[:-2], args[-1]
     return args, None
 def __init__(self, variables, flavor, values, body=None):
     self.variables = variables
     self.flavor = normalize_whitespace(flavor)
     self.values = values
     self.body = body or []
 def _is_separator(self, value):
     return normalize_whitespace(value) in self.separators
Exemple #17
0
 def value(self):
     header = self.get_token(self.type)
     return normalize_whitespace(header.value).strip('* ')
 def handles(cls, statement, ctx):
     return normalize_whitespace(statement[0].value) == 'ELSE IF'
Exemple #19
0
 def _normalize(self, marker):
     return normalize_whitespace(marker).strip('* ').title()
 def _normalize(self, marker, remove=None):
     if remove:
         marker = marker.replace(remove, '')
     return normalize_whitespace(marker).strip().title()
Exemple #21
0
 def _lex_name_arguments_and_with_name(self, tokens):
     self._lex_name_and_arguments(tokens)
     if len(tokens) > 1 and \
             normalize_whitespace(tokens[-2].value) in ('WITH NAME', 'AS'):
         tokens[-2].type = Token.WITH_NAME
         tokens[-1].type = Token.NAME
Exemple #22
0
 def _normalize_name(self, name):
     name = normalize_whitespace(name).title()
     if name in self.aliases:
         return self.aliases[name]
     return name
Exemple #23
0
 def _get_args_and_alias(self):
     args = tuple(self.get_values(Token.ARGUMENT)[1:])
     if len(args) > 1 and normalize_whitespace(args[-2]) == 'WITH NAME':
         return args[:-2], args[-1]
     return args, None
 def _normalize_name(self, name):
     upper = normalize_whitespace(name).upper()
     if upper in self.aliases:
         return self.aliases[upper]
     return upper