How to recognise start-of-line in an Antlr grammar?

三世轮回 提交于 2019-12-23 17:46:05

问题


In the language I work with, some keywords must be at the start of the line. This is mainly because string values within the language can go over multiple lines, and strings could easily contain these keywords.

The old yacc/lex grammar implementation I have easily deals with this because the lexer uses normal regexes to match text patterns, e.g.

^description    { actions }

matches 'description' at the start of a line and then does actions.

How can I do this in Antlr4? It does not appear to support proper regex for lexical matching. I'm using the IntelliJ plugin, and it complains when I use the '^' character on any lexer rule RHS.

来源:https://stackoverflow.com/questions/32870858/how-to-recognise-start-of-line-in-an-antlr-grammar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!