Some simple information syncing

This commit is contained in:
2026-07-28 21:08:58 +08:00
parent 1837339f69
commit 3633be1995
65 changed files with 1132 additions and 368581 deletions

View File

@@ -530,6 +530,8 @@ def _read_string(lx: Lexer | t.CPtr):
tok: Token | t.CPtr = new_token(lx.pool, TokenType.String, start_lineno, start_col)
if tok == None: return
content_len: t.CSizeT = content_end - content_buf_start
# esc_len: 转义后实际字节数(用于判断单字符)
esc_len: t.CSizeT = content_len
# 处理转义序列(非 raw 字符串)
if is_raw == 0 and content_len > 0:
@@ -572,15 +574,22 @@ def _read_string(lx: Lexer | t.CPtr):
rpos += 1
conv_buf[wpos] = '\0'
token_set_str_literal(lx.pool, tok, conv_buf)
esc_len = wpos
else:
token_set_str(lx.pool, tok, lx.src, content_buf_start, content_len)
tok.end_lineno = lx.lineno
tok.end_col_offset = lx.col
# flags 字段复用bit0=raw, bit1=bytes, bit2=fstring, bit3=triple
# flags 字段复用bit0=raw, bit1=bytes, bit2=fstring, bit3=triple, bit4=dquote, bit5=单字符候选
if is_raw: tok.kw_subtype = tok.kw_subtype | 1
if is_bytes: tok.kw_subtype = tok.kw_subtype | 2
if is_fstring: tok.kw_subtype = tok.kw_subtype | 4
if is_triple: tok.kw_subtype = tok.kw_subtype | 8
# bit4 (16) = 双引号0=单引号, 1=双引号)
if quote == '"': tok.kw_subtype = tok.kw_subtype | 16
# bit5 (32) = 单字符候选(非三引号、非 fstring、转义后正好 1 字节)
# 用于 CONST_CHAR 判定,避免 '\0' 等含 NUL 字节被 strlen 误判为空字符串
if is_triple == 0 and is_fstring == 0 and esc_len == 1:
tok.kw_subtype = tok.kw_subtype | 32
_emit(lx, tok)