How to detect beginning of line, or: “The name 'getCharPositionInLine' does not exist in the current context”

倾然丶 夕夏残阳落幕 提交于 2019-12-06 13:29:29

Simplest approach is to just recognize an EOL as the corresponding BOL token.

BC  : '/*' .*? '*/' -> channel(HIDDEN) ;
LC  : '//' ~[\r\n]* -> channel(HIDDEN) ;
HWS : [ \t]*        -> channel(HIDDEN) ;
BOL : [\r\n\f]+ ;

Rules like a block comment rule will consume the EOLs internally, so no problem there. Rules like a line comment will not consume the EOL, so a proper BOL will be emitted for the line immediately following.

A potential problem is that no BOL will be emitted for the beginning of input. Simplest way to handle this is to force prefix the input text with a line terminal before feeding it to the lexer.

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