예제 #1
0
def BlockParser(input):
    return Parser.loop(
        Parser.terminal(TokenType.OPEN_CURLY),
        Parser.doAssert(StatementParser,
                        f"statement or '{TokenType.CLOSE_CURLY.key}'"),
        Parser.terminal(TokenType.CLOSE_CURLY),
        createNode=lambda open, statements, close: Block.withChildren(
            statements, open.pos))(input)
예제 #2
0
def MethodsDeclarationParser(input):
    return Parser.loop(
        Parser.terminal(TokenType.OPEN_CURLY),
        Parser.doAssert(FunctionDefinitionParser,
                        f"method definition or '{TokenType.CLOSE_CURLY.key}'"),
        Parser.terminal(TokenType.CLOSE_CURLY),
        createNode=lambda open, methods, close: Block.withChildren(
            methods, open.pos),
        name="methods block")(input)