Skip to content

feat(lexer,stdlib): complete Lua 5.4 lexer escapes, long strings, and stdlib edge semantics - #73

Merged
cursor[bot] merged 1 commit into
masterfrom
cursor/lua54-lexer-stdlib-83af
Dec 2, 2026
Merged

cursor[bot] merged 1 commit into
masterfrom
cursor/lua54-lexer-stdlib-83af

Conversation

@esrrhs

@esrrhs esrrhs commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Summary

Implements P3 (Lua 5.4 lexer & standard library edge semantics) on top of master (including PR #69, PR #70, PR #71), without mixing in P4 or P5.

Lexer & String Colon Methods

  • src/util/string_util.cpp (ReplaceEscapeChars): Added Lua 5.3/5.4 \u{XXXX} UTF-8 codepoint escapes (0..0x7FFFFFFF, 1–6 byte extended UTF-8, arbitrary leading zeros, and strict { / hex digit / range / } error checks). Preserved PR feat: add kernel mode and lock host language contract #69's \xHH implementation and "invalid hexadecimal escape" diagnostic intact; left IsNumber/IsInteger/Boost::regex untouched (P5).
  • src/compile/flex/scanner.l, scanner.cpp (regenerated with flex++ 2.6.4), src/compile/my_flexer.cpp:
    • Added multi-level long string scanning ([=[...]=]) with Lua 5.4 immediate leading-newline stripping, \r\n/\n\r/\r → \n normalization, proper handling of embedded ]/]]= sequences (e.g. [=[a[1]]=], [=[a[1]]]=]), and unfinished long string diagnostics. Also fixed <MULTI_LINE_COMMENT_STATE> non-matching closer backtracking for --[=[a[1]]=].
    • Added leading/trailing decimal-point float literals (.5, 1., .5e2, 1.e2, 0x.8, 0x1., 0x.8p2, 0x1.p2) while preserving malformed number rejection on 1..2, 0x., 1.e, .5a, etc.
    • Verified all newly accepted float literal forms remain rejected under --mode=kernel (floating-point literal is forbidden in --mode=kernel, honoring PR feat: add kernel mode and lock host language contract #69's host language contract).
  • src/compile/compile_common.h, semantic_analysis.cpp, c_gen.{h,cpp}, src/interp/codegen.{h,cpp}: Deduplicated the 3 copies of kStringLibraryMethods into shared StringLibraryMethods() and added Lua 5.4 methods pack, unpack, packsize.

Standard Library Edge Semantics

  • src/native/string/native_string.cpp (string.format):
    • Missing format arguments now raise bad argument #N to 'format' (no value) (fixing 1-based argument numbering).
    • %s with modifiers rejects embedded \0 with string contains zeros (plain %s still preserves \0).
    • %q with modifiers raises specifier '%q' cannot have modifiers.
    • Preserved existing test_format_s_bad_arg_table.lua contract (string.format("%s", {}) errors).
  • src/native/basic/native_basic.cpp, src/native/table/native_table.{h,cpp} (tonumber, next, BasicPairsIterator):
    • tonumber(e, base) with non-nil base now rejects non-string e (bad argument #1 to 'tonumber' (string expected, got <type>)), stops stripping 0x/0X for explicit base=16 (tonumber("0x10", 16) == nil), and parses integer-only for explicit base=10. Kept test_basic_tonumber_edge.lua intact (out-of-range and fractional bases continue returning nil). Updated two legacy coverage test assertions (test_basic_tonumber_extra.lua, test_basic_pairs_coverage.lua) that previously checked the old tonumber("0x...", 16) behavior.
    • Added O(1) TableHelper::NextKV (spec → array index → quick_data_/bucket lookup + active_pos) used by both next and BasicPairsIterator, eliminating O(N²) rescanning and raising invalid key to 'next' for absent or NaN keys in next.
  • src/native/utf8/native_utf8.cpp:
    • Added Lua 5.4 optional lax parameter (Lua truthiness) to utf8.len, utf8.codepoint, and utf8.codes (accepting surrogates 0xD800..0xDFFF and 4–6 byte extended UTF-8 up to 0x7FFFFFFF while still rejecting overlongs and 0xFE/0xFF), updated utf8.codes registration to variadic, and removed the 40-line stale draft comment. Preserved utf8.char strict validation pinned by test_utf8_char_boundary.lua.

Verification

  • Release build (-O3 -DNDEBUG, GCC 13.3.0): 0 new compiler warnings (src/ has 0 warnings).
  • unit_tests (FAKELUA_HOME=/agent/repos/fakelua, excluding MySQL/Redis integration tests): 1840 / 1840 passed, including 8 new regression test cases covering all P3 features across TCC, GCC, INTERP, and --mode=kernel.
  • flua cmd/test.lua: passed (exit 0) across all 3 backends (--jit_type=0, --jit_type=1, --jit_type=2).
Open in Web Open in Cursor 

… stdlib edge semantics

Co-authored-by: esrrhs <esrrhs@163.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 95.69378% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.52%. Comparing base (b686d2e) to head (4a45fbf).

Files with missing lines Patch % Lines
src/util/string_util.cpp 90.00% 5 Missing ⚠️
src/native/basic/native_basic.cpp 89.18% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff            @@
##           master      #73    +/-   ##
========================================
  Coverage   94.52%   94.52%            
========================================
  Files         130      130            
  Lines       32588    32699   +111     
========================================
+ Hits        30803    30909   +106     
- Misses       1785     1790     +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cursor
cursor Bot merged commit e162845 into master Dec 2, 2026
9 checks passed
@cursor
cursor Bot deleted the cursor/lua54-lexer-stdlib-83af branch December 2, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants