Example #1
0
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))
Example #2
0
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
        ),
    )
Example #3
0
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), )
Example #4
0
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))
Example #5
0
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))
Example #6
0
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)
Example #7
0
def ERROR(token_seq, *_):
    t = peek(token_seq)
    raise_error('{l} error: {m}'.format(l=loc(t),
                                        m=' '.join(get_line(token_seq))))
Example #8
0
def ERROR(token_seq, *_):
    t = peek(token_seq)
    raise_error('{l} error: {m}'.format(l=loc(t), m=' '.join(get_line(token_seq))))
Example #9
0
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))
Example #10
0
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))
Example #11
0
def _else_block(token_seq, _):
    line = get_line(token_seq)
    _ = consume(line) and error_if_not_empty(line)
    return get_block(token_seq)
Example #12
0
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)
Example #13
0
def _if_block(token_seq, macros):
    arguments = get_line(token_seq)
    return __calc_if(consume(arguments) and evaluate_expression(arguments, macros), token_seq, macros)
Example #14
0
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))
Example #15
0
def _else_block(token_seq, _):
    line = get_line(token_seq)
    _ = consume(line) and error_if_not_empty(line)
    return get_block(token_seq)
Example #16
0
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)
Example #17
0
def _if_block(token_seq, macros):
    arguments = get_line(token_seq)
    return __calc_if(
        consume(arguments) and evaluate_expression(arguments, macros),
        token_seq, macros)
Example #18
0
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)