Beispiel #1
0
 def __init__(self):
     from tl.bnf.declaration import Declaration
     from tl.bnf.variable import Variable
     Group.__init__(self, [
         "class",
         NamedToken('class_name', Variable),
         TokenFunctor(self.pushClassName),
         Group([
             ":",
             NamedToken('base0', Variable),
             TokenFunctor(self.pushBase0),
             Group([
                 ",",
                 NamedToken('basen', Variable),
                 TokenFunctor(self.pushBaseN),
             ],
                   min=0,
                   max=-1)
         ],
               min=0),
         "{",
         TokenFunctor(self.startScope),
         Group([Declaration], min=0, max=-1),
         "}",
     ])
     self._class_name = None
     self._bases = []
     self._scope = None
    def __init__(self, subexpr):
        self._subexpr = subexpr
        from tl.bnf.function_call import FunctionParam
#        from tl.bnf.variable_value import VariableValue
        from tl.bnf.operators import BinaryInfixOperator
        from tl.bnf.variable import Variable
        Group.__init__(self, [
            subexpr,
            Group([
                BinaryInfixOperator("."),
                NamedToken('attribute', Variable),
                Group([
                    '(',
                    Group([
                        FunctionParam,
                        Group([
                            ',',
                            FunctionParam
                        ], min=0, max=-1)
                    ], min=0, max=1),
                    ')',
                    TokenFunctor(self.pushMethod),
                ])
                | TokenFunctor(self.pushMember)
            ], min=0, max=-1)
        ])
Beispiel #3
0
    def __init__(self, is_affectation=False):
        from tl.bnf.value import Value
        self.is_affectation = is_affectation
        expr = SubExpr(group=(Group(['(', Expression, ')']) | Value))
        expr = AttributeAccessSubExpr(expr)
        for i, op in enumerate(self.__class__.__operators__):
            expr = SubExpr(
                operators=self.__class__.__operators__[i],
                subexpr=expr
            )

        if is_affectation:
            from tl.bnf.variable_value import VariableValue
            ops = list(BinaryInfixOperator(op) for op in self.__affect_operators__)
            Group.__init__(self, [
#                TokenFunctor(self.prepareLeftOperand),
#                AttributeAccessSubExpr(Variable)
#                | TokenFunctor(self.cleanupLeftOperand),
#                TokenFunctor(self.pushLeftOperand),
                AttributeAccessSubExpr(VariableValue),
                Alternative(ops),
                expr
            ])
        else:
            Group.__init__(self, expr)
Beispiel #4
0
 def __init__(self, operators=None, subexpr=None, group=None, min=1, max=1):
     if operators is not None and subexpr is not None:
         ops = list(BinaryInfixOperator(op) for op in operators)
         Group.__init__(self, [
              subexpr,
             Group([Alternative(ops), subexpr], min=0, max=-1)
         ], min=min, max=max)
     elif group is not None:
         Group.__init__(self, group, min, max)
Beispiel #5
0
 def __init__(self):
     Group.__init__(self, [
         '<', NamedToken('open', Identifier), '>',
         NamedToken('content', NamedToken('data', Identifier(r'[^<]+')) | Group(Balise, min=0, max=-1)),
         '</', NamedToken('close', Identifier), '>',
         TokenFunctor(self, Balise.hasSameTag),
     ])
     self._open_tag = self.getByName('open')
     self._node_content = self.getByName('content')
     self._close_tag = self.getByName('close')
Beispiel #6
0
 def __init__(self):
     from tl.bnf.declaration import Declaration
     Group.__init__(self, [
         BlockStatement
         | ReturnStatement
         | FunctionCallStatement
         | MethodCallStatement
         | Declaration
         | Affectation
     ])
Beispiel #7
0
 def __init__(self):
     from tl.bnf.declaration import Declaration
     Group.__init__(self, [
         BlockStatement
         | ReturnStatement
         | FunctionCallStatement
         | MethodCallStatement
         | Declaration
         | Affectation
     ])
 def __init__(self):
     Group.__init__(self, [
         Group([
             NamedToken('type', Type),
             NamedToken('name', Variable),
             TokenFunctor(self.pushBoth)
         ])| Group([
             NamedToken('auto_name', Variable),
             TokenFunctor(self.pushName)
         ])
     ])
Beispiel #9
0
 def __init__(self, group=None, min=1, max=1):
     Group.__init__(
         self,
         [
             NamedToken("function_name", Variable),
             TokenFunctor(self.pushName),
             "(",
             Group([FunctionParam, Group([",", FunctionParam], min=0, max=-1)], min=0, max=1),
             ")",
         ],
         min=min,
         max=max,
     )
Beispiel #10
0
 def match(self, context):
     expr = context.beginExpression()
     res = Group.match(self, context)
     context.endExpression()
     if res == True:
         context.getCurrentScope().statements.append(expr.clean())
     return res
Beispiel #11
0
 def __init__(self):
     Group.__init__(self, [
         '<', NamedToken('open', BaliseTag), '>',
         Identifier(r'[^<]+') | Group(Balise, min=0, max=-1)),
         '</', NamedToken('close', BaliseTag), '>',
         TokenFunctor(self.hasSameTag),
     ])
 def match(self, context):
     expr = context.beginExpression()
     res = Group.match(self, context)
     context.endExpression()
     if res == True:
         context.getCurrentScope().statements.append(expr[0])
     return res
Beispiel #13
0
 def __init__(self, keywords, with_expression, min=1, max=1):
     self._keywords = keywords
     self._with_expression = with_expression
     group = [self._keywords]
     if self._with_expression == True:
         from tl.bnf.expression import Expression
         group.extend(["(", Expression, ")"])
     from tl.bnf.statement import Statement
     group.extend([
         "{",
         Group([Statement], min=0, max=-1),
         "}",
         TokenFunctor(self.endScope)]
     )
     Group.__init__(self, group, min=min, max=max)
     self._scope = None
     self._expr = None
Beispiel #14
0
 def match(self, context):
     context.beginExpression()
     res = Group.match(self, context)
     expr = context.getCurrentExpression()
     context.endExpression()
     if res == True:
         context.getCurrentExpression().append(expr)
     return res
Beispiel #15
0
 def match(self, context):
     context.beginExpression()
     res = Group.match(self, context)
     expr = context.getCurrentExpression()
     context.endExpression()
     if res == True:
         context.getCurrentExpression().append(ast.FunctionCall(expr[0], expr[1:]))
     return res
Beispiel #16
0
 def match(self, context):
     context.beginExpression()
     res = Group.match(self, context)
     expr = context.getCurrentExpression()
     context.endExpression()
     if res == True:
         context.getCurrentExpression().append(expr.clean())
     return res
Beispiel #17
0
 def __init__(self):
     Group.__init__(self, [
         '<',
         NamedToken('open', Identifier),
         '>',
         NamedToken(
             'content',
             NamedToken('data', Identifier(r'[^<]+'))
             | Group(Balise, min=0, max=-1)),
         '</',
         NamedToken('close', Identifier),
         '>',
         TokenFunctor(self, Balise.hasSameTag),
     ])
     self._open_tag = self.getByName('open')
     self._node_content = self.getByName('content')
     self._close_tag = self.getByName('close')
Beispiel #18
0
    def match(self, context):
        self._class_name = None
        self._bases = []
        self._scope = None

        res = Group.match(self, context)
        if self._scope is not None:
            context.endScope()
        if res == False and self._class_name is not None:
            raise Exception("Error in class declaration " + self._class_name)
        return res
Beispiel #19
0
    def match(self, context):
        self._class_name = None
        self._bases = []
        self._scope = None

        res = Group.match(self, context)
        if self._scope is not None:
            context.endScope()
        if res == False and self._class_name is not None:
            raise Exception("Error in class declaration " + self._class_name)
        return res
 def match(self, context):
     self._is_first = True
     main = context.beginExpression()
     self._expr = context.beginExpression()
     res = Group.match(self, context)
     context.endExpression()
     if res == True and len(self._expr) > 0:
         main.append(self._expr)
     context.endExpression()
     context.getCurrentExpression().append(main)
     return res
Beispiel #21
0
 def __init__(self):
     Group.__init__(self, [
         Group([
             NamedToken('type', Type),
             NamedToken('name', Variable),
             TokenFunctor(self.pushBoth)
         ])
         | Group([
             NamedToken('auto_name', Variable),
             TokenFunctor(self.pushName)
         ]),
         Group(
             Group([
                 TokenFunctor(self.hasBoth),
                 Group(['(', Expression, ')'])
             ]) | Group(['=', Expression]),
             min=0, max=1
         ),
         EndStatement
     ])
Beispiel #22
0
class ReturnStatement(Group):
    __group__ = ["return", Group([Expression], min=0), ";"]

    def match(self, context):
        expr = context.beginExpression()
        res = Group.match(self, context)
        context.endExpression()
        if res == True:
            context.getCurrentScope().statements.append(
                ["return", expr.clean()])
        return res
Beispiel #23
0
 def __init__(self):
     from tl.bnf.declaration import Declaration
     from tl.bnf.variable import Variable
     Group.__init__(self, [
         "class",
         NamedToken('class_name', Variable),
         TokenFunctor(self.pushClassName),
         Group([
             ":", NamedToken('base0', Variable), TokenFunctor(self.pushBase0),
             Group([
                 ",", NamedToken('basen', Variable), TokenFunctor(self.pushBaseN),
             ], min=0, max=-1)
         ], min=0),
         "{",
         TokenFunctor(self.startScope),
         Group([Declaration], min=0, max=-1),
         "}",
     ])
     self._class_name = None
     self._bases = []
     self._scope = None
Beispiel #24
0
 def match(self, context):
     print '#STARTMATCH',object.__str__(self)
     context.printTokenStack()
     self._params = []
     self._scope = None
     res = Group.match(self, context)
     if self._scope is not None:
         context.endScope()
     self._params = []
     self._scope = None
     print '#ENDMATCH',object.__str__(self), res
     return res
Beispiel #25
0
 def __init__(self):
     Group.__init__(self, [
         NamedToken('type', Type),
         NamedToken('name', Variable),
         "(",
         Group([
             [
                 NamedToken('param', FunctionDeclarationParam),
                 TokenFunctor(self.pushParam),
             ],
             Group([
                 ",",
                 NamedToken('oparam', FunctionDeclarationParam),
                 TokenFunctor(self.pushOtherParam),
             ], min=0, max=-1)
         ], min=0),
         ")",
         "{",
         TokenFunctor(self.startScope),
         Group([Statement], min=0, max=-1),
         "}",
     ])
Beispiel #26
0
 def __init__(self):
     Group.__init__(self, [
         Group([
             NamedToken('type', Type),
             NamedToken('name', Variable),
             TokenFunctor(self.pushBoth)
         ])
         | Group([
             NamedToken('auto_name', Variable),
             TokenFunctor(self.pushName)
         ]),
         Group(Group(
             [TokenFunctor(self.hasBoth),
              Group(['(', Expression, ')'])]) | Group(['=', Expression]),
               min=0,
               max=1), EndStatement
     ])
Beispiel #27
0
 def match(self, context):
     if self._with_expression == True:
         self._expr = context.beginExpression()
     if isinstance(self._keywords, list):
         name = "-".join(self._keywords)+'_'
     else:
         name = str(self._keywords)+'_'
     self._scope = context.beginScope(
         ast.SCOPE_TYPES['block'],
         name,
         generate_unique=True
     )
     res = Group.match(self, context)
     if self._with_expression == True:
         context.endExpression()
     if self._scope is not None:
         context.endScope()
     return res
Beispiel #28
0
class Row(Group):
    __group__ = [Data, Group([Separator, Data], min=0, max=-1), EOL]

    def onMatch(self, context):
        context.rows.append([])
Beispiel #29
0
 def __init__(self):
     Group.__init__(self, [Block("while", True)])
Beispiel #30
0
 def __init__(self):
     Group.__init__(self, [
         Block("while", True)
     ])
 def match(self, context):
     context.beginExpression()
     res = Group.match(self, context)
     context.endExpression()
     return res
Beispiel #32
0
 def __init__(self):
     Group.__init__(self, [
         Block("if", True),
         Block(["else", "if"], True, min=0, max=-1),
         Block("else", False, min=0, max=1)
     ])
 def match(self, context):
     context.beginExpression()
     res = Group.match(self, context)
     context.endExpression()
     return res
Beispiel #34
0
class TinyXml(Group):
    __group__ = Group([Balise()], max=-1)
Beispiel #35
0
 def __init__(self):
     Group.__init__(self, [
         Block("if", True),
         Block(["else", "if"], True, min=0, max=-1),
         Block("else", False, min=0, max=1)
     ])
Beispiel #36
0
class CSV(Group):
    __group__ = Group([Row], max=-1)