fix: escape sequences in strings, --version/--help, manifest parser, debug cleanup

- Lexer (Nim + Bux): resolve escape sequences (\n, \t, \r, etc) instead of
  keeping raw source text in token. This was the root cause of \n being
  double-escaped to \\n in generated C code.
- Manifest parser (src_bux/manifest.bux): use bux_strlen instead of broken
  String_SplitCount(s, "") hack for string length; fix quote stripping.
- CLI (src_bux/cli.bux): --version/--help now recognized alongside version/help.
- Remove ~30+ debug Print statements from cli, parser, lexer, sema, main.
- Clean up unneeded Print/PrintInt extern declarations.
- _selfhost/src/: synced from src_bux/.
This commit is contained in:
2026-06-05 18:24:59 +03:00
parent a10c49cb16
commit a45a2ecd49
11 changed files with 255 additions and 158 deletions
+21 -8
View File
@@ -260,6 +260,8 @@ proc scanString(lex: var Lexer, startLoc: SourceLocation, prefixLen: int): Token
let startPos = lex.pos - prefixLen
# prefixLen characters before the opening quote were already consumed by caller
# but we need to handle the quote itself
# Collect resolved string content to properly handle escape sequences
var resolved = ""
if lex.peek() == '"':
discard lex.advance()
while not lex.isAtEnd() and lex.peek() != '"':
@@ -268,14 +270,19 @@ proc scanString(lex: var Lexer, startLoc: SourceLocation, prefixLen: int): Token
break
if lex.peek() == '\\':
discard lex.advance()
discard lex.scanEscapeSequence()
resolved.add(lex.scanEscapeSequence())
else:
discard lex.advance()
resolved.add(lex.advance())
if lex.isAtEnd():
lex.emitError(startLoc, "unterminated string literal")
else:
discard lex.advance() # closing "
result = lex.makeToken(tkStringLiteral, startLoc, startPos)
# Rebuild text with resolved escapes: prefix + " + resolved + "
var text = lex.source[startPos ..< startPos + prefixLen]
text.add('"')
text.add(resolved)
text.add('"')
result = Token(kind: tkStringLiteral, text: text, loc: startLoc)
proc scanBacktickString(lex: var Lexer, startLoc: SourceLocation): Token =
## Scan a backtick-delimited raw string literal: content is literal,
@@ -291,23 +298,29 @@ proc scanBacktickString(lex: var Lexer, startLoc: SourceLocation): Token =
proc scanChar(lex: var Lexer, startLoc: SourceLocation, prefixLen: int): Token =
let startPos = lex.pos - prefixLen
# Collect resolved char content to properly handle escape sequences
var resolved = ""
if lex.peek() == '\'':
discard lex.advance()
if lex.isAtEnd():
lex.emitError(startLoc, "unterminated char literal")
return lex.makeToken(tkCharLiteral, startLoc, startPos)
if lex.peek() == '\n':
elif lex.peek() == '\n':
lex.emitError(lex.currentLocation(), "newline in char literal")
elif lex.peek() == '\\':
discard lex.advance()
discard lex.scanEscapeSequence()
resolved.add(lex.scanEscapeSequence())
else:
discard lex.advance()
resolved.add(lex.advance())
if lex.isAtEnd() or lex.peek() != '\'':
lex.emitError(lex.currentLocation(), "expected closing ' for char literal")
else:
discard lex.advance()
result = lex.makeToken(tkCharLiteral, startLoc, startPos)
# Rebuild text with resolved escape: prefix + ' + resolved + '
var text = lex.source[startPos ..< startPos + prefixLen]
text.add('\'')
text.add(resolved)
text.add('\'')
result = Token(kind: tkCharLiteral, text: text, loc: startLoc)
# ---------------------------------------------------------------------------
# Symbols / operators