🚀 feat: Multiple improvements for Nyash parser and LLVM backend

Parser improvements:
- Added expression statement fallback in parse_statement() for flexible syntax
- Fixed ternary operator to use PeekExpr instead of If AST (better lowering)
- Added peek_token() check to avoid ?/?: operator conflicts

LLVM Python improvements:
- Added optional ESC_JSON_FIX environment flag for string concatenation
- Improved PHI generation with better default handling
- Enhanced substring tracking for esc_json pattern

Documentation updates:
- Updated language guide with peek expression examples
- Added box theory diagrams to Phase 15 planning
- Clarified peek vs when syntax differences

These changes enable cleaner parser implementation for self-hosting,
especially for handling digit conversion with peek expressions instead
of 19-line if-else chains.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Selfhosting Dev
2025-09-14 19:16:32 +09:00
parent ab1afbc57b
commit 3ba96d9a03
30 changed files with 685 additions and 375 deletions

View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
ROOT_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
BIN="$ROOT_DIR/target/release/nyash"
if [[ ! -x "$BIN" ]]; then
echo "[build] nyash (release) ..." >&2
cargo build --release >/dev/null
fi
mkdir -p "$ROOT_DIR/tmp"
TMP_SRC="$ROOT_DIR/tmp/ny_parser_input.ny"
printf 'return 1+2*3\n' > "$TMP_SRC"
# Run parser MVP (Python) to JSON v0, then pipe to bridge
JSON_OUT=$(python3 "$ROOT_DIR/tools/ny_parser_mvp.py" "$TMP_SRC")
if [[ -z "$JSON_OUT" ]]; then
echo "error: parser produced no JSON" >&2
exit 1
fi
echo "$JSON_OUT" | "$BIN" --ny-parser-pipe >/tmp/ny_parser_mvp_rt.out || true
if rg -q '^Result:\s*7\b' /tmp/ny_parser_mvp_rt.out; then
echo "✅ Ny parser MVP roundtrip OK" >&2
exit 0
else
echo "❌ Ny parser MVP roundtrip FAILED" >&2
cat /tmp/ny_parser_mvp_rt.out >&2 || true
exit 2
fi