edk2toollib/uefi/edk2/parsers/base_parser.py
def _TokenizeConditional(cls, text):
        ''' takes in a string that has macros replaced '''
        # TOKENIZER
        # first we create tokens
        TEXT_MODE = 0
        QUOTE_MODE = 1
        MACRO_MODE = 2
        token = ""
        mode = 0
        tokens = []
        for character in text:
            if character == "\"" and len(token) == 0:
                mode = QUOTE_MODE
            elif character == "\"" and mode == QUOTE_MODE:
                if len(token) > 0:
                    tokens.append(f"\"{token}\"")
                    token = ""
                mode = TEXT_MODE
            elif character == "$" and len(token) == 0:
                token += character
                mode = MACRO_MODE
            elif character == ')' and mode == MACRO_MODE:
                token += character
                tokens.append(token)
                token = ""
                mode = TEXT_MODE
            elif mode == TEXT_MODE and (character == "(" or character == ")"):
                if len(token) > 0:
                    tokens.append(token)
                    token = ""
                tokens.append(character)
            elif character == " " and (mode == TEXT_MODE or mode == MACRO_MODE):
                if len(token) > 0:
                    tokens.append(token)
                    token = ""
                    mode = TEXT_MODE
            else:
                token += character
        # make sure to add in the last token just in case
        if len(token) > 0:
            tokens.append(token)

        # then we do the lexer and convert operands as necessary
        for index in range(len(tokens)):
            token = tokens[index]
            token_upper = token.upper()
            if token_upper in cls.operators:
                token = token_upper
            elif token_upper == "||":
                token = "OR"
            elif token_upper == "&&":
                token = "AND"
            elif token_upper == "EQ":
                token = "=="
            elif token_upper == "NE":
                token = "!="
            elif token == "!":
                token = "NOT"
            tokens[index] = token

        # collapse the not
        collapsed_tokens = []
        found_not = False
        for token in tokens:
            if str(token).upper() == "NOT":
                found_not = True
                continue
            if not found_not:
                collapsed_tokens.append(token)
            elif token in cls.operators:
                collapsed_tokens.append("!+" + token)
                found_not = False
            else:  # add the not back
                found_not = False
                collapsed_tokens.append("NOT")
                collapsed_tokens.append(token)

        return collapsed_tokens
 takes in a string that has macros replaced 
takes in a string that has macros replaced
takes in a string that has macros replaced
def _TokenizeConditional(cls, text):
        TEXT_MODE = 0
        QUOTE_MODE = 1
        MACRO_MODE = 2
        token = ""
        mode = 0
        tokens = []
        for character in text:
            if character == "\"" and len(token) == 0:
                mode = QUOTE_MODE
            elif character == "\"" and mode == QUOTE_MODE:
                if len(token) > 0:
                    tokens.append(f"\"{token}\"")
                    token = ""
                mode = TEXT_MODE
            elif character == "$" and len(token) == 0:
                token += character
                mode = MACRO_MODE
            elif character == ')' and mode == MACRO_MODE:
                token += character
                tokens.append(token)
                token = ""
                mode = TEXT_MODE
            elif mode == TEXT_MODE and (character == "(" or character == ")"):
                if len(token) > 0:
                    tokens.append(token)
                    token = ""
                tokens.append(character)
            elif character == " " and (mode == TEXT_MODE or mode == MACRO_MODE):
                if len(token) > 0:
                    tokens.append(token)
                    token = ""
                    mode = TEXT_MODE
            else:
                token += character
        if len(token) > 0:
            tokens.append(token)
        for index in range(len(tokens)):
            token = tokens[index]
            token_upper = token.upper()
            if token_upper in cls.operators:
                token = token_upper
            elif token_upper == "||":
                token = "OR"
            elif token_upper == "&&":
                token = "AND"
            elif token_upper == "EQ":
                token = "=="
            elif token_upper == "NE":
                token = "!="
            elif token == "!":
                token = "NOT"
            tokens[index] = token
        collapsed_tokens = []
        found_not = False
        for token in tokens:
            if str(token).upper() == "NOT":
                found_not = True
                continue
            if not found_not:
                collapsed_tokens.append(token)
            elif token in cls.operators:
                collapsed_tokens.append("!+" + token)
                found_not = False
            else:  
                found_not = False
                collapsed_tokens.append("NOT")
                collapsed_tokens.append(token)
        return collapsed_tokens
def _TokenizeConditional ( cls , text ) : TEXT_MODE = 0 QUOTE_MODE = 1 MACRO_MODE = 2 token = "" mode = 0 tokens = [ ] for character in text : if character == "\"" and len ( token ) == 0 : mode = QUOTE_MODE elif character == "\"" and mode == QUOTE_MODE : if len ( token ) > 0 : tokens . append ( f"\"{token}\"" ) token = "" mode = TEXT_MODE elif character == "$" and len ( token ) == 0 : token += character mode = MACRO_MODE elif character == ')' and mode == MACRO_MODE : token += character tokens . append ( token ) token = "" mode = TEXT_MODE elif mode == TEXT_MODE and ( character == "(" or character == ")" ) : if len ( token ) > 0 : tokens . append ( token ) token = "" tokens . append ( character ) elif character == " " and ( mode == TEXT_MODE or mode == MACRO_MODE ) : if len ( token ) > 0 : tokens . append ( token ) token = "" mode = TEXT_MODE else : token += character if len ( token ) > 0 : tokens . append ( token ) for index in range ( len ( tokens ) ) : token = tokens [ index ] token_upper = token . upper ( ) if token_upper in cls . operators : token = token_upper elif token_upper == "||" : token = "OR" elif token_upper == "&&" : token = "AND" elif token_upper == "EQ" : token = "==" elif token_upper == "NE" : token = "!=" elif token == "!" : token = "NOT" tokens [ index ] = token collapsed_tokens = [ ] found_not = False for token in tokens : if str ( token ) . upper ( ) == "NOT" : found_not = True continue if not found_not : collapsed_tokens . append ( token ) elif token in cls . operators : collapsed_tokens . append ( "!+" + token ) found_not = False else : found_not = False collapsed_tokens . append ( "NOT" ) collapsed_tokens . append ( token ) return collapsed_tokens
takes in a string that has macros replaced
takes in a string that has macros replaced
''' takes in a string that has macros replaced ''' # TOKENIZER # first we create tokens # make sure to add in the last token just in case # then we do the lexer and convert operands as necessary # collapse the not # add the not back
cls
text