Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个语法标记指定为:
list_value = Suppress(oneOf("[ (")) + Group( delimitedList(string_value | int_value))("list") + Suppress(oneOf("] )"))
然而,这显然允许(foo, bar]
(foo, bar]
如何强制列表开始和结束字符必须匹配?
您可以在两个规则之间选择一个列表:一个用于括号,一个用于方括号。感谢您提出 pyparsing。我喜欢。我对你的问题的回答是:
delim_value = Group(delimitedList(string_value | int_value))("list") list_value = Or( (Suppress("[") + delim_value + Suppress("]"), Suppress("(") + delim_value + Suppress(")")) )