chore: clean up experimental changes, keep core parser improvements

This commit is contained in:
2026-06-07 17:11:45 +03:00
parent 134e8e877d
commit 4794335673
2 changed files with 3 additions and 30 deletions
-3
View File
@@ -541,9 +541,6 @@ func Cli_BuildProject(projectDir: String) -> int {
return 1; return 1;
} }
let lex: *Lexer = Lexer_Tokenize(source); let lex: *Lexer = Lexer_Tokenize(source);
Print(" [tokens: ");
PrintInt(lex.tokenCount as int64);
PrintLine("]");
if Lexer_DiagCount(lex) > 0 { if Lexer_DiagCount(lex) > 0 {
Print(" Lex errors in "); Print(" Lex errors in ");
PrintLine(path); PrintLine(path);
+3 -27
View File
@@ -869,13 +869,7 @@ func parserParseBlock(p: *Parser) -> *Block {
} }
let beforePos: int = p.pos; let beforePos: int = p.pos;
let s: *Stmt = parserParseStmt(p); let s: *Stmt = parserParseStmt(p);
// Infinite-loop safeguard
if p.pos == beforePos { if p.pos == beforePos {
// If stuck and current token is }, consume it and exit
if parserCheck(p, tkRBrace) {
discard parserAdvance(p);
break;
}
discard parserAdvance(p); discard parserAdvance(p);
continue; continue;
} }
@@ -891,8 +885,7 @@ func parserParseBlock(p: *Parser) -> *Block {
b.stmtCount = b.stmtCount + 1; b.stmtCount = b.stmtCount + 1;
} }
} }
// Consume } if present (may already be consumed by safeguard) discard parserExpect(p, tkRBrace, "expected '}'");
parserMatch(p, tkRBrace);
return b; return b;
} }
@@ -1002,11 +995,6 @@ func parserParseFuncDecl(p: *Parser, isPublic: bool, isExtern: bool, isAsync: bo
// Body // Body
if !isExtern && parserCheck(p, tkLBrace) { if !isExtern && parserCheck(p, tkLBrace) {
d.refBody = parserParseBlock(p); d.refBody = parserParseBlock(p);
// HACK: consume any leftover } that parserParseBlock may have missed
// Without this, the module handler sees the } and exits early.
if parserCheck(p, tkRBrace) {
discard parserAdvance(p);
}
} else { } else {
d.refBody = null as *Block; d.refBody = null as *Block;
} }
@@ -2038,24 +2026,11 @@ func parserParseDecl(p: *Parser) -> *Decl {
discard parserAdvance(p); // consume { discard parserAdvance(p); // consume {
var items: *Decl = null as *Decl; var items: *Decl = null as *Decl;
var lastItem: *Decl = null as *Decl; var lastItem: *Decl = null as *Decl;
var moduleDepth: int = 1; while !parserCheck(p, tkRBrace) && parserPeek(p, 0) != tkEndOfFile {
while moduleDepth > 0 && parserPeek(p, 0) != tkEndOfFile {
if parserCheck(p, tkNewLine) || parserCheck(p, tkSemicolon) { if parserCheck(p, tkNewLine) || parserCheck(p, tkSemicolon) {
discard parserAdvance(p); discard parserAdvance(p);
continue; continue;
} }
// Track stray braces that parserParseDecl may have left behind
if parserCheck(p, tkLBrace) {
moduleDepth = moduleDepth + 1;
discard parserAdvance(p);
continue;
}
if parserCheck(p, tkRBrace) {
moduleDepth = moduleDepth - 1;
discard parserAdvance(p);
if moduleDepth <= 0 { break; }
continue;
}
let beforePos: int = p.pos; let beforePos: int = p.pos;
let item: *Decl = parserParseDecl(p); let item: *Decl = parserParseDecl(p);
if item != null as *Decl { if item != null as *Decl {
@@ -2073,6 +2048,7 @@ func parserParseDecl(p: *Parser) -> *Decl {
discard parserAdvance(p); discard parserAdvance(p);
} }
} }
discard parserExpect(p, tkRBrace, "expected '}' to close module");
d.childDecl1 = items; // first item of module d.childDecl1 = items; // first item of module
} else { } else {
parserMatch(p, tkSemicolon); parserMatch(p, tkSemicolon);