【问题标题】:PetitParser not distributive?PetitParser 不是分布式的?
【发布时间】:2013-03-20 14:23:34
【问题描述】:

PetitParser 中的规则是可分配的吗?

还有以下规则:

integerLiteral --> hexIntegerLiteral / octalIntegerLiteral / decimalIntegerLiteral
  hexIntegerLiteral     --> hexNumeral , (integerTypeSuffix optional)
  octalIntegerLiteral   --> octalNumeral , (integerTypeSuffix optional)
  decimalIntegerLiteral --> decimalNumeral , (integerTypeSuffix optional)

如果我将它们更改为:

integerLiteral --> (hexIntegerLiteral / octalIntegerLiteral / decimalIntegerLiteral) , (integerTypeSuffix optional)
  hexIntegerLiteral     --> hexNumeral
  octalIntegerLiteral   --> octalNumeral
  decimalIntegerLiteral --> decimalNumeral

然后0777L 不再被解析。它应该与 octalNumeral , (integerTypeSuffix optional) 或新版本中的 octalIntegerLiteral , (integerTypeSuffix optional) 匹配,但这不会发生。

【问题讨论】:

    标签: pharo petitparser


    【解决方案1】:

    是的,PetitParser 中的有序选择是可分配的。在您的示例中缺少一些上下文,所以我不知道为什么它对您不起作用。

    PetitParser 优化器会自动执行您建议的更改。重写规则(以稍微更一般的形式)定义为:

    PPOptimizer>>#postfixChoice
        <optimize>
    
        | before prefix body1 body2 postfix after |
        before := PPListPattern any.
        prefix := PPPattern any.
        body1 := PPListPattern any.
        body2 := PPListPattern any.
        postfix := PPPattern any.
        after := PPListPattern any.
        rewriter
            replace: before / (prefix , body1) / (prefix , body2) / after
            with: before / (prefix , (body1 / body2)) / after.
        rewriter
            replace: before / (body1 , postfix) / (body2 , postfix) / after
            with: before / ((body1 / body2) , postfix) / after
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 2018-02-08
      • 2020-12-07
      • 1970-01-01
      • 2020-03-31
      • 2011-02-15
      相关资源
      最近更新 更多