How to describe function arguments in a PEG grammar

I'm still struggling with the ambiguous Qt qmake grammar.

Now I can’t find a way to describe function arguments that may contain brackets (for example, regex):

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

I tried to describe the function call as follows:

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]

How to add support for inline parentheses without quotes / double quotes in such a grammar? How to distinguish round arguments inside a function and a close function of one?

Example of a valid function call:

contains(CMAKE_INSTALL_LIBS_DIR, ^(/usr)?/lib(64)?.*)
+6
source share
1 answer

, :
.
, :

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]

, -.

+2

All Articles