6

我仍在与 Qt 的 qmake 模棱两可的语法作斗争。

现在我找不到一种方法来描述可以包含括号的函数参数(例如正则表达式):

functionName(arg1, "arg2", ^(arg3)+$)

我试图描述这样的函数调用:

FunctionCall = Identifier space* "(" space* FunctionArgumentList? space* ")" space* eol*

FunctionArgumentList = FunctionArgumentString ((space* "," space* FunctionArgumentString)* / (blank* FunctionArgumentString)*)
FunctionArgumentString = ReplaceFunctionCall / TestFunctionCall / EnquotedString / RegularFunctionArgumentString
RegularFunctionArgumentString = RegularFunctionArgumentStringChar+
RegularFunctionArgumentStringChar = !(")" / blank / "," / quote / doublequote) SourceCharacter
SourceCharacter <- [\u0000-\uFFFC]

如何在这种语法中添加对没有引号/双引号的嵌入式括号的支持?如何区分函数参数内的括号和函数关闭一个?

有效的函数调用示例:

contains(CMAKE_INSTALL_LIBS_DIR, ^(/usr)?/lib(64)?.*)
4

1 回答 1

2

好吧,我自己找到了一个非常老套的解决方案:
只需进一步查找下一个语句。
这是使用这种方式的简化语法片段:

FunctionCall = Identifier _* "(" _* FunctionArgumentList? _* ")" _*
FunctionArgumentList = CommaSeparatedList / FunctionArgument
CommaSeparatedList = FunctionArgument (COMMA_WS FunctionArgument?)+

FunctionArgument = FunctionArgumentImpl FunctionArgumentImpl*
FunctionArgumentImpl = EnquotedString / FunctionArgumentString
FunctionArgumentString = FunctionArgumentStringChar+
FunctionArgumentStringChar = !(COMMA / QUOTE / DOUBLEQUOTE / EndOfFunction) SourceCharacter

EndOfFunction = ")" _* (
     eoi / eol
    / "=" / "+=" / "*=" / "-=" / "~="
    / "," / "." / "_"
    / "(" / ")"
    "{" / "}" / ":" / "|"
)

COMMA_WS = _ "," _
COMMA = ","
QUOTE = "'"
DOUBLEQUOTE = '"'
BACKSLASH = "\\"
_ = [ \t]

希望这对某人有用。

于 2017-12-29T20:00:49.063 回答