吐嘈一下,emacs30 的 PEG 官方文档示例运行报错

我又仔细研究了一下源码, peg-parse 宏是想兼容 with-peg-rulespeg-run 两种用法,根据参数形式不同来确定使用哪种。

  • with-peg-rules 的参数形式:每个列表的第一个参数是变量名,后面是多个 pexs,变量可以引用;我称它为 rules 形式
  • peg-run 的参数形式是:多个 pexs,这种就是 pexs 形式

如果第一个参数都是 cons,没法区别这两种。当第一个参数不是cons时,就是使用 pexs 格式,否则是 rules 格式。

下面的第二个例子,第一个参数写成空字符串就可以使用啦。

;; peg-parse 参数为 rules 形式
(with-temp-buffer
  (insert "avioeuiewrhvi/* *//**/vhioehvioe")
  (goto-char (point-min))
  (peg-parse (text (+ (not two-comments) (any)) two-comments)
             (two-comments (two (peg minifycss--comment)))))

;; peg-parse 参数为 pexs 形式,第一个参数不能为 cons
(with-temp-buffer
  (insert "/* *//**/")
  (goto-char (point-min))
  (peg-parse "" (two (peg minifycss--comment))))
2 个赞