English 中文(简体)
• 如何结合《新南半球公约》中的评论意见
原标题:How to combine tokens around comments in ANTLR

我是《南极海生委》的新手,利用它来开发一种模棱两可的语言。 我想做的是,在不使用AST的情况下,如何把围绕“comments”的标语合并成一个标语。

我正在使用这一简单的图表来说明问题。

grammar test;

query   
    :     expression+   
    ;

expression
    :   alpha 
    ;


alpha
    : ID
    ;


ID  :   ( a .. z | A .. Z | _ ) ( a .. z | A .. Z | 0 .. 9 | _ )*
    ;


COMMENT
    :    {  ( options {greedy=false;} : . )*  }  {$channel=HIDDEN;}
    ;

现在,如果我们以简单文本“试验参数”执行,就会产生两种不同的信号,即“试验”和“试验”。 我只想从中挑出来。 任何帮助都将受到高度赞赏。

预 收

Jim

问题回答

我不敢肯定,但你试图这样做:

 ID  :   ( a .. z | A .. Z | _ ) ( a .. z | A .. Z | 0 .. 9 | _ )* COMMENT? ( a .. z | A .. Z | 0 .. 9 | _ )* 
;




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签