feat(lex_parser, pprocessor): replace consume with next and remove stream resets
- Replace `scc_probe_stream_consume` with `scc_probe_stream_next` for consistent stream advancement - Remove redundant `scc_probe_stream_reset` calls before peeking, as `next` and `peek` handle state - Update `scc_cstring_new` to `scc_cstring_create` and `scc_pos_init` to `scc_pos_create` for naming consistency - Change `scc_pp_macro_get` parameter to `const scc_cstring_t*` for better const-correctness - Improves code clarity and maintains proper stream position tracking
This commit is contained in:
@@ -4,12 +4,16 @@
|
||||
|
||||
cbool check_char(const char *str, int expect, int *output) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_pos_t pos = scc_pos_create();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
*output = scc_lex_parse_char(stream, &pos);
|
||||
return *output == expect;
|
||||
cbool ret1 = *output == expect;
|
||||
scc_probe_stream_reset(stream);
|
||||
*output = scc_lex_parse_char(stream, &pos);
|
||||
cbool ret2 = *output == expect;
|
||||
return ret1 && ret2;
|
||||
}
|
||||
|
||||
#define CHECK_CHAR_VALID(str, expect) \
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
cbool check_identifier(const char *str, const char *expect,
|
||||
scc_cstring_t *output) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_pos_t pos = scc_pos_create();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
@@ -19,7 +19,7 @@ cbool check_identifier(const char *str, const char *expect,
|
||||
|
||||
#define CHECK_IDENTIFIER_VALID(str, expect) \
|
||||
do { \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_create(); \
|
||||
cbool ret = check_identifier(str, expect, &_output); \
|
||||
TEST_CHECK(ret == true); \
|
||||
TEST_CHECK(strcmp(_output.data, expect) == 0); \
|
||||
@@ -28,7 +28,7 @@ cbool check_identifier(const char *str, const char *expect,
|
||||
|
||||
#define CHECK_IDENTIFIER_INVALID(str) \
|
||||
do { \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_create(); \
|
||||
cbool ret = check_identifier(str, NULL, &_output); \
|
||||
TEST_CHECK(ret == false); \
|
||||
scc_cstring_free(&_output); \
|
||||
|
||||
@@ -5,7 +5,7 @@ cbool check(const char *str, usize expect, usize *output) {
|
||||
// TODO maybe have other logger
|
||||
(void)(expect);
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_pos_t pos = scc_pos_create();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
|
||||
void check_skip_block_comment(const char *str, const char *expect_remaining) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_pos_t pos = scc_pos_create();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
|
||||
scc_lex_parse_skip_block_comment(stream, &pos);
|
||||
scc_probe_stream_sync(stream);
|
||||
|
||||
// Check remaining content
|
||||
char buffer[256] = {0};
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
|
||||
void check_skip_line(const char *str, const char *expect_remaining) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_pos_t pos = scc_pos_create();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
|
||||
scc_lex_parse_skip_line(stream, &pos);
|
||||
scc_probe_stream_sync(stream);
|
||||
|
||||
// Check remaining content
|
||||
char buffer[256] = {0};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
cbool check_string(const char *str, const char *expect, scc_cstring_t *output) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_pos_t pos = scc_pos_create();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
@@ -18,7 +18,7 @@ cbool check_string(const char *str, const char *expect, scc_cstring_t *output) {
|
||||
|
||||
#define CHECK_STRING_VALID(str, expect) \
|
||||
do { \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_create(); \
|
||||
cbool ret = check_string(str, expect, &_output); \
|
||||
TEST_CHECK(ret == true); \
|
||||
TEST_CHECK(strcmp(_output.data, expect) == 0); \
|
||||
@@ -27,7 +27,7 @@ cbool check_string(const char *str, const char *expect, scc_cstring_t *output) {
|
||||
|
||||
#define CHECK_STRING_INVALID(str) \
|
||||
do { \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_create(); \
|
||||
cbool ret = check_string(str, NULL, &_output); \
|
||||
TEST_CHECK(ret == false); \
|
||||
scc_cstring_free(&_output); \
|
||||
|
||||
Reference in New Issue
Block a user