我正在寻找一个 peg.js 语法表达式来匹配:
"variable"
# 失败"variable."
# 失败""
# 失败"variable.variable"
# 好的"variable.variable.variable.variable.variable"
#好的
我期望的输入
{PATH: "variable.variable"}
{PATH: "variable.variable.variable.variable.variable"}
示例.pegjs
start =
PATH_EXP
STRING_EXP =
chars:[0-9a-zA-Z_]+ { return chars.join(""); }
PATH_EXP =
path:(STRING_EXP "." STRING_EXP) { return {PATH: path.join("")}; }
我不知道如何使表达式重复,但也使它成为可选的。