feat(lex_parser, pprocessor): rename identifier header check and add macro system

- Rename `scc_lex_parse_is_identifier_header` to `scc_lex_parse_is_identifier_prefix` for clarity and add a TODO comment
- Update lexer to use the renamed function for consistency
- Fix package and dependency names in `cbuild.toml` (`smcc_pprocesser` → `scc_pprocesser`, `smcc_lex_parser` → `lex_parser`)
- Introduce new macro system with header file `pp_macro.h` defining macro types, structures, and management functions
- Refactor preprocessor initialization and cleanup in `pprocessor.c` to use new macro table and stream handling
- Replace legacy `hashmap` with `scc_pp_macro_table_t` for macro storage
- Improve error handling and resource management in preprocessor lifecycle
This commit is contained in:
zzy
2025-12-13 16:09:46 +08:00
parent 874a58281f
commit 07a76d82f4
16 changed files with 970 additions and 490 deletions

View File

@@ -1,30 +1,30 @@
#ifndef __SMCC_PP_TOKEN_H__
#define __SMCC_PP_TOKEN_H__
#ifndef __SCC_PP_TOKEN_H__
#define __SCC_PP_TOKEN_H__
/* clang-format off */
/// https://cppreference.cn/w/c/preprocessor
#define PP_INST_TOKEN \
X(define , PP_STD, PP_TOK_DEFINE ) \
X(undef , PP_STD, PP_TOK_UNDEF ) \
X(include , PP_STD, PP_TOK_INCLUDE ) \
X(if , PP_STD, PP_TOK_IF ) \
X(ifdef , PP_STD, PP_TOK_IFDEF ) \
X(ifndef , PP_STD, PP_TOK_IFNDEF ) \
X(else , PP_STD, PP_TOK_ELSE ) \
X(elif , PP_STD, PP_TOK_ELIF ) \
X(elifdef , PP_STD, PP_TOK_ELIFDEF ) \
X(elifndef , PP_C23, PP_TOK_ELIFNDEF ) \
X(endif , PP_STD, PP_TOK_ENDIF ) \
X(line , PP_STD, PP_TOK_LINE ) \
X(embed , PP_C23, PP_TOK_EMBED ) \
X(error , PP_STD, PP_TOK_ERROR ) \
X(warning , PP_C23, PP_TOK_WARNING ) \
X(pragma , PP_STD, PP_TOK_PRAMA ) \
#define SCC_PP_INST_TOKEN \
X(define , SCC_PP_STD, SCC_PP_TOK_DEFINE ) \
X(undef , SCC_PP_STD, SCC_PP_TOK_UNDEF ) \
X(include , SCC_PP_STD, SCC_PP_TOK_INCLUDE ) \
X(if , SCC_PP_STD, SCC_PP_TOK_IF ) \
X(ifdef , SCC_PP_STD, SCC_PP_TOK_IFDEF ) \
X(ifndef , SCC_PP_STD, SCC_PP_TOK_IFNDEF ) \
X(else , SCC_PP_STD, SCC_PP_TOK_ELSE ) \
X(elif , SCC_PP_STD, SCC_PP_TOK_ELIF ) \
X(elifdef , SCC_PP_STD, SCC_PP_TOK_ELIFDEF ) \
X(elifndef , SCC_PP_C23, SCC_PP_TOK_ELIFNDEF ) \
X(endif , SCC_PP_STD, SCC_PP_TOK_ENDIF ) \
X(line , SCC_PP_STD, SCC_PP_TOK_LINE ) \
X(embed , SCC_PP_C23, SCC_PP_TOK_EMBED ) \
X(error , SCC_PP_STD, SCC_PP_TOK_ERROR ) \
X(warning , SCC_PP_C23, SCC_PP_TOK_WARNING ) \
X(pragma , SCC_PP_STD, SCC_PP_TOK_PRAMA ) \
// END
/* clang-format on */
#define X(name, type, tok) tok,
typedef enum pp_token { PP_INST_TOKEN } pp_token_t;
typedef enum scc_pp_token { SCC_PP_INST_TOKEN } scc_pp_token_t;
#undef X
#endif /* __SMCC_PP_TOKEN_H__ */
#endif /* __SCC_PP_TOKEN_H__ */