antlr4cs

antlr grammar avoiding angle brackets

北城以北 提交于 2019-12-12 03:34:09
问题 In this question I asked about extracting tags from arbitrary text. The solution provided worked well, but there's one edge case I'd like to handle. To recap, I'm parsing arbitrary user-entered text and would like to have any occurrence of < or > to conform to valid tag syntax. Where an angle bracket isn't part of a valid tag, it should be escaped as < or > . The syntax I'm looking for is <foo#123> where foo is text from a fixed list of entries and 123 is a number [0-9]+ . The parser: parser

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

感情迁移 提交于 2019-12-08 00:46:12
问题 I'm trying to create a Beginning-Of-Line token: lexer grammar ScriptLexer; BOL : {getCharPositionInLine() == 0;}; // Beginning Of Line token But the above emits the error The name 'getCharPositionInLine' does not exist in the current context As it creates this code: private void BOL_action(RuleContext _localctx, int actionIndex) { switch (actionIndex) { case 0: getCharPositionInLine() == 0; break; } } Where the getCharPositionInLine() method doesn't exist... 回答1: Simplest approach is to just

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

倾然丶 夕夏残阳落幕 提交于 2019-12-06 13:29:29
I'm trying to create a Beginning-Of-Line token: lexer grammar ScriptLexer; BOL : {getCharPositionInLine() == 0;}; // Beginning Of Line token But the above emits the error The name 'getCharPositionInLine' does not exist in the current context As it creates this code: private void BOL_action(RuleContext _localctx, int actionIndex) { switch (actionIndex) { case 0: getCharPositionInLine() == 0; break; } } Where the getCharPositionInLine() method doesn't exist... Simplest approach is to just recognize an EOL as the corresponding BOL token. BC : '/*' .*? '*/' -> channel(HIDDEN) ; LC : '//' ~[\r\n]*