- 在argparse库中将所有null指针常量替换为nullptr - 更新头文件和源文件中的指针初始化和比较操作 - 修改测试文件中的相关断言检查 - 更新AST定义文件中的注释说明
55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
#ifndef __SCC_LEXER_UTILS_H__
|
|
#define __SCC_LEXER_UTILS_H__
|
|
|
|
#include "scc_lexer.h"
|
|
|
|
static inline void scc_lexer_gen_number_true(scc_lexer_tok_t *tok) {
|
|
Assert(tok != nullptr && tok->type == SCC_TOK_UNKNOWN);
|
|
tok->type = SCC_TOK_INT_LITERAL;
|
|
tok->lexeme = scc_str_from_cstr("1");
|
|
}
|
|
|
|
static inline void scc_lexer_gen_number_false(scc_lexer_tok_t *tok) {
|
|
Assert(tok != nullptr && tok->type == SCC_TOK_UNKNOWN);
|
|
tok->type = SCC_TOK_INT_LITERAL;
|
|
tok->lexeme = scc_str_from_cstr("0");
|
|
}
|
|
|
|
static inline cbool scc_lexer_peek_non_blank(scc_lexer_tok_ring_t *stream,
|
|
scc_lexer_tok_t *out) {
|
|
cbool ok;
|
|
while (1) {
|
|
scc_ring_peek(*stream, *out, ok);
|
|
if (!ok || out->type != SCC_TOK_BLANK)
|
|
break;
|
|
scc_ring_next_consume(*stream, *out, ok);
|
|
scc_lexer_tok_drop(out);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
static inline cbool scc_lexer_next_non_blank(scc_lexer_tok_ring_t *stream,
|
|
scc_lexer_tok_t *out) {
|
|
cbool ok;
|
|
if (!scc_lexer_peek_non_blank(stream, out))
|
|
return false;
|
|
scc_ring_next_consume(*stream, *out, ok);
|
|
return true;
|
|
}
|
|
|
|
static inline void scc_lexer_skip_until_newline(scc_lexer_tok_ring_t *stream) {
|
|
scc_lexer_tok_t tok;
|
|
cbool ok;
|
|
while (1) {
|
|
scc_ring_next_consume(*stream, tok, ok);
|
|
if (!ok)
|
|
break;
|
|
scc_tok_type_t type = tok.type;
|
|
scc_lexer_tok_drop(&tok);
|
|
if (type == SCC_TOK_ENDLINE)
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endif /* __SCC_LEXER_UTILS_H__ */
|