gpt4 book ai didi

python - 使用 pyparsing 解析键值对,其中值可能会持续多行

转载 作者:太空宇宙 更新时间:2023-11-03 14:17:17 25 4
gpt4 key购买 nike

如何使用 pyparsing 解析如下所示的关键属性定义?

some_key a b c d
other_key /some/path /some/other/path.pl \
'$SOME_ENV_VAR$' \
'$OTHER_ENV_VAR$'

此示例中的键是 some_keyother_key。值是行的其余部分,包括键名称后面的空格后的 [\t],以及使用 \ 继续行的选项。

我对pyparsing比较陌生,这超出了我目前的能力。

最佳答案

source code对于 pyparsing (例如 cppStyleComment )很有启发性,以下内容现在对我有用:

name = pp.Word(pp.alphas + '_', pp.alphanums + '_')
value = pp.Regex(r'(?:[^\n]*\\\n)*[^\n]*')
definition = name + value

关于python - 使用 pyparsing 解析键值对,其中值可能会持续多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48171858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com