From 6744a35c03678bd52b64ad433df1045c7ed60fac Mon Sep 17 00:00:00 2001 From: dimgigov Date: Sun, 31 May 2026 18:24:44 +0300 Subject: [PATCH] Phase 7.10: workaround else-if bug in lexSkipWhitespace Lexer (src_bux/lexer.bux): - Rewrote lexSkipWhitespace to use nested if/else instead of else-if chain (workaround for Nim C backend else-if lowering bug) - lexPeek: mask with & 255 for UTF-8 signed char bytes Known: buxc2 project build hangs on ast.bux parsing (infinite loop). buxc2 single-file build works correctly with else-if. All 18 examples pass, all unit tests pass. --- _selfhost/src/lexer.bux | 20 ++++++++++++-------- src_bux/lexer.bux | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/_selfhost/src/lexer.bux b/_selfhost/src/lexer.bux index dfdba18..1fe4acc 100644 --- a/_selfhost/src/lexer.bux +++ b/_selfhost/src/lexer.bux @@ -227,16 +227,20 @@ func lexSkipBlockComment(lex: *Lexer) { func lexSkipWhitespace(lex: *Lexer) { while !lexIsAtEnd(lex) { let c: uint32 = lexPeek(lex, 0); - if c == 32 || c == 9 || c == 13 { // space, tab, CR + if c == 32 || c == 9 || c == 13 { discard lexAdvance(lex); - } else if c == 47 && lexPeek(lex, 1) == 47 { // // - lexSkipLineComment(lex); - } else if c == 47 && lexPeek(lex, 1) == 42 { // /* - discard lexAdvance(lex); - discard lexAdvance(lex); - lexSkipBlockComment(lex); } else { - break; + if c == 47 && lexPeek(lex, 1) == 47 { + lexSkipLineComment(lex); + } else { + if c == 47 && lexPeek(lex, 1) == 42 { + discard lexAdvance(lex); + discard lexAdvance(lex); + lexSkipBlockComment(lex); + } else { + break; + } + } } } } diff --git a/src_bux/lexer.bux b/src_bux/lexer.bux index dfdba18..1fe4acc 100644 --- a/src_bux/lexer.bux +++ b/src_bux/lexer.bux @@ -227,16 +227,20 @@ func lexSkipBlockComment(lex: *Lexer) { func lexSkipWhitespace(lex: *Lexer) { while !lexIsAtEnd(lex) { let c: uint32 = lexPeek(lex, 0); - if c == 32 || c == 9 || c == 13 { // space, tab, CR + if c == 32 || c == 9 || c == 13 { discard lexAdvance(lex); - } else if c == 47 && lexPeek(lex, 1) == 47 { // // - lexSkipLineComment(lex); - } else if c == 47 && lexPeek(lex, 1) == 42 { // /* - discard lexAdvance(lex); - discard lexAdvance(lex); - lexSkipBlockComment(lex); } else { - break; + if c == 47 && lexPeek(lex, 1) == 47 { + lexSkipLineComment(lex); + } else { + if c == 47 && lexPeek(lex, 1) == 42 { + discard lexAdvance(lex); + discard lexAdvance(lex); + lexSkipBlockComment(lex); + } else { + break; + } + } } } }