refactor(lexer, ast): Rewrite decl with c standard grammar of decl

This commit is contained in:
2026-06-12 18:32:13 +08:00
parent 6ff9c804aa
commit 5099bbaab7
4 changed files with 407 additions and 230 deletions
+15 -1
View File
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{str::FromStr, sync::LazyLock};
use thiserror::Error;
@@ -330,6 +330,17 @@ fn parse_puncuation(
Ok(token_value)
}
// static KEYWORDS: LazyLock<HashMap<&'static str, TokenValue>> = LazyLock::new(|| {
// let mut m = HashMap::new();
// m.insert("if", TokenValue::If);
// m.insert("else", TokenValue::Else);
// m.insert("while", TokenValue::While);
// m.insert("for", TokenValue::For);
// m.insert("return", TokenValue::Return);
// m.insert("break", TokenValue::Break);
// m.insert("continue", TokenValue::Continue);
// m
// });
fn parse_ident(
str_iter: &mut Cursor,
) -> Result<TokenValue, LexParseError> {
@@ -370,6 +381,9 @@ fn parse_ident(
if name.eq("continue") {
return Ok(TokenValue::Continue);
}
if name.eq("static") {
return Ok(TokenValue::Static);
}
if let Some(type_ident) = TypeIdent::from_str(&name).ok() {
return Ok(TokenValue::TypeIdent(type_ident));
}