def parse_rule(self, text, filename=None): """Parse rule with optional background and scenario(s). :param text: Text that contains 0..* steps :return: List of parsed rule (as :class:`~behave.model:Rule` object). """ assert isinstance(text, six.text_type) if not self.language: self.language = DEFAULT_LANGUAGE self.reset() self.filename = filename self.rule = model.Rule(filename, 0, u"rule", u"") self.statement = self.rule self.state = "rule" for line in text.split("\n"): self.line += 1 if not line.strip() and self.state != "multiline": # -- SKIP EMPTY LINES, except in multiline string args. continue self.action(line) # -- FINALLY: if self.table: self.action_table("") steps = self.statement.steps return steps
def _build_rule_statement(self, keyword, line): name = line[len(keyword) + 1:].strip() rule = model.Rule(self.filename, self.line, keyword, name, tags=self.tags) self.rule = rule self.scenario_container = rule self.statement = rule # MAYBE: self.background = None self.feature.add_rule(self.statement) # -- RESET STATE: self.tags = []