使用 Pest.rs,如果 PUSH 是可选的,我如何避免 'peek was called on empty stack'?

Using Pest.rs, how can I avoid 'peek was called on empty stack' if the PUSH is optional?

Pest.rs 具有推入和查看堆栈的能力。当用户给出定界符时,这很有用,例如 Perl 和 PostgreSQL 中的自定义引号(双美元语法)。如果该项目可能不在堆栈中,我该怎么做。例如,Exim 配置文件指出,

It is also possible to use newline and other control characters (those with code values less than 32, plus DEL) as separators in lists. Such separators must be provided literally at the time the list is processed. For options that are string-expanded, you can write the separator using a normal escape sequence. This will be processed by the expander before the string is interpreted as a list. For example, if a newline-separated list of domains is generated by a lookup, you can process it directly by a line such as this:

domains = <\n ${lookup mysql{.....}}

您可以在此处看到覆盖默认分隔符 : 的标记 <\n 是可选的。你可以在这里看到语法本质上是,

list_sep        = ${ "<" ~ (!WHITE_SPACE ~ ANY) }
list            = {
  list_type
  ~ key
  ~ "="
  ~ PUSH(list_sep)?
  ~ !(PEEK ~ ANY)+
  ~ (PEEK ~ !(PEEK ~ ANY))*
}

但是当我 运行 我得到时,

peek was called on empty stack

是否可以通过 PEG 提供此操作,以便将列表作为字符串呈现给用户,但作为元素标记的实际列表?

我开始做的一种方法是确保 PUSH 始终发生。它甚至看起来像一个可选的 PUSH 应该是一个编译器错误,

而不是

~ PUSH(list_sep)?

这样做,

~ PUSH(list_sep?)