Exemplo n.º 1
0
        return NoMatch()

    def p_arithmetic_interval(self, p_arithmetic_exp):
        p_interval = Suppress(Literal('xrange') | Literal('range')) + Suppress('(') \
                     + p_arithmetic_exp + Optional(Suppress(',') + p_arithmetic_exp) \
                     + Suppress(')')
        p_interval.setParseAction(self._parse_interval)
        return p_interval


class PyBoolExpressionParser(InfixBoolExpressionParser):
    def build_term_parser(self):
        return PyTermParser()

    @cached
    def p_cmp_in(self):
        not_in = Combine(CaselessKeyword(u'not') + CaselessKeyword(u'in'),
                         adjacent=False)
        p_cmp_in = CaselessKeyword(u'in') | not_in
        p_cmp_in.setParseAction(self._parse_cmp_operator)
        return p_cmp_in


py_term = PyTermParser().p_arithmetic_exp()
term_parsers.register_converter('python_bool',
                                PyBoolExpressionParser().p_bool_exp())
term_parsers.register_converter('python_term', py_term)
term_parsers.register_converter('python_term_list',
                                ListParser(py_term).p_list())
del py_term
Exemplo n.º 2
0
        return self._parse_interval(s,p, ('[', t[0], t[1], ')'))

    def p_list(self, p_item):
        p_list = pyparsing.delimitedList(p_item)
        p_list.setParseAction(self._parse_list)
        return p_list

    @cached
    def p_foreach_list(self):
        item = self.p_arithmetic_exp()
        p_colon_interval = item + pyparsing.Suppress(':') + item
        p_colon_interval.setParseAction(self._parse_colon_interval)
        p_values = self.p_list(item) | self.p_arithmetic_interval(item) | p_colon_interval
        return (pyparsing.Suppress('(') + p_values + pyparsing.Suppress(')')) | p_values

term_parsers.register_converter('slosl_foreach_list',
                                SloslForeachListParser().p_foreach_list())


class SloslForeachListSerializer(InfixTermBuilder):
    def _handle_list(self, operator, operands, status):
        assert operator == u'list'
        return [ u'%s' % u','.join(operands) ]

tree_converters.register_converter('slosl_foreach_list',
                                   SloslForeachListSerializer())


class SLOSLEditor(object):
    VALID_FUNCTIONS = ('lowest', 'highest', 'closest', 'furthest')
    def __init__(self):
        self.__setup_child_calls()
Exemplo n.º 3
0
            start, stop = t
        return [ ('interval:closed-open', start, stop) ]

    def p_case(self, *args):
        return NoMatch()

    def p_arithmetic_interval(self, p_arithmetic_exp):
        p_interval = Suppress(Literal('xrange') | Literal('range')) + Suppress('(') \
                     + p_arithmetic_exp + Optional(Suppress(',') + p_arithmetic_exp) \
                     + Suppress(')')
        p_interval.setParseAction(self._parse_interval)
        return p_interval

class PyBoolExpressionParser(InfixBoolExpressionParser):
    def build_term_parser(self):
        return PyTermParser()

    @cached
    def p_cmp_in(self):
        not_in = Combine(CaselessKeyword('not') + CaselessKeyword('in'), adjacent=False)
        p_cmp_in = CaselessKeyword('in') | not_in
        p_cmp_in.setParseAction(self._parse_cmp_operator)
        return p_cmp_in


py_term = PyTermParser().p_arithmetic_exp()
term_parsers.register_converter('python_bool',      PyBoolExpressionParser().p_bool_exp())
term_parsers.register_converter('python_term',      py_term)
term_parsers.register_converter('python_term_list', ListParser(py_term).p_list())
del py_term