我有这样的语法:
terminator = '\n';
module.exports = grammar({
name: 'sciname',
rules: {
source_file: ($) => repeat($._sci_name),
_sci_name: ($) => seq($.uninomial, optional($.tail), terminator),
_uninomial: ($) => /[A-Z][a-z]+/,
uninomial: ($) => choice($._uninomial, seq($.genus, $.subgenus)),
genus: ($) => $._uninomial,
subgenus: ($) => seq('(', $._uninomial, ')'),
tail: ($) => /.+/,
},
});
tail
规则假设捕获之后的任何东西uninomial
。但是我在这个测试中遇到了麻烦:
=====================
Subgenus
=====================
Bubo (Bubo)
---------------------
(source_file (uninomial (genus) (subgenus)))
生产:
(source_file (uninomial) (tail))
代替
(source_file (uninomial (genus) (subgenus)))
更改优先级似乎不会影响此行为。有没有办法制定一个“包罗万象”的规则,比如tail
只有在所有其他以前的规则都失败的情况下才参与?