PEG语法来解析可选内容

时间:2012-06-12 10:22:53

标签: ruby treetop peg

任何人都可以告诉我如何在支持两者的Treetop上编写语法:

system u AAA1 car=5, motor=4

system u car=5, motor=4

1 个答案:

答案 0 :(得分:2)

您想要使用“可选表达式”(请参阅​​this page约60%):

grammar Sokmesa
  rule line
    "system" wsp+ marker wsp+ (category wsp+)? attributelist
  end
  rule category
    "AAA1" # Or whatever
  end
  # Add rules for 'marker', 'wsp', and 'attributelist' here
end