Beispiel #1
0
    def parse(self, value, delimiter):
        self._delimiter = delimiter
        dollars = value.count('$')
        if dollars == 0:
            # speed up: only use pyparsing if there is a $ in the string
            return ScaItem(value)
        elif dollars == 1:
            # speed up: try a simple reference
            try:
                tokens = self._simple_ref_parser.leaveWhitespace().parseString(value).asList()
            except pp.ParseException as e:
                # fall back on the full parser
                try:
                    tokens = self._parser.leaveWhitespace().parseString(value).asList()
                except pp.ParseException as e:
                    raise ParseError(e.msg, e.line, e.col, e.lineno)
        else:
            # use the full parser
            try:
                tokens = self._parser.leaveWhitespace().parseString(value).asList()
            except pp.ParseException as e:
                raise ParseError(e.msg, e.line, e.col, e.lineno)

        items = self._create_items(tokens)
        if len(items) == 1:
            return items[0]
        else:
            return CompItem(items)
Beispiel #2
0
    def _parse_expression(self, expr):
        try:
            tokens = InvItem._parser.parseString(expr).asList()
        except pp.ParseException as e:
            raise ParseError(e.msg, e.line, e.col, e.lineno)

        if len(tokens) == 1:
            self._expr_type = tokens[0][0]
            self._expr = list(tokens[0][1])
        else:
            raise ExpressionError('Failed to parse %s' % str(expr))

        if self._expr_type == _TEST:
            export, parameter, value = self._get_vars(self._expr[2][1], None, None, None)
            export, parameter, value = self._get_vars(self._expr[4][1], export, parameter, value)
            if parameter is not None:
                path = parameter
                path.drop_first()
                self._refs.append(str(path))
Beispiel #3
0
    def _parse_expression(self, expr):
        parser = parser_funcs.get_expression_parser()
        try:
            tokens = parser.parseString(expr).asList()
        except pp.ParseException as e:
            raise ParseError(e.msg, e.line, e.col, e.lineno)

        if len(tokens) == 2:  # options are set
            passed_opts = [x[1] for x in tokens.pop(0)]
            self.ignore_failed_render = parser_funcs.IGNORE_ERRORS in passed_opts
            self.needs_all_envs = parser_funcs.ALL_ENVS in passed_opts
        elif len(tokens) > 2:
            raise ExpressionError('Failed to parse %s' % str(tokens),
                                  tbFlag=False)
        self._expr_type = tokens[0][0]
        self._expr = list(tokens[0][1])

        if self._expr_type == parser_funcs.VALUE:
            self._value_path = DictPath(self._settings.delimiter,
                                        self._expr[0][1]).drop_first()
            self._question = LogicTest([], self._settings.delimiter)
            self.refs = []
            self.inv_refs = [self._value_path]
        elif self._expr_type == parser_funcs.TEST:
            self._value_path = DictPath(self._settings.delimiter,
                                        self._expr[0][1]).drop_first()
            self._question = LogicTest(self._expr[2:],
                                       self._settings.delimiter)
            self.refs = self._question.refs
            self.inv_refs = self._question.inv_refs
            self.inv_refs.append(self._value_path)
        elif self._expr_type == parser_funcs.LIST_TEST:
            self._value_path = None
            self._question = LogicTest(self._expr[1:],
                                       self._settings.delimiter)
            self.refs = self._question.refs
            self.inv_refs = self._question.inv_refs
        else:
            msg = 'Unknown expression type: %s'
            raise ExpressionError(msg % self._expr_type, tbFlag=False)
Beispiel #4
0
    def _parse_expression(self, expr):
        try:
            tokens = InvItem._parser.parseString(expr).asList()
        except pp.ParseException as e:
            raise ParseError(e.msg, e.line, e.col, e.lineno)

        if len(tokens) == 1:
            self._expr_type = tokens[0][0]
            self._expr = list(tokens[0][1])
        elif len(tokens) == 2:
            for opt in tokens[0]:
                if opt[1] == _IGNORE_ERRORS:
                    self._ignore_failed_render = True
                elif opt[1] == _ALL_ENVS:
                    self._needs_all_envs = True
            self._expr_type = tokens[1][0]
            self._expr = list(tokens[1][1])
        else:
            raise ExpressionError('Failed to parse %s' % str(tokens), tbFlag=False)

        if self._expr_type == _VALUE:
            self._value_path = DictPath(self._settings.delimiter, self._expr[0][1]).drop_first()
            self._question = Question([], self._settings.delimiter)
            self._refs = []
            self._inv_refs = [ self._value_path ]
        elif self._expr_type == _TEST:
            self._value_path = DictPath(self._settings.delimiter, self._expr[0][1]).drop_first()
            self._question = Question(self._expr[2:], self._settings.delimiter)
            self._refs = self._question.refs()
            self._inv_refs = self._question.inv_refs()
            self._inv_refs.append(self._value_path)
        elif self._expr_type == _LIST_TEST:
            self._value_path = None
            self._question = Question(self._expr[1:], self._settings.delimiter)
            self._refs = self._question.refs()
            self._inv_refs = self._question.inv_refs()
        else:
            raise ExpressionError('Unknown expression type: %s' % self._expr_type, tbFlag=False)
Beispiel #5
0
 def full_parse():
     try:
         return self.ref_parser.parseString(value)
     except pp.ParseException as e:
         raise ParseError(e.msg, e.line, e.col, e.lineno)