Exemplo n.º 1
0
    def tokenCreator(self, text, i, token=None):

        if not token or token.formed:
            token = Token()

        char, pos = ord(text[i]), i

        #Formar nuevas cadenas
        if (not token.inFormation and self.is_quote(char)):
            token.add(char)
            token.inFormation = True
            token.formed = False
            token.type = "string"

        elif (token.inFormation):
            if (self.is_quote(token.atFirst()) and not self.is_quote(char)):
                token.add(char)
            else:
                token.add(char)
                token.formed = True
        else:
            token = Token()

        pos += 1
        return (pos, token)
Exemplo n.º 2
0
    def tokenCreator(self, char, token):

        repeatChar = None

        if not token or token.formed:
            token = Token()

        charCode = ord(char)

        # Comment
        if not token.inFormation and self.is_semicolon(charCode):
            token.formed = False
            token.inFormation = True
            token.type = "COMMENT"
            token.add(charCode)

        elif token.inFormation and self.is_semicolon(token.atFirst()):
            if self.is_newLine(charCode):
                token = Token()
            else:
                pass

        # Quote String
        elif not token.inFormation and self.is_quote(charCode):
            token.formed = False
            token.inFormation = True
            token.type = "STRING"
            token.add(charCode)

        elif token.inFormation and self.is_quote(token.atFirst()):
            if self.is_quote(charCode):
                token.add(charCode)
                token.inFormation = False
                token.formed = True
            else:
                token.add(charCode)

        # DoubleQuote String
        elif not token.inFormation and self.is_doubleQuote(charCode):
            token.formed = False
            token.inFormation = True
            token.type = "STRING"
            token.add(charCode)

        elif token.inFormation and self.is_doubleQuote(token.atFirst()):
            if self.is_doubleQuote(charCode):
                token.add(charCode)
                token.inFormation = False
                token.formed = True
            else:
                token.add(charCode)

        # Arithmetic Operator
        elif not token.inFormation and self.is_arithmeticOp(charCode):
            token.add(charCode)
            token.inFormation = False
            token.formed = True
            token.type = "ARITHMETIC_OP"

        # Identifier
        elif not token.inFormation and self.is_alpha(charCode):
            token.add(charCode)
            token.inFormation = True
            Token.Formed = False
            token.type = "IDENT"

        elif token.inFormation and self.is_alpha(token.atFirst()):
            if self.is_alpha(charCode) or self.is_digit(charCode):
                token.add(charCode)
            else:
                token.inFormation = False
                token.formed = True
                repeatChar = True

        return (token, repeatChar)