def UNDEF(token_seq, macros): line = get_line(token_seq) macro_name = consume(line) and error_if_not_type( consume(line, EOFLocation), (IDENTIFIER, KEYWORD)) _ = macro_name in macros and macros.pop(macro_name) _ = error_if_not_empty(line) yield IGNORE(location=loc(macro_name))
def INCLUDE(token_seq, macros): line = get_line(token_seq) file_path = consume(line) and get_rule(INCLUDE, peek_or_terminal(line), hash_funcs=(type, identity))(line, macros) search_paths = (os.getcwd(),) _ = error_if_not_empty(line) return chain( macros['__ preprocess __']( tokenize(load(file_path, chain(macros['__ include_dirs __'], search_paths))), macros ), )
def INCLUDE(token_seq, macros): line = get_line(token_seq) file_path = consume(line) and get_rule( INCLUDE, peek_or_terminal(line), hash_funcs=(type, identity))(line, macros) search_paths = (os.getcwd(), ) _ = error_if_not_empty(line) return chain( macros['__ preprocess __'](tokenize( load(file_path, chain(macros['__ include_dirs __'], search_paths))), macros), )
def DEFINE(token_seq, macros): line = get_line(token_seq) define_token = consume(line) name = consume(line) value = consume(line, default=IGNORE()) if value == TOKENS.LEFT_PARENTHESIS and column_number(name) + len(name) == column_number(value): macro = _func_macro_definition(name, line) else: # object macro macro = ObjectMacro(name, tuple(filter_out_empty_tokens(chain((value,), line)))) _ = name in macros and macros.pop(name) and logger.warning('{0} Redefining macro {1}'.format(loc(name), name)) macros[name] = macro yield IGNORE(location=loc(define_token))
def DEFINE(token_seq, macros): line = get_line(token_seq) define_token = consume(line) name = consume(line) value = consume(line, default=IGNORE()) if value == TOKENS.LEFT_PARENTHESIS and column_number(name) + len( name) == column_number(value): macro = _func_macro_definition(name, line) else: # object macro macro = ObjectMacro( name, tuple(filter_out_empty_tokens(chain((value, ), line)))) _ = name in macros and macros.pop(name) and logger.warning( '{0} Redefining macro {1}'.format(loc(name), name)) macros[name] = macro yield IGNORE(location=loc(define_token))
def nested_block(token_seq): for token in chain(get_line(token_seq), get_block(token_seq)): # get the entire block ... yield token yield error_if_not_value(token_seq, TOKENS.PENDIF)
def ERROR(token_seq, *_): t = peek(token_seq) raise_error('{l} error: {m}'.format(l=loc(t), m=' '.join(get_line(token_seq))))
def WARNING(token_seq, *_): t = peek(token_seq) logger.warning('{l} warning: {m}'.format(l=loc(t), m=' '.join(get_line(token_seq)))) yield IGNORE(location=loc(t))
def UNDEF(token_seq, macros): line = get_line(token_seq) macro_name = consume(line) and error_if_not_type(consume(line, EOFLocation), (IDENTIFIER, KEYWORD)) _ = macro_name in macros and macros.pop(macro_name) _ = error_if_not_empty(line) yield IGNORE(location=loc(macro_name))
def _else_block(token_seq, _): line = get_line(token_seq) _ = consume(line) and error_if_not_empty(line) return get_block(token_seq)
def _if_not_def_block(token_seq, macros): arguments = get_line(token_seq) argument = consume(arguments) and error_if_not_type(consume(arguments), (IDENTIFIER, KEYWORD)) _ = error_if_not_empty(arguments) return __calc_if(argument not in macros, token_seq, macros)
def _if_block(token_seq, macros): arguments = get_line(token_seq) return __calc_if(consume(arguments) and evaluate_expression(arguments, macros), token_seq, macros)
def _if_not_def_block(token_seq, macros): arguments = get_line(token_seq) argument = consume(arguments) and error_if_not_type( consume(arguments), (IDENTIFIER, KEYWORD)) _ = error_if_not_empty(arguments) return __calc_if(argument not in macros, token_seq, macros)
def _if_block(token_seq, macros): arguments = get_line(token_seq) return __calc_if( consume(arguments) and evaluate_expression(arguments, macros), token_seq, macros)