Esempio n. 1
0
    def _get_token(self, tclass, value):

        # Override the superclass method to distinguish
        # keywords from other plain identifiers. If we
        # don't find a keyword (or if we're not dealing
        # with an identifier) then just call the superclass
        # method

        if tclass == FirstIdentifierToken:

            # Note: This routine will highlight keywords and
            # builtins even if they're not intended to be such,
            # e.g. if a keyword is used as a function argument
            # it will be highlighted as a keyword. This is probably
            # desired behaviour, since that's not a good practice,
            # and vi seems to do the same.

            if value in keyword.kwlist:
                return KeywordToken(value)
            elif value in dir(__builtin__):
                return BuiltinToken(value)
            else:
                return IdentifierToken(value)

        return Parser._get_token(self, tclass, value)
Esempio n. 2
0
    def _get_token(self, tclass, value):

        # Override the superclass method to distinguish
        # keywords from other plain identifiers. If we
        # don't find a keyword (or if we're not dealing
        # with an identifier) then just call the superclass
        # method

        ckeyws = ["auto", "break", "case", "char", "const", "continue",
                  "default", "do", "double", "else", "enum", "extern",
                  "float", "for", "goto", "if", "int", "long", "register",
                  "return", "short", "signed", "sizeof", "static",
                  "struct", "switch", "typedef", "union", "unsigned",
                  "void", "volatile", "while"]
        if tclass == IdentifierToken:
            if value in ckeyws:
                return KeywordToken(value)

        return Parser._get_token(self, tclass, value)