示例#1
0
def _resolve(self, tokens, filename, passN= 0 ):
    if self.hotswap and not ImportParser.shouldCompile(False, self.package, self):
        return

    self.filename = filename
    self.iter = 0

    self.tokens = tokens

    while self.iter < len(tokens) - 1 :
        b = self.thisToken().token

        if passN == 2:
            if b == "import":
                ImportParser.importParser(self, True)
            elif b == "def" :
                if self.indentLevel == 0:
                    nex = self.lookInfront()

                    Parser.addBookmark(self)
                    funcHead(self)
                    Parser.returnBookmark(self)
        elif passN == 1:
            if b == "import":
                ImportParser.importParser(self, True)

            elif b == "type":
                Parser.addBookmark(self)
                Struct.typeParser(self, decl= True)
                Parser.returnBookmark(self)

        elif passN == 0:
            if b == "type":
                Scope.addVar(Tree.Node(self), self, self.nextToken().token, Scope.Type(True, Types.StructInit(self.thisToken().token)))

                #"""
                self.structs[self.package][self.thisToken().token] = Struct.Struct(self.thisToken().token, [],[], {}, self)
                self.structs[self.package][self.thisToken().token].methods = {}
                #"""

        if b == "\n":
            Parser.addBookmark(self)
            Parser.newLine(self)
            Parser.returnBookmark(self)

        self.nextToken()

    for i in self.imports:
        if not i in self.allImports[self.package]:
            self.allImports[self.package].add(i)


    self.imports = []

    self.lineNumber = 1
    self.normalIndent = 0
示例#2
0
def _resolve(self, tokens, filename, passN= 0 ):
    self.filename = filename
    self.iter = 0

    self.tokens = tokens

    while self.iter < len(tokens) - 1 :
        b = self.thisToken().token

        if passN == 2:
            if b == "import":
                ImportParser.importParser(self, True)
            elif b == "def" :
                if self.indentLevel == 0:
                    nex = self.lookInfront()

                    Parser.addBookmark(self)
                    funcHead(self)
                    Parser.returnBookmark(self)
        elif passN == 1:
            if b == "import":
                ImportParser.importParser(self, True)

            elif b == "type":
                Parser.addBookmark(self)
                Struct.typeParser(self, decl= True)
                Parser.returnBookmark(self)

        elif passN == 0:
            if b == "type":
                Scope.addVar(Tree.Node(self), self, self.nextToken().token, Scope.Type(True, Types.StructInit(self.thisToken().token)))

                self.structs[self.package][self.thisToken().token] = Struct.Struct(self.thisToken().token, [],[], {})
                self.structs[self.package][self.thisToken().token].methods = {}

        if b == "\n":
            Parser.addBookmark(self)
            Parser.newLine(self)
            Parser.returnBookmark(self)

        self.nextToken()

    for i in self.imports:
        if not i in self.allImports[self.package]:
            self.allImports[self.package].append(i)

    self.imports = []

    self.lineNumber = 1
    self.normalIndent = 0
示例#3
0
def match(parser):
    t = parser.thisToken()
    self = Tree.Match(parser)
    parser.currentNode.addNode(self)
    parser.currentNode = self

    while t.token != "with":
        t = parser.nextToken()
        if t.token == "with":
            break
        Parser.callToken(parser)
        t = parser.thisToken()

    ExprParser.endExpr(parser)

    parser.nextToken()
    Parser.callToken(parser)

    while not Parser.isEnd(parser):
        t = parser.nextToken()
        if t.token == "->":
            ExprParser.endExpr(parser)

            #print("entered ->")
            if len(self.nodes) == 0:
                Error.parseError(parser, "unexpected ->")
            previos = self.nodes[-1]
            if type(previos) is [Tree.MatchCase, Tree.Block]:
                Error.parseError(parser, "unexpected ->")

            case = Tree.MatchCase(parser)
            case.addNode(previos)

            self.nodes[-1] = case
            case.owner = self

            body = Tree.Block(parser)
            self.addNode(body)

            parser.currentNode = body

            Parser.addBookmark(parser)

            parser.nextToken()
            Parser.callToken(parser)

            while not Parser.isEnd(parser):
                parser.nextToken()
                """if Parser.isEnd(parser):
                    parser.callToken(parser)
                    #print("break", parser.thisToken())
                break
                """
                Parser.callToken(parser)
            #print("break", parser.thisToken())
            Parser.returnBookmark(parser)

            ExprParser.endExpr(parser)
            parser.currentNode = body.owner

            continue

        Parser.callToken(parser)

        if parser.thisToken().token == "->":
            parser.iter -= 1

    if len(self.nodes) % 2 == 0:
        Error.parseError(parser, "Expecting ->")

    parser.currentNode = self.owner
示例#4
0
def _resolve(self, tokens, filename, passN=0):
    target = self.global_target
    if self.package != "main":
        self.global_target = "full"

    if self.hotswap and not ImportParser.shouldCompile(False, self.package,
                                                       self):
        return

    self.filename = filename
    self.iter = 0

    self.tokens = tokens

    while self.iter < len(tokens) - 1:
        b = self.thisToken().token

        if passN == 2:
            if b == "import":
                ImportParser.importParser(self, True)
            elif b == "from":
                ImportParser.fromParser(self, True)
            elif b == "def":
                if self.indentLevel == 0:
                    nex = self.lookInfront()

                    Parser.addBookmark(self)
                    funcHead(self)
                    Parser.returnBookmark(self)
        elif passN == 1:
            if b == "import":
                ImportParser.importParser(self, True)
            elif b == "from":
                ImportParser.fromParser(self, True)
            elif b == "type":
                Parser.addBookmark(self)
                Struct.typeParser(self, decl=True)
                Parser.returnBookmark(self)

        elif passN == 0:
            if b == "type":
                name = self.nextToken().token
                if name == "ext":
                    name = self.nextToken().token

                ofType = None
                gen = {}

                if self.nextToken().token == "[":
                    Scope.incrScope(self)
                    gen = FuncParser.generics(self, name)
                    Scope.decrScope(self)
                    ofType = self.thisToken().token
                else:
                    ofType = self.thisToken().token

                Scope.addVar(Tree.Node(self), self, name,
                             Scope.Type(True, Types.StructInit(name)))

                if ofType is None or ofType == "=":
                    #"""
                    self.structs[self.package][name] = Struct.Struct(
                        name, [], [], gen, self, self.package)
                    self.structs[self.package][name].methods = {}
                    #"""
                elif ofType == "either":
                    self.interfaces[self.package][name] = Types.Enum(
                        self.package, name, coll.OrderedDict(), gen)
                elif ofType == "with":
                    self.interfaces[self.package][name] = Types.Interface(
                        False, {}, name=self.package + "." + name)
                elif ofType == "is":
                    self.interfaces[self.package][name] = Types.Alias(
                        self.package, name, Types.Null(), gen)

        if b == "\n":
            Parser.addBookmark(self)
            Parser.newLine(self)
            Parser.returnBookmark(self)

        self.nextToken()

    for i in self.imports:
        if not i in self.allImports[self.package]:
            self.allImports[self.package].append(i)

    self.imports = []

    self.lineNumber = 1
    self.normalIndent = 0

    self.global_target = target