简体   繁体   中英

Correct use of Syntactic Predicates in XText

I have a grammar with some ambuguities I need to resolve. One of the rules takes the following form:

TArg:
    anys=Anys
    | rnumb1=PNumb ".." (rnumb2=PNumb)?
;

Or this image, if you prefer

The rule Anys has the potential to start with a PNumb . I can see where the ambiguity is, but how to I tell XText to take the second path if it sees a PNumb followed by the double dot?

Presumably, if I use

TArg:
    (=>  rnumb1=PNumb ".." (rnumb2=PNumb)?)
    |anys=Anys
;

Then it will always choose the first if it sees a number, regargless of if it sees the "..", and I will run into problems.

What is the correct usage/placement of the syntactic predicate here to allow Antlr to look ahead to see if the ".." is present?

Cheers in advance.

You need to also include the '..'

TArg:
  =>(rnumb1=PNumb "..") (rnumb2=PNumb)?
  | anys=Anys
;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM