feat: rename core types to scc prefix for consistency
Updated type names from `core_*` to `scc_*` across lex_parser and stream modules to maintain naming consistency within the SCC codebase. This includes changes to function signatures and internal usage of types like `core_probe_stream_t`, `core_pos_t`, and `cstring_t` to their `scc_*` counterparts.
This commit is contained in:
@@ -11,16 +11,16 @@ static inline cbool lex_parse_is_whitespace(int ch) {
|
||||
return ch == ' ' || ch == '\t';
|
||||
}
|
||||
|
||||
int lex_parse_char(core_probe_stream_t *input, core_pos_t *pos);
|
||||
cbool lex_parse_string(core_probe_stream_t *input, core_pos_t *pos,
|
||||
cstring_t *output);
|
||||
cbool lex_parse_number(core_probe_stream_t *input, core_pos_t *pos,
|
||||
int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos);
|
||||
cbool lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos,
|
||||
scc_cstring_t *output);
|
||||
cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos,
|
||||
usize *output);
|
||||
cbool lex_parse_identifier(core_probe_stream_t *input, core_pos_t *pos,
|
||||
cstring_t *output);
|
||||
void lex_parse_skip_endline(core_probe_stream_t *input, core_pos_t *pos);
|
||||
void lex_parse_skip_block_comment(core_probe_stream_t *input, core_pos_t *pos);
|
||||
void lex_parse_skip_line(core_probe_stream_t *input, core_pos_t *pos);
|
||||
void lex_parse_skip_whitespace(core_probe_stream_t *input, core_pos_t *pos);
|
||||
cbool lex_parse_identifier(scc_probe_stream_t *input, scc_pos_t *pos,
|
||||
scc_cstring_t *output);
|
||||
void lex_parse_skip_endline(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 lex_parse_skip_line(scc_probe_stream_t *input, scc_pos_t *pos);
|
||||
void lex_parse_skip_whitespace(scc_probe_stream_t *input, scc_pos_t *pos);
|
||||
|
||||
#endif /* __SMCC_LEX_PARSER_H__ */
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include <lex_parser.h>
|
||||
|
||||
void lex_parse_skip_endline(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
void lex_parse_skip_endline(scc_probe_stream_t *input, scc_pos_t *pos) {
|
||||
Assert(input != null && pos != null);
|
||||
core_probe_stream_reset(input);
|
||||
int ch = core_probe_stream_peek(input);
|
||||
scc_probe_stream_reset(input);
|
||||
int ch = scc_probe_stream_peek(input);
|
||||
if (ch == '\r') {
|
||||
core_probe_stream_consume(input);
|
||||
ch = core_probe_stream_peek(input);
|
||||
scc_probe_stream_consume(input);
|
||||
ch = scc_probe_stream_peek(input);
|
||||
if (ch == '\n') {
|
||||
core_probe_stream_consume(input);
|
||||
scc_probe_stream_consume(input);
|
||||
}
|
||||
core_pos_next_line(pos);
|
||||
} else if (ch == '\n') {
|
||||
core_probe_stream_consume(input);
|
||||
scc_probe_stream_consume(input);
|
||||
core_pos_next_line(pos);
|
||||
} else {
|
||||
LOG_WARN("not a newline character");
|
||||
@@ -57,12 +57,12 @@ static inline int got_simple_escape(int ch) {
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
void lex_parse_skip_line(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
core_probe_stream_t *stream = input;
|
||||
void lex_parse_skip_line(scc_probe_stream_t *input, scc_pos_t *pos) {
|
||||
scc_probe_stream_t *stream = input;
|
||||
Assert(stream != null && pos != null);
|
||||
core_probe_stream_reset(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
while (1) {
|
||||
int ch = core_probe_stream_peek(stream);
|
||||
int ch = scc_probe_stream_peek(stream);
|
||||
|
||||
if (ch == core_stream_eof) {
|
||||
return;
|
||||
@@ -73,29 +73,29 @@ void lex_parse_skip_line(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
lex_parse_skip_endline(stream, pos);
|
||||
return;
|
||||
} else {
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lex_parse_skip_block_comment(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
core_probe_stream_t *stream = input;
|
||||
void 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;
|
||||
core_probe_stream_reset(stream);
|
||||
ch = core_probe_stream_consume(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
ch = scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
// FIXME Assertion
|
||||
Assert(ch == '/');
|
||||
ch = core_probe_stream_consume(stream);
|
||||
ch = scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
Assert(ch == '*');
|
||||
|
||||
// all ready match `/*`
|
||||
while (1) {
|
||||
core_probe_stream_reset(stream);
|
||||
ch = core_probe_stream_peek(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
ch = scc_probe_stream_peek(stream);
|
||||
|
||||
if (ch == core_stream_eof) {
|
||||
LOG_WARN("Unterminated block comment");
|
||||
@@ -106,12 +106,12 @@ void lex_parse_skip_block_comment(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
lex_parse_skip_endline(stream, pos);
|
||||
continue;
|
||||
}
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
if (ch == '*') {
|
||||
ch = core_probe_stream_peek(stream);
|
||||
ch = scc_probe_stream_peek(stream);
|
||||
if (ch == '/') {
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
return;
|
||||
}
|
||||
@@ -119,35 +119,35 @@ void lex_parse_skip_block_comment(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
}
|
||||
}
|
||||
|
||||
void lex_parse_skip_whitespace(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
core_probe_stream_t *stream = input;
|
||||
void lex_parse_skip_whitespace(scc_probe_stream_t *input, scc_pos_t *pos) {
|
||||
scc_probe_stream_t *stream = input;
|
||||
Assert(stream != null && pos != null);
|
||||
core_probe_stream_reset(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
while (1) {
|
||||
int ch = core_probe_stream_peek(stream);
|
||||
int ch = scc_probe_stream_peek(stream);
|
||||
|
||||
if (!lex_parse_is_whitespace(ch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
}
|
||||
}
|
||||
|
||||
static inline cbool _lex_parse_uint(core_probe_stream_t *input, core_pos_t *pos,
|
||||
static inline cbool _lex_parse_uint(scc_probe_stream_t *input, scc_pos_t *pos,
|
||||
int base, usize *output) {
|
||||
Assert(input != null && pos != null);
|
||||
if (input == null || pos == null) {
|
||||
return false;
|
||||
}
|
||||
Assert(base == 2 || base == 8 || base == 10 || base == 16);
|
||||
core_probe_stream_reset(input);
|
||||
scc_probe_stream_reset(input);
|
||||
int ch, tmp;
|
||||
usize n = 0;
|
||||
usize offset = pos->offset;
|
||||
while (1) {
|
||||
ch = core_probe_stream_peek(input);
|
||||
ch = scc_probe_stream_peek(input);
|
||||
|
||||
if (ch == core_stream_eof) {
|
||||
break;
|
||||
@@ -166,7 +166,7 @@ static inline cbool _lex_parse_uint(core_probe_stream_t *input, core_pos_t *pos,
|
||||
return false;
|
||||
}
|
||||
|
||||
core_probe_stream_consume(input);
|
||||
scc_probe_stream_consume(input);
|
||||
core_pos_next(pos);
|
||||
n = n * base + tmp;
|
||||
// TODO number overflow
|
||||
@@ -187,11 +187,11 @@ static inline cbool _lex_parse_uint(core_probe_stream_t *input, core_pos_t *pos,
|
||||
* @return int
|
||||
* https://cppreference.cn/w/c/language/character_constant
|
||||
*/
|
||||
int lex_parse_char(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
core_probe_stream_t *stream = input;
|
||||
int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) {
|
||||
scc_probe_stream_t *stream = input;
|
||||
Assert(stream != null && pos != null);
|
||||
core_probe_stream_reset(stream);
|
||||
int ch = core_probe_stream_peek(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
int ch = scc_probe_stream_peek(stream);
|
||||
int ret = core_stream_eof;
|
||||
|
||||
if (ch == core_stream_eof) {
|
||||
@@ -201,17 +201,17 @@ int lex_parse_char(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
LOG_WARN("Unexpected character '%c' at begin", ch);
|
||||
goto ERR;
|
||||
}
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
|
||||
ch = core_probe_stream_consume(stream);
|
||||
ch = scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
|
||||
if (ch == core_stream_eof) {
|
||||
LOG_WARN("Unexpected EOF at middle");
|
||||
goto ERR;
|
||||
} else if (ch == '\\') {
|
||||
ch = core_probe_stream_consume(stream);
|
||||
ch = scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
if (ch == '0') {
|
||||
// 数字转义序列
|
||||
@@ -237,7 +237,7 @@ int lex_parse_char(core_probe_stream_t *input, core_pos_t *pos) {
|
||||
} else {
|
||||
ret = ch;
|
||||
}
|
||||
if ((ch = core_probe_stream_consume(stream)) != '\'') {
|
||||
if ((ch = scc_probe_stream_consume(stream)) != '\'') {
|
||||
LOG_ERROR("Unclosed character literal '%c' at end, expect `'`", ch);
|
||||
core_pos_next(pos);
|
||||
goto ERR;
|
||||
@@ -257,14 +257,14 @@ ERR:
|
||||
* @return cbool
|
||||
* https://cppreference.cn/w/c/language/string_literal
|
||||
*/
|
||||
cbool lex_parse_string(core_probe_stream_t *input, core_pos_t *pos,
|
||||
cstring_t *output) {
|
||||
core_probe_stream_t *stream = input;
|
||||
cbool 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);
|
||||
core_probe_stream_reset(stream);
|
||||
int ch = core_probe_stream_peek(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
int ch = scc_probe_stream_peek(stream);
|
||||
|
||||
Assert(cstring_is_empty(output));
|
||||
Assert(scc_cstring_is_empty(output));
|
||||
if (ch == core_stream_eof) {
|
||||
LOG_WARN("Unexpected EOF at begin");
|
||||
goto ERR;
|
||||
@@ -272,12 +272,12 @@ cbool lex_parse_string(core_probe_stream_t *input, core_pos_t *pos,
|
||||
LOG_WARN("Unexpected character '%c' at begin", ch);
|
||||
goto ERR;
|
||||
}
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
|
||||
cstring_t str = cstring_from_cstr("");
|
||||
scc_cstring_t str = scc_cstring_from_cstr("");
|
||||
while (1) {
|
||||
ch = core_probe_stream_peek(stream);
|
||||
ch = scc_probe_stream_peek(stream);
|
||||
|
||||
if (ch == core_stream_eof) {
|
||||
LOG_ERROR("Unexpected EOF at string literal");
|
||||
@@ -287,30 +287,30 @@ cbool lex_parse_string(core_probe_stream_t *input, core_pos_t *pos,
|
||||
goto ERR;
|
||||
} else if (ch == '\\') {
|
||||
// TODO bad practice and maybe bugs here
|
||||
core_probe_stream_consume(stream);
|
||||
ch = core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
ch = scc_probe_stream_consume(stream);
|
||||
int val = got_simple_escape(ch);
|
||||
if (val == -1) {
|
||||
LOG_ERROR("Invalid escape character it is \\%c [%d]", ch, ch);
|
||||
} else {
|
||||
cstring_append_ch(&str, val);
|
||||
scc_cstring_append_ch(&str, val);
|
||||
continue;
|
||||
}
|
||||
} else if (ch == '"') {
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
break;
|
||||
}
|
||||
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
cstring_append_ch(&str, ch);
|
||||
scc_cstring_append_ch(&str, ch);
|
||||
}
|
||||
|
||||
*output = str;
|
||||
return true;
|
||||
ERR:
|
||||
cstring_free(&str);
|
||||
scc_cstring_free(&str);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -323,12 +323,12 @@ ERR:
|
||||
* @return cbool
|
||||
* https://cppreference.cn/w/c/language/integer_constant
|
||||
*/
|
||||
cbool lex_parse_number(core_probe_stream_t *input, core_pos_t *pos,
|
||||
cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos,
|
||||
usize *output) {
|
||||
core_probe_stream_t *stream = input;
|
||||
scc_probe_stream_t *stream = input;
|
||||
Assert(stream != null && pos != null && output != null);
|
||||
core_probe_stream_reset(stream);
|
||||
int ch = core_probe_stream_peek(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
int ch = scc_probe_stream_peek(stream);
|
||||
int base = 10; // 默认十进制
|
||||
|
||||
if (ch == core_stream_eof) {
|
||||
@@ -338,20 +338,20 @@ cbool lex_parse_number(core_probe_stream_t *input, core_pos_t *pos,
|
||||
|
||||
if (ch == '0') {
|
||||
// 消费 '0'
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
|
||||
// 查看下一个字符
|
||||
ch = core_probe_stream_peek(stream);
|
||||
ch = scc_probe_stream_peek(stream);
|
||||
if (ch == 'x' || ch == 'X') {
|
||||
// 十六进制
|
||||
base = 16;
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
} else if (ch == 'b' || ch == 'B') {
|
||||
// 二进制 (C23扩展)
|
||||
base = 2;
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
} else if (ch >= '0' && ch <= '7') {
|
||||
// 八进制
|
||||
@@ -374,7 +374,7 @@ cbool lex_parse_number(core_probe_stream_t *input, core_pos_t *pos,
|
||||
}
|
||||
|
||||
// 解析整数部分
|
||||
core_probe_stream_reset(stream);
|
||||
scc_probe_stream_reset(stream);
|
||||
usize n;
|
||||
if (_lex_parse_uint(stream, pos, base, &n) == false) {
|
||||
// 如果没有匹配任何数字,但输入是 '0',已经处理过了
|
||||
@@ -383,7 +383,7 @@ cbool lex_parse_number(core_probe_stream_t *input, core_pos_t *pos,
|
||||
// 单个数字的情况,例如 "1"
|
||||
// 我们需要消费这个数字并返回它的值
|
||||
if (ch >= '1' && ch <= '9') {
|
||||
core_probe_stream_consume(stream);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
*output = ch - '0';
|
||||
return true;
|
||||
@@ -406,23 +406,23 @@ ERR:
|
||||
* @return cbool
|
||||
* https://cppreference.cn/w/c/language/identifier
|
||||
*/
|
||||
cbool lex_parse_identifier(core_probe_stream_t *input, core_pos_t *pos,
|
||||
cstring_t *output) {
|
||||
cbool lex_parse_identifier(scc_probe_stream_t *input, scc_pos_t *pos,
|
||||
scc_cstring_t *output) {
|
||||
Assert(input != null && pos != null && output != null);
|
||||
Assert(cstring_is_empty(output));
|
||||
core_probe_stream_t *stream = input;
|
||||
core_probe_stream_reset(stream);
|
||||
int ch = core_probe_stream_peek(stream);
|
||||
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) {
|
||||
LOG_WARN("Unexpected EOF at begin");
|
||||
} else if (ch == '_' || (ch >= 'a' && ch <= 'z') ||
|
||||
(ch >= 'A' && ch <= 'Z')) {
|
||||
while (1) {
|
||||
cstring_append_ch(output, ch);
|
||||
core_probe_stream_consume(stream);
|
||||
scc_cstring_append_ch(output, ch);
|
||||
scc_probe_stream_consume(stream);
|
||||
core_pos_next(pos);
|
||||
ch = core_probe_stream_peek(stream);
|
||||
ch = scc_probe_stream_peek(stream);
|
||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
|
||||
(ch == '_') || (ch >= '0' && ch <= '9')) {
|
||||
continue;
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
cbool check_char(const char *str, int expect, int *output) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
core_pos_t pos = core_pos_init();
|
||||
core_mem_probe_stream_t mem_stream;
|
||||
core_probe_stream_t *stream =
|
||||
core_mem_probe_stream_init(&mem_stream, str, smcc_strlen(str), false);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
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 = lex_parse_char(stream, &pos);
|
||||
return *output == expect;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
#include <lex_parser.h>
|
||||
#include <utest/acutest.h>
|
||||
|
||||
cbool check_identifier(const char *str, const char *expect, cstring_t *output) {
|
||||
cbool check_identifier(const char *str, const char *expect,
|
||||
scc_cstring_t *output) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
core_pos_t pos = core_pos_init();
|
||||
core_mem_probe_stream_t mem_stream;
|
||||
core_probe_stream_t *stream =
|
||||
core_mem_probe_stream_init(&mem_stream, str, smcc_strlen(str), false);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
|
||||
cbool ret = lex_parse_identifier(stream, &pos, output);
|
||||
if (ret && expect) {
|
||||
@@ -18,19 +19,19 @@ cbool check_identifier(const char *str, const char *expect, cstring_t *output) {
|
||||
|
||||
#define CHECK_IDENTIFIER_VALID(str, expect) \
|
||||
do { \
|
||||
cstring_t _output = cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
cbool ret = check_identifier(str, expect, &_output); \
|
||||
TEST_CHECK(ret == true); \
|
||||
TEST_CHECK(strcmp(_output.data, expect) == 0); \
|
||||
cstring_free(&_output); \
|
||||
scc_cstring_free(&_output); \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_IDENTIFIER_INVALID(str) \
|
||||
do { \
|
||||
cstring_t _output = cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
cbool ret = check_identifier(str, NULL, &_output); \
|
||||
TEST_CHECK(ret == false); \
|
||||
cstring_free(&_output); \
|
||||
scc_cstring_free(&_output); \
|
||||
} while (0)
|
||||
|
||||
void test_valid_identifier(void) {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#include <lex_parser.h>
|
||||
#include <utest/acutest.h>
|
||||
|
||||
cbool check(const char *str, usize expect, usize *output) {
|
||||
// TODO maybe have other logger
|
||||
(void)(expect);
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
core_pos_t pos = core_pos_init();
|
||||
core_mem_probe_stream_t mem_stream;
|
||||
core_probe_stream_t *stream =
|
||||
core_mem_probe_stream_init(&mem_stream, str, smcc_strlen(str), false);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
return lex_parse_number(stream, &pos, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
void check_skip_block_comment(const char *str, const char *expect_remaining) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
core_pos_t pos = core_pos_init();
|
||||
core_mem_probe_stream_t mem_stream;
|
||||
core_probe_stream_t *stream =
|
||||
core_mem_probe_stream_init(&mem_stream, str, smcc_strlen(str), false);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
|
||||
lex_parse_skip_block_comment(stream, &pos);
|
||||
|
||||
@@ -15,7 +15,7 @@ void check_skip_block_comment(const char *str, const char *expect_remaining) {
|
||||
char buffer[256] = {0};
|
||||
int i = 0;
|
||||
int ch;
|
||||
while ((ch = core_probe_stream_consume(stream)) != core_stream_eof &&
|
||||
while ((ch = scc_probe_stream_consume(stream)) != core_stream_eof &&
|
||||
i < 255) {
|
||||
buffer[i++] = (char)ch;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
void check_skip_line(const char *str, const char *expect_remaining) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
core_pos_t pos = core_pos_init();
|
||||
core_mem_probe_stream_t mem_stream;
|
||||
core_probe_stream_t *stream =
|
||||
core_mem_probe_stream_init(&mem_stream, str, smcc_strlen(str), false);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
|
||||
lex_parse_skip_line(stream, &pos);
|
||||
|
||||
@@ -15,7 +15,7 @@ void check_skip_line(const char *str, const char *expect_remaining) {
|
||||
char buffer[256] = {0};
|
||||
int i = 0;
|
||||
int ch;
|
||||
while ((ch = core_probe_stream_consume(stream)) != core_stream_eof &&
|
||||
while ((ch = scc_probe_stream_consume(stream)) != core_stream_eof &&
|
||||
i < 255) {
|
||||
buffer[i++] = (char)ch;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
#include <lex_parser.h>
|
||||
#include <utest/acutest.h>
|
||||
|
||||
cbool check_string(const char *str, const char *expect, cstring_t *output) {
|
||||
cbool check_string(const char *str, const char *expect, scc_cstring_t *output) {
|
||||
log_set_level(&__default_logger_root, 0);
|
||||
core_pos_t pos = core_pos_init();
|
||||
core_mem_probe_stream_t mem_stream;
|
||||
core_probe_stream_t *stream =
|
||||
core_mem_probe_stream_init(&mem_stream, str, smcc_strlen(str), false);
|
||||
scc_pos_t pos = scc_pos_init();
|
||||
scc_mem_probe_stream_t mem_stream;
|
||||
scc_probe_stream_t *stream =
|
||||
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
||||
|
||||
cbool ret = lex_parse_string(stream, &pos, output);
|
||||
if (ret && expect) {
|
||||
@@ -18,19 +18,19 @@ cbool check_string(const char *str, const char *expect, cstring_t *output) {
|
||||
|
||||
#define CHECK_STRING_VALID(str, expect) \
|
||||
do { \
|
||||
cstring_t _output = cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
cbool ret = check_string(str, expect, &_output); \
|
||||
TEST_CHECK(ret == true); \
|
||||
TEST_CHECK(strcmp(_output.data, expect) == 0); \
|
||||
cstring_free(&_output); \
|
||||
scc_cstring_free(&_output); \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_STRING_INVALID(str) \
|
||||
do { \
|
||||
cstring_t _output = cstring_new(); \
|
||||
scc_cstring_t _output = scc_cstring_new(); \
|
||||
cbool ret = check_string(str, NULL, &_output); \
|
||||
TEST_CHECK(ret == false); \
|
||||
cstring_free(&_output); \
|
||||
scc_cstring_free(&_output); \
|
||||
} while (0)
|
||||
|
||||
void test_simple_string(void) {
|
||||
|
||||
Reference in New Issue
Block a user