diff --git a/src/parser/declarations/static_def/members.rs b/src/parser/declarations/static_def/members.rs index bb2cffbc..ee6c93d8 100644 --- a/src/parser/declarations/static_def/members.rs +++ b/src/parser/declarations/static_def/members.rs @@ -77,12 +77,36 @@ pub(crate) fn try_parse_method_or_field( p.advance(); // consume '(' let mut params = Vec::new(); while !p.match_token(&TokenType::RPAREN) && !p.is_at_end() { - crate::must_advance!(p, _unused, "static method parameter parsing"); - if let TokenType::IDENTIFIER(param) = &p.current_token().token_type { - params.push(param.clone()); - p.advance(); + // Peek at the current token to ensure forward progress + match p.current_token().token_type { + TokenType::IDENTIFIER(ref param) => { + params.push(param.clone()); + p.advance(); + } + TokenType::COMMA => { + p.advance(); + } + TokenType::NEWLINE => { + // Stage-3 tolerant mode: allow newlines in parameter list + p.advance(); + } + TokenType::RPAREN => { + break; + } + _ => { + // Unexpected token handling + if std::env::var("NYASH_PARSER_METHOD_PARAM_STRICT").ok().as_deref() == Some("1") { + return Err(ParseError::UnexpectedToken { + found: p.current_token().token_type.clone(), + expected: "parameter identifier, comma, or )".to_string(), + line: p.current_token().line, + }); + } else { + // Tolerant mode: skip unexpected token to avoid infinite loop + p.advance(); + } + } } - if p.match_token(&TokenType::COMMA) { p.advance(); } } p.consume(TokenType::RPAREN)?; // Allow NEWLINE(s) between ')' and '{' of method body diff --git a/tools/hakorune_emit_mir.sh b/tools/hakorune_emit_mir.sh index 8a439a2c..1448e659 100644 --- a/tools/hakorune_emit_mir.sh +++ b/tools/hakorune_emit_mir.sh @@ -43,10 +43,10 @@ CODE="$(cat "$IN")" # 1) Stage‑B: Hako parser emits Program(JSON v0) to stdout set +e -PROG_JSON_OUT=$(NYASH_DISABLE_NY_COMPILER=1 HAKO_DISABLE_NY_COMPILER=1 \ +PROG_JSON_OUT=$(NYASH_JSON_ONLY=1 NYASH_DISABLE_NY_COMPILER=1 HAKO_DISABLE_NY_COMPILER=1 \ NYASH_PARSER_STAGE3=1 HAKO_PARSER_STAGE3=1 NYASH_PARSER_ALLOW_SEMICOLON=1 \ NYASH_ENABLE_USING=1 HAKO_ENABLE_USING=1 \ - "$NYASH_BIN" --backend vm "$ROOT/lang/src/compiler/entry/compiler_stageb.hako" -- --source "$CODE" 2>/dev/null) + "$NYASH_BIN" --backend vm "$ROOT/lang/src/compiler/entry/compiler_stageb.hako" -- --source "$CODE" 2>/dev/null | awk '/^{/,/^}$/') rc=$? set -e if [ $rc -ne 0 ] || [ -z "$PROG_JSON_OUT" ]; then