]> git.kaiwu.me - njs.git/commit
Parser: own the [In] grammar parameter
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 1 Sep 2026 01:30:37 +0000 (18:30 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 4 Sep 2026 20:56:37 +0000 (13:56 -0700)
commitb16eec01885cf8f5849f1be056b590e4d1217531
treef71a3b18433fcc658ee355cd9df8a96edb527df5
parent55f72dc3defe3eba610d9e0304ab544d17652545
Parser: own the [In] grammar parameter

Previously, the [In] parameter lived in the lexer, in a byte array indexed by
bracket nesting depth.  The lexer advanced the depth while prereading, the
parser wrote at the depth it had consumed to, so a delimiter in a conditional
consequent left the write in the wrong slot and the restriction was lost:

    for (a ? (b) : c in d; false;);

The fix is to carry the parameter in njs_parser_stack_entry_t: a frame
records the value in effect when it was pushed and restores it when popped,
including on the njs_parser_reject() landing frame.  An arrow initializer now
gets [~In] as well, which it escaped before.

This also allows to remove the [In] support from the lexer. The parser
owns the parameter now. njs_lexer_t drops from 104 to 80 bytes and no longer
allocates.
src/njs_lexer.c
src/njs_lexer.h
src/njs_parser.c
src/njs_parser.h
src/test/njs_unit_test.c