预处理以更轻松地在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
不过,这是在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论