Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Should the parser stay ANTLR-generated? (intent of #565, needs-design)

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
重构
描述清晰度
需要澄清
活跃度
活跃
技术栈
csharp
领域
compilers

调研方向

先阅读 Core/Antlr、AngouriMath.g、Docs/Contributing/ImproveParser.md 和 StringizeRoundTripTest,以了解当前 parser 及其验收标准。任何拟议的替代方案都应根据 round-trip 保留、错误消息、运行时成本,以及 Docs/Usage/Syntax.md 是否仍然准确进行评估;当维护者基于这些检查作出决定后,该 issue 即告完成。

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

描述

Splitting the intent of #565 out of the branch, which is being closed: it proposed replacing the ANTLR-generated parser with one built on Yoakke, and the question it raises is live even though the branch is not.

What the branch did

Deleted the whole of Core/Antlr — the grammar, the four generated files, the .interp/.tokens
artefacts and the bundled antlr-4.8-complete.jar — and replaced it with a hand-assembled parser:
+740 / −7185 across 26 files.

Why ANTLR is worth replacing

Not on parser-theory grounds. On the day-to-day cost of it:

  • The generated files are committed, so a grammar change is a two-step ritual — edit
    AngouriMath.g, run antlr_rerun.bat, then run a post-processing pass whose only job is to rewrite
    public to internal on the generated classes. Docs/Contributing/ImproveParser.md documents it,
    and the documentation has to warn you to regenerate the unmodified grammar first and check the diff
    is empty, so that a toolchain version difference is not mistaken for your change.
  • It needs a JDK to change the grammar at all, in a repository that otherwise needs only the .NET
    SDK.
  • A 1 MB jar is in the source tree.
  • The error messages are ANTLR's, which is why MissingOperatorParseException and friends exist to
    translate them, and why Docs/Usage/Syntax.md had to be written by hand as a separate statement of
    what the parser accepts.

Why it is not obviously worth doing

  • The parser works, and its contract is now tested. StringizeRoundTripTest holds printing to being
    parsing's inverse across every node type, and 2.0 fixed several node shapes that did not round-trip.
    A rewrite starts that guarantee from zero.
  • The grammar is the specification. Syntax.md describes it, but AngouriMath.g is the thing that
    decides, and it is 480-odd lines of readable declarative rules. A hand-written recursive-descent
    parser is more code and less obviously equivalent to a reader.
  • Yoakke is itself a dependency, and a small one — it would be trading a build-time dependency on a
    jar for a run-time dependency on a young library, which for a package with 313k downloads is a
    different kind of risk rather than less risk.
  • Nothing about the parser is currently a bug. The open parse issues are about what the grammar
    says — precedence, notation — not about how it is produced.

What would make this decidable

  1. Is the round trip preserved? StringizeRoundTripTest over every node type is the acceptance, and
    it did not exist when #565 was written.
  2. Are the error messages better? The reason to hand-write a parser is control over failure; if the
    replacement's messages are no better than the translated ANTLR ones, the main benefit is only the
    build simplification.
  3. What does it cost at run time? Parsing is on the hot path for FromString, which caches by
    string precisely because it is not free.
  4. Does Syntax.md stay true, and can it be generated from the new parser rather than maintained
    beside it?

I have no recommendation. The four costs above are real and so are the four objections, and this is a
maintainer's call about what the library wants to own. Filed so that the reasoning survives the branch
rather than being rediscovered in another four years.

主要语言
C#
星标
831
派生
79
平均合并
2 小时 22 分钟
30 天内合并 PR
507

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

ASC-Community/AngouriMath 的其他 Issue

查看 ASC-Community/AngouriMath 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

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