预处理以更轻松地在ANTLR中解析

发布于 2025-02-10 01:32:30 字数 662 浏览 2 评论 0原文

我试图用一种非常简约的自然主义语法制作一种语言。从本质上讲,声明随后是标记的正常文本。

@decleration
The first line that is just normal text #someMetaData
The second line <markup> with more normal text

@decleration2
<moreMarkup> more normal text #MoreMetaData

不过,这是在ANTLR上工作的巨大痛苦,因此我将其更改为“明确”语法:

@decleration
~"The first line that is just normal text" #someMetaData
~"The second line "<markup>" with more normal text"

@decleration2
~<moreMarkup>" more normal text" #MoreMetaData

这种语法非常容易解析,但最终不是我想要的语言。

我的问题是:是否有一些直接/优雅的方式来遵循第一个语法,进行一些预处理并在Antlr4中吐出第二个语法?手动编写预处理器可能并不难,但是如果可以的话,我宁愿避免进行两级解析。

谢谢你!

I am trying to make a language with a very minimalist naturalistic syntax. Essentially, a declaration followed by lines of marked up normal text.

@decleration
The first line that is just normal text #someMetaData
The second line <markup> with more normal text

@decleration2
<moreMarkup> more normal text #MoreMetaData

This was a huge pain to get working in ANTLR though, so I changed it to this "explicit" syntax instead:

@decleration
~"The first line that is just normal text" #someMetaData
~"The second line "<markup>" with more normal text"

@decleration2
~<moreMarkup>" more normal text" #MoreMetaData

This syntax is very easy to parse, but ultimately isn't what I want for the language.

My question is this: is there some straightforward/elegant way to take the first syntax, do a bit of preprocessing, and spit out the second syntax, within ANTLR4? It might not be too hard to write a preprocessor manually, but I'd rather avoid two-levels of parsing if I can.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文