[BUG] Tokenizer mishandles triple-quoted strings — keywords replaced inside them

未关闭
#24 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
python
领域
compilers

调研方向

The bug lives in _tokenize_preserving_strings in maithili_dsl/transpiler/transpile.py, which only matches single-line quoted strings and # comments. Reproduce by transpiling x = """क " में " ख""" and confirm में is replaced inside the literal. Extend the tokenizer regex to match triple-quoted strings ("""...""" and '''...''', spanning newlines) before the single-quote alternatives, then add tests for keywords inside triple quotes, inner quotes, and a multi-line docstring. Done when those cases pass unchanged and existing transpiler tests still pass.

由索引模型根据 Issue 内容生成。

描述

area:transpiler bug P2

File: maithili_dsl/transpiler/transpile.py (_tokenize_preserving_strings)

The tokenizer only knows single-line "..." / '...' strings and # comments. Triple-quoted strings are parsed as pairs of empty strings, so when the content itself contains a quote, part of the string body is treated as code and keywords inside it get replaced:

Input:  x = """क " में " ख"""
Output: x = """क " in " ख"""   # में replaced inside a string literal

(Verified against v0.3.0. Simple triple-quoted strings without inner quotes survive only by accident.)

Fix: extend the tokenizer regex to match """...""" and '''...''' (with re.DOTALL-style content) before the single-quote alternatives. Consider f-string prefixes (f"...") while in there.

Tests: triple-quoted string with keywords, with inner quotes, multi-line docstring on a कार्य.

主要语言
Python
星标
1
派生
4
平均合并
12 天 21 小时
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

alphacrack/python-maithili-dsl 的其他 Issue

查看 alphacrack/python-maithili-dsl 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。