## ✅ Fixed Issues ### 1. `local` keyword tokenization (commit 9aab64f7) - Added Stage-3 gate for LOCAL/TRY/CATCH/THROW keywords - LOCAL now only active when NYASH_PARSER_STAGE3=1 ### 2. `env.local.get` keyword conflict - File: `lang/src/compiler/entry/compiler_stageb.hako:21-23` - Problem: `.local` in member access tokenized as `.LOCAL` keyword - Fix: Commented out `env.local.get("HAKO_SOURCE")` line - Fallback: Use `--source` argument (still functional) ### 3. `flow` keyword missing - Added FLOW to TokenType enum (`src/tokenizer/kinds.rs`) - Added "flow" → TokenType::FLOW mapping (`src/tokenizer/lex_ident.rs`) - Added FLOW to Stage-3 gate (requires NYASH_PARSER_STAGE3=1) - Added FLOW to parser statement dispatch (`src/parser/statements/mod.rs`) - Added FLOW to declaration handler (`src/parser/statements/declarations.rs`) - Updated box_declaration parser to accept BOX or FLOW (`src/parser/declarations/box_definition.rs`) - Treat `flow FooBox {}` as syntactic sugar for `box FooBox {}` ### 4. Module namespace conversion - Renamed `lang.compiler.builder.ssa.local` → `localvar` (avoid keyword) - Renamed file `local.hako` → `local_ssa.hako` - Converted 152 path-based using statements to namespace format - Added 26+ entries to `nyash.toml` [modules] section ## ⚠️ Remaining Issues ### Stage-B selfhost compiler performance - Stage-B compiler not producing output (hangs/times out after 10+ seconds) - Excessive PHI debug output suggests compilation loop issue - Needs investigation: infinite loop or N² algorithm in hako compiler ### Fallback JSON version mismatch - Rust fallback (`--emit-mir-json`) emits MIR v1 JSON (schema_version: "1.0") - Smoke tests expect MIR v0 JSON (`"version":0, "kind":"Program"`) - stageb_helpers.sh fallback needs adjustment ## Test Status - Parse errors: FIXED ✅ - Keyword conflicts: FIXED ✅ - Stage-B smoke tests: STILL FAILING ❌ (performance issue) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
137 lines
5.0 KiB
Rust
137 lines
5.0 KiB
Rust
use super::{NyashTokenizer, TokenType};
|
|
use crate::grammar::engine;
|
|
|
|
impl NyashTokenizer {
|
|
/// キーワードまたは識別子を読み取り
|
|
pub(crate) fn read_keyword_or_identifier(&mut self) -> TokenType {
|
|
let mut identifier = String::new();
|
|
|
|
while let Some(c) = self.current_char() {
|
|
if c.is_alphanumeric() || c == '_' {
|
|
identifier.push(c);
|
|
self.advance();
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// キーワードチェック
|
|
let mut tok = match identifier.as_str() {
|
|
"box" => TokenType::BOX,
|
|
"global" => TokenType::GLOBAL,
|
|
"singleton" => TokenType::SINGLETON,
|
|
"new" => TokenType::NEW,
|
|
"match" => TokenType::MATCH,
|
|
"if" => TokenType::IF,
|
|
"else" => TokenType::ELSE,
|
|
"loop" => TokenType::LOOP,
|
|
"break" => TokenType::BREAK,
|
|
"continue" => TokenType::CONTINUE,
|
|
"return" => TokenType::RETURN,
|
|
"function" => TokenType::FUNCTION,
|
|
"fn" => TokenType::FN,
|
|
"print" => TokenType::PRINT,
|
|
"this" => TokenType::THIS,
|
|
"me" => TokenType::ME,
|
|
"init" => TokenType::INIT,
|
|
"pack" => TokenType::PACK,
|
|
"birth" => TokenType::BIRTH,
|
|
"nowait" => TokenType::NOWAIT,
|
|
"await" => TokenType::AWAIT,
|
|
"interface" => TokenType::INTERFACE,
|
|
// "include" keyword removed (use `using` instead)
|
|
"import" => TokenType::IMPORT,
|
|
"try" => TokenType::TRY,
|
|
"catch" => TokenType::CATCH,
|
|
"cleanup" => TokenType::CLEANUP,
|
|
"throw" => TokenType::THROW,
|
|
"local" => TokenType::LOCAL,
|
|
"flow" => TokenType::FLOW,
|
|
"static" => TokenType::STATIC,
|
|
"outbox" => TokenType::OUTBOX,
|
|
"not" => TokenType::NOT,
|
|
"override" => TokenType::OVERRIDE,
|
|
"from" => TokenType::FROM,
|
|
"weak" => TokenType::WEAK,
|
|
"using" => TokenType::USING,
|
|
"and" => TokenType::AND,
|
|
"or" => TokenType::OR,
|
|
"true" => TokenType::TRUE,
|
|
"false" => TokenType::FALSE,
|
|
"null" => TokenType::NULL,
|
|
_ => TokenType::IDENTIFIER(identifier.clone()),
|
|
};
|
|
|
|
// Stage-3 gate: LOCAL/FLOW/TRY/CATCH/THROW require NYASH_PARSER_STAGE3=1
|
|
let stage3_enabled = crate::config::env::parser_stage3();
|
|
if !stage3_enabled {
|
|
let is_stage3 = matches!(
|
|
tok,
|
|
TokenType::LOCAL
|
|
| TokenType::FLOW
|
|
| TokenType::TRY
|
|
| TokenType::CATCH
|
|
| TokenType::THROW
|
|
);
|
|
if is_stage3 {
|
|
if std::env::var("NYASH_TOK_TRACE").ok().as_deref() == Some("1") {
|
|
eprintln!("[tok-stage3] Degrading {:?} to IDENTIFIER (NYASH_PARSER_STAGE3={})",
|
|
tok, stage3_enabled);
|
|
}
|
|
tok = TokenType::IDENTIFIER(identifier.clone());
|
|
}
|
|
} else {
|
|
if std::env::var("NYASH_TOK_TRACE").ok().as_deref() == Some("1") {
|
|
let is_stage3 = matches!(
|
|
tok,
|
|
TokenType::LOCAL
|
|
| TokenType::FLOW
|
|
| TokenType::TRY
|
|
| TokenType::CATCH
|
|
| TokenType::THROW
|
|
);
|
|
if is_stage3 {
|
|
eprintln!("[tok-stage3] Keeping {:?} as keyword (NYASH_PARSER_STAGE3={})",
|
|
tok, stage3_enabled);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 12.7 Strict mode: fallback extended keywords to IDENTIFIER
|
|
if Self::strict_12_7() {
|
|
let is_extended = matches!(
|
|
tok,
|
|
TokenType::INTERFACE
|
|
| TokenType::USING
|
|
| TokenType::OUTBOX
|
|
| TokenType::NOWAIT
|
|
| TokenType::OVERRIDE
|
|
| TokenType::WEAK
|
|
| TokenType::PACK
|
|
);
|
|
if is_extended {
|
|
tok = TokenType::IDENTIFIER(identifier.clone());
|
|
}
|
|
}
|
|
|
|
// 統一文法エンジンとの差分チェック(動作は変更しない)
|
|
if std::env::var("NYASH_GRAMMAR_DIFF").ok().as_deref() == Some("1") {
|
|
if let Some(kw) = engine::get().is_keyword_str(&identifier) {
|
|
if let TokenType::IDENTIFIER(_) = tok {
|
|
eprintln!(
|
|
"[GRAMMAR-DIFF] tokenizer=IDENT, grammar=KEYWORD({}) word='{}'",
|
|
kw, identifier
|
|
);
|
|
}
|
|
} else if !matches!(tok, TokenType::IDENTIFIER(_)) {
|
|
eprintln!(
|
|
"[GRAMMAR-DIFF] tokenizer=KEYWORD, grammar=IDENT word='{}'",
|
|
identifier
|
|
);
|
|
}
|
|
}
|
|
|
|
tok
|
|
}
|
|
}
|