antlr2

Negated lexer rules/tokens

旧城冷巷雨未停 提交于 2020-05-17 08:49:28
问题 I am trying to match (and ignore) c-style block comments. To me the sequence is (1) /* followed by (2) anything other than /* or */ until (3) */ . BLOCK_COMMENT_START : "/*" ; BLOCK_COMMENT_END : "*/" ; BLOCK_COMMENT : BLOCK_COMMENT_START ( ~( BLOCK_COMMENT_START | BLOCK_COMMENT_END ) )* BLOCK_COMMENT_END { // again, we want to skip the entire match from the lexer stream $setType( Token.SKIP ); } ; But Antlr does not think like I do ;) sql-stmt.g:121:34: This subrule cannot be inverted. Only

antlr2 return multiple values

落爺英雄遲暮 提交于 2020-01-06 14:16:35
问题 How to make a rule return multiple values in antlr2.For example: declSpecifiers returns [int mods] : ( storageClassSpecifier | typeQualifier | typeSpecifier)+ ; I have some other information besides 'mods' to return.What should I do? 回答1: In ANTLR v3.x, you can include multiple return values by listing them in the brackets. declSpecifiers returns [int mods, Object otherInfo] : ( storageClassSpecifier | typeQualifier | typeSpecifier)+ ; The generated code will return a generated class