feat(lex_parser): rename functions and update header guard prefix

- Change header guard from `__SMCC_LEX_PARSER_H__` to `__SCC_LEX_PARSER_H__`
- Prefix all lexer functions with `scc_` (e.g., `lex_parse_char` → `scc_lex_parse_char`)
- Add new helper function `scc_lex_parse_is_identifier_header`
- Update references in source and test files to use new function names
- Replace `core_stream_eof` with `scc_stream_eof` for consistency
This commit is contained in:
zzy
2025-12-13 14:06:13 +08:00
parent 94d3f46fac
commit 874a58281f
17 changed files with 98 additions and 92 deletions

View File

@@ -1,6 +1,6 @@
#include <lex_parser.h>
void lex_parse_skip_endline(scc_probe_stream_t *input, scc_pos_t *pos) {
void scc_lex_parse_skip_endline(scc_probe_stream_t *input, scc_pos_t *pos) {
Assert(input != null && pos != null);
scc_probe_stream_reset(input);
int ch = scc_probe_stream_peek(input);
@@ -57,20 +57,20 @@ static inline int got_simple_escape(int ch) {
/* clang-format on */
}
void lex_parse_skip_line(scc_probe_stream_t *input, scc_pos_t *pos) {
void scc_lex_parse_skip_line(scc_probe_stream_t *input, scc_pos_t *pos) {
scc_probe_stream_t *stream = input;
Assert(stream != null && pos != null);
scc_probe_stream_reset(stream);
while (1) {
int ch = scc_probe_stream_peek(stream);
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
return;
}
// TODO endline
if (lex_parse_is_endline(ch)) {
lex_parse_skip_endline(stream, pos);
if (scc_lex_parse_is_endline(ch)) {
scc_lex_parse_skip_endline(stream, pos);
return;
} else {
scc_probe_stream_consume(stream);
@@ -79,7 +79,8 @@ void lex_parse_skip_line(scc_probe_stream_t *input, scc_pos_t *pos) {
}
}
void lex_parse_skip_block_comment(scc_probe_stream_t *input, scc_pos_t *pos) {
void scc_lex_parse_skip_block_comment(scc_probe_stream_t *input,
scc_pos_t *pos) {
scc_probe_stream_t *stream = input;
Assert(stream != null && pos != null);
int ch;
@@ -97,13 +98,13 @@ void lex_parse_skip_block_comment(scc_probe_stream_t *input, scc_pos_t *pos) {
scc_probe_stream_reset(stream);
ch = scc_probe_stream_peek(stream);
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
LOG_WARN("Unterminated block comment");
return;
}
if (lex_parse_is_endline(ch)) {
lex_parse_skip_endline(stream, pos);
if (scc_lex_parse_is_endline(ch)) {
scc_lex_parse_skip_endline(stream, pos);
continue;
}
scc_probe_stream_consume(stream);
@@ -119,14 +120,14 @@ void lex_parse_skip_block_comment(scc_probe_stream_t *input, scc_pos_t *pos) {
}
}
void lex_parse_skip_whitespace(scc_probe_stream_t *input, scc_pos_t *pos) {
void scc_lex_parse_skip_whitespace(scc_probe_stream_t *input, scc_pos_t *pos) {
scc_probe_stream_t *stream = input;
Assert(stream != null && pos != null);
scc_probe_stream_reset(stream);
while (1) {
int ch = scc_probe_stream_peek(stream);
if (!lex_parse_is_whitespace(ch)) {
if (!scc_lex_parse_is_whitespace(ch)) {
return;
}
@@ -149,7 +150,7 @@ static inline cbool _lex_parse_uint(scc_probe_stream_t *input, scc_pos_t *pos,
while (1) {
ch = scc_probe_stream_peek(input);
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
break;
} else if (ch >= 'a' && ch <= 'z') {
tmp = ch - 'a' + 10;
@@ -187,14 +188,14 @@ static inline cbool _lex_parse_uint(scc_probe_stream_t *input, scc_pos_t *pos,
* @return int
* https://cppreference.cn/w/c/language/character_constant
*/
int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) {
int scc_lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) {
scc_probe_stream_t *stream = input;
Assert(stream != null && pos != null);
scc_probe_stream_reset(stream);
int ch = scc_probe_stream_peek(stream);
int ret = core_stream_eof;
int ret = scc_stream_eof;
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
LOG_WARN("Unexpected EOF at begin");
goto ERR;
} else if (ch != '\'') {
@@ -207,7 +208,7 @@ int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) {
ch = scc_probe_stream_consume(stream);
scc_pos_next(pos);
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
LOG_WARN("Unexpected EOF at middle");
goto ERR;
} else if (ch == '\\') {
@@ -245,7 +246,7 @@ int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) {
return ret;
ERR:
return core_stream_eof;
return scc_stream_eof;
}
/**
@@ -257,15 +258,15 @@ ERR:
* @return cbool
* https://cppreference.cn/w/c/language/string_literal
*/
cbool lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos,
scc_cstring_t *output) {
cbool scc_lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos,
scc_cstring_t *output) {
scc_probe_stream_t *stream = input;
Assert(stream != null && pos != null && output != null);
scc_probe_stream_reset(stream);
int ch = scc_probe_stream_peek(stream);
Assert(scc_cstring_is_empty(output));
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
LOG_WARN("Unexpected EOF at begin");
goto ERR;
} else if (ch != '"') {
@@ -279,10 +280,10 @@ cbool lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos,
while (1) {
ch = scc_probe_stream_peek(stream);
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
LOG_ERROR("Unexpected EOF at string literal");
goto ERR;
} else if (lex_parse_is_endline(ch)) {
} else if (scc_lex_parse_is_endline(ch)) {
LOG_ERROR("Unexpected newline at string literal");
goto ERR;
} else if (ch == '\\') {
@@ -323,15 +324,15 @@ ERR:
* @return cbool
* https://cppreference.cn/w/c/language/integer_constant
*/
cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos,
usize *output) {
cbool scc_lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos,
usize *output) {
scc_probe_stream_t *stream = input;
Assert(stream != null && pos != null && output != null);
scc_probe_stream_reset(stream);
int ch = scc_probe_stream_peek(stream);
int base = 10; // 默认十进制
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
LOG_WARN("Unexpected EOF at begin");
goto ERR;
}
@@ -406,15 +407,15 @@ ERR:
* @return cbool
* https://cppreference.cn/w/c/language/identifier
*/
cbool lex_parse_identifier(scc_probe_stream_t *input, scc_pos_t *pos,
scc_cstring_t *output) {
cbool scc_lex_parse_identifier(scc_probe_stream_t *input, scc_pos_t *pos,
scc_cstring_t *output) {
Assert(input != null && pos != null && output != null);
Assert(scc_cstring_is_empty(output));
scc_probe_stream_t *stream = input;
scc_probe_stream_reset(stream);
int ch = scc_probe_stream_peek(stream);
if (ch == core_stream_eof) {
if (ch == scc_stream_eof) {
LOG_WARN("Unexpected EOF at begin");
} else if (ch == '_' || (ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z')) {