English 中文(简体)
强制性和任择性空间
原标题:Mandatory and optional spaces

我需要这样说:

"qqq www eee" -> "qqq", "www", "eee" (case A)
"qqq   www  eee" -> "qqq", "www", "eee" (case B)

这里的图表一目前有:

grammar Query;

SHORT_NAME : ( a .. z )+ ;

name returns [String s]: SHORT_NAME { $s = $SHORT_NAME.text; };      

names 
    returns [List<String> v]
    @init { $v = new ArrayList<String>(); }
    : name1 = name { $v.add($name1.s); } 
      (    name2 = name { $v.add($name2.s); })*;

它对<条码>A的工作进行罚款,但因<条码>而失效。

line 1:4 missing SHORT_NAME at    
line 1:5 extraneous input     expecting SHORT_NAME
line 1:10 extraneous input     expecting SHORT_NAME

如何使其发挥作用的想法?

最佳回答

删除<条码>,从<条码>上删除<条码>,改为<条码>。 SPACES 注

grammar Query;

SPACES
 : (    |  	 )+
 ;

SHORT_NAME 
 : ( a .. z )+ 
 ;

name returns [String s]
 : SHORT_NAME { $s = $SHORT_NAME.text; }
 ;      

names returns [List<String> v]
@init { $v = new ArrayList<String>(); }
 : a=name { $v.add($a.s); } (SPACES b=name { $v.add($b.s); })*
 ;

或者简单地抛弃了弹性层次的空间,以便你无需将其置于贵族规则中:

grammar Query;

SPACES
 : (    |  	 )+ {skip();}
 ;

SHORT_NAME 
 : ( a .. z )+ 
 ;

name returns [String s]
 : SHORT_NAME { $s = $SHORT_NAME.text; }
 ;      

names returns [List<String> v]
@init { $v = new ArrayList<String>(); }
 : (name { $v.add($b.s); })+
 ;
问题回答

暂无回答




相关问题
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 ...

热门标签