예제 #1
0
class Not(CIKeyword):
    """
    The reason for defining an Enum grammar of Keywords is for populating the Keyword.table for checking whether
    terminal symbols are actually DSL keywords.
    """
    regex = re.compile(r"(not|-)", re.IGNORECASE)
    grammar = Enum(K("not"), K("-"))
class And(CIKeyword):
    """
    The reason for defining an Enum grammar of Keywords is for populating the Keyword.table for checking whether
    terminal symbols are actually DSL keywords.
    """
    regex = re.compile(r"(and|\+|&)", re.IGNORECASE)
    grammar = Enum(K("and"), K("+"), K("&"))
예제 #3
0
class Operator(Keyword):
    """
    Operator in transaction output condition
    """

    grammar = Enum(K("&&"), K("||"), K("AND"), K("OR"))
    regex = re.compile(r"[&&|\|\||\w]+")

    @classmethod
    def token(cls: Type[OperatorType], keyword: str) -> OperatorType:
        """
        Return Operator instance from keyword

        :param keyword: Operator keyword in expression
        :return:
        """
        op = cls(keyword)
        return op

    def compose(
        self, parser: Any = None, grammar: Any = None, attr_of: str = None
    ) -> str:
        """
        Return the Operator keyword as string format

        :param parser: Parser instance
        :param grammar: Grammar
        :param attr_of: Attribute of...
        """
        return "{0}".format(self.name)
예제 #4
0
class Operator(Symbol):
    grammar = Enum(K("&"), K("-"))

    def _build(self, rr):
        rr._ops.append(self[0])
        rr._nextop = self[0]
        return
예제 #5
0
class Or(CIKeyword):
    """
    The reason for defining an Enum grammar of Keywords is for populating the Keyword.table for checking whether
    terminal symbols are actually DSL keywords.
    """
    regex = re.compile(r"(or|\|)", re.IGNORECASE)
    grammar = Enum(K("or"), K("|"))

    def __init__(self, *args):
        # Normalize different OR keywords (ignore the keyword argument that was passed).
        super(Or, self).__init__(BooleanOperator.OR)
예제 #6
0
                                             p.compose(self[0], **x))
        p.indention_level += 1
        s += "{0}\n".format(p.compose(self[1], **x))
        p.indention_level -= 1
        s += "{0}}}".format(p.indent * p.indention_level)
        return s

    def to_simple(self):
        """Generate corresponding simple object that can be evaluated."""
        return s_s.While(self[0].to_simple(), self[1].to_simple())


identifier = regex(r"[a-zA-Z_][0-9a-zA-Z_]*")
Symbol.regex = identifier

Keyword.grammar = Enum(K("else"), K("if"), K("while"))
Symbol.check_keywords = True

Number.grammar = regex(r"(\+|\-)?[0-9]+(\.[0-9]+)?")
Boolean.grammar = regex(r"(true|false)")
Variable.grammar = Symbol

term_expression = [Number, Boolean, Variable]

Not.grammar = "!", term_expression

unary_term_expression = [Not, term_expression]

multiplicative_expression = [Multiply, Divide, unary_term_expression]

Multiply.grammar = term_expression, "*", multiplicative_expression
예제 #7
0
class Type(Keyword):
    grammar = Enum(K('int'), K('long'))
예제 #8
0
class ClauseOperator(Symbol):
    regex = re.compile(r"[^\s]{1,2}")
    grammar = Enum("=", "<", ">", ">=", "<=")