简体   繁体   中英

Why is a custom SyntaxNode subclass not working with parentheses?

I have a treetop grammar like below:

grammar Addme

  rule AddExpr
    Num '+' Num
  end

  rule Num
    [0-9]+ <ExprNumber>
  end

end

This is working when I parse the expression:

g = AddmeParser.new
t = g.parse("1234+56789")

. . . there is a syntax node that matches "1234" with type ExprNumber . But, if I add parentheses to the rule like this:

rule Num
    ([0-9]+) <ExprNumber>
end

It will not match the class ExprNumber . Why would this happen?

The node has already been created inside the parentheses. A module can be mixed in, but not a class.

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