diff --git a/grammar.lark b/grammar.lark index b5d3d60..ca4a47c 100644 --- a/grammar.lark +++ b/grammar.lark @@ -1,4 +1,4 @@ -%import common (LETTER, DIGIT, INT, CNAME, SIGNED_NUMBER, NUMBER) +%import common (CNAME, INT, SIGNED_NUMBER, NUMBER) _WHITESPACE: /\s+/ STRING: /("(?!"").*?(?" vardescriptor_set.9: VARNAME [ /\[/ [ SIGNED_NUMBER | IDENTIFIER ] /\]/ ] // conditions - ?condition: grouped_condition | ungrouped_condition - ?ungrouped_condition: operation | basic_condition + ?condition: operation_or + ?operation_or: operation_and | operation_or _WHITESPACE "or" _WHITESPACE operation_and + ?operation_and: atom_cond | operation_and _WHITESPACE "and" _WHITESPACE atom_cond + ?atom_cond: operation_not | grouped_condition | basic_condition + operation_not: "not" ( ( _WHITESPACE atom_cond ) | ( _WHITESPACE? grouped_condition ) ) ?grouped_condition.8: "(" _WHITESPACE? condition _WHITESPACE? ")" ?basic_condition: comparison | truthy_operand - ?operation: operation_not | operation_and | operation_or - operation_and: condition _WHITESPACE "and" _WHITESPACE condition - operation_or: condition _WHITESPACE "or" _WHITESPACE condition - operation_not: "not" ( ( _WHITESPACE ungrouped_condition ) | ( _WHITESPACE? grouped_condition ) ) ?complexvalue: vardescriptor_get | SIMPLEVALUE truthy_operand: vardescriptor_get comparison: ( complexvalue | listvalue ) _WHITESPACE ( /not/ _WHITESPACE )? /eq|ne|lt|gt|le|ge|contains|in|any_in|contains_any/ _WHITESPACE ( complexvalue | listvalue ) listvalue.9: "(" ( _WHITESPACE? complexvalue ( _WHITESPACE? "," _WHITESPACE? complexvalue )* )? _WHITESPACE? ")" + varvalue: content_var //#endif //#if ALLOW_COMMVARS // command: stn (send to negative) commandstn: "" content_negtag "" - commandstni: "" | ">" ) + commandstni: "" | ">" ) // ">" ending for backward compatibility // command: if - commandif.2: commandif_if commandif_elif* commandif_else? "" + commandif: commandif_if commandif_elif* commandif_else? "" commandif_if: "" ifvalue commandif_elif: "" ifvalue commandif_else: "" ifvalue - ifvalue.3: content + ifvalue: content // command: set commandset: "" ( starredvalue | commandsetcontent ) "" commandsetmodifiers: (_WHITESPACE /evaluate|ifundefined|add/ )+ - ?commandsetcontent.3: content + ?commandsetcontent: content // variable set //#if ALLOW_WILDCARDS @@ -138,25 +138,24 @@ extranetworktag: "<" /(?!ppp:)\w+:/ encontent ">" //#else starredvalue.9: "*" ( vardescriptor_get | listvalue ) //#endif - variableset.2: "${" _WHITESPACE? vardescriptor_set [ variablesetmodifiers ] _WHITESPACE? "=" [ /!/ ] ( starredvalue | varvalue ) "}" + variableset: "${" _WHITESPACE? vardescriptor_set [ variablesetmodifiers ] _WHITESPACE? "=" [ /!/ ] ( starredvalue | varvalue ) "}" variablesetmodifiers: /[+?!]+/ // command: echo commandecho: "" [ commandechodefault "" ] | "/>" ) - ?commandechodefault.3: content + ?commandechodefault: content // variable use - variableuse.2: "${" _WHITESPACE? vardescriptor_get _WHITESPACE? [ ":" varvalue ] "}" + variableuse: "${" _WHITESPACE? vardescriptor_get _WHITESPACE? [ ":" varvalue ] "}" // command: ext commandext: "" [ commandexttriggers "" ] | "/>" ) commandexttype: [/\$/] IDENTIFIER ?commandextid.2: STRING | CNAME - ?commandextparams.2: STRING | SIGNED_NUMBER + ?commandextparams: STRING | SIGNED_NUMBER ?commandextif: "if" _WHITESPACE condition ?commandexttriggers.3: content //#endif -varvalue: content_var //#if ALLOW_CHOICES or ALLOW_WILDCARDS // choices parameters (for choices and wildcards) @@ -169,7 +168,8 @@ varvalue: content_var // choice options choice: [ [ _WHITESPACE? choiceiscmd ] [ _WHITESPACE? choicelabels ] [ _WHITESPACE? choiceweight ] [ _WHITESPACE? choiceif ] _WHITESPACE? "::" ] choicevalue choiceiscmd: /%/ // the option text is a special command - choicelabels: /["']/ IDENTIFIER ( _WHITESPACE? "," _WHITESPACE? IDENTIFIER )* /["']/ + choicelabels: ( /"/ IDENTIFIER ( _WHITESPACE? "," _WHITESPACE? IDENTIFIER )* /"/ ) + | ( /'/ IDENTIFIER ( _WHITESPACE? "," _WHITESPACE? IDENTIFIER )* /'/ ) choiceweight: NUMBER choiceif: "if" _WHITESPACE condition choicevalue: content_choice @@ -177,7 +177,7 @@ varvalue: content_var //#if ALLOW_CHOICES // choices construct - choices.2: "{" [ choicesoptions_sampler | ( choicesoptions _WHITESPACE? "$$" ) ] choice ( "|" choice )* "}" + choices: "{" [ choicesoptions_sampler | ( choicesoptions _WHITESPACE? "$$" ) ] choice ( "|" choice )* "}" //#endif //#if ALLOW_WILDCARDS @@ -186,7 +186,7 @@ varvalue: content_var wcdescription: STRING // wildcards construct - wildcard.2: "__" [ choicesoptions_sampler | ( choicesoptions _WHITESPACE? "$$" ) ] wildcard_name [ wc_filter ] [ wildcardvar ] "__" + wildcard: "__" [ choicesoptions_sampler | ( choicesoptions _WHITESPACE? "$$" ) ] wildcard_name [ wc_filter ] [ wildcardvar ] "__" wc_filter_nums: IDENTIFIER | INDEX | (INDEX /-/ INDEX) //#if ALLOW_COMMVARS wildcard_name.2: ( WC_NAME_PLAIN_START | variableuse | commandecho ) ( WC_NAME_PLAIN | variableuse | commandecho )* @@ -195,15 +195,18 @@ varvalue: content_var wildcard_name.2: ( WC_NAME_PLAIN_START) WC_NAME_PLAIN* wc_filter_simple: wc_filter_nums //#endif - wc_filter: /["']/ ( [ /#/ ] wc_filter_or | ( /#?\^/ wildcard_name ) ) /["']/ + wc_filter: ( /"/ ( [ /#/ ] wc_filter_or | ( /#?\^/ wildcard_name ) ) /"/ ) + | ( /'/ ( [ /#/ ] wc_filter_or | ( /#?\^/ wildcard_name ) ) /'/ ) wc_filter_or: wc_filter_and ( _WHITESPACE? "," _WHITESPACE? wc_filter_and )* wc_filter_and: wc_filter_simple ( _WHITESPACE? "+" _WHITESPACE? wc_filter_simple )* - wildcardvar.7: "(" _WHITESPACE? vardescriptor_get _WHITESPACE? "=" varvalue ")" + wildcardvar: "(" _WHITESPACE? vardescriptor_get _WHITESPACE? "=" varvalue ")" //#if ALLOW_COMMVARS // command: setwcdeffilter commandsetwcdeffilter: "" - wc_name_str: /["']/ wildcard_name /["']/ - wc_filter_limited: /["']/ wc_filter_or /["']/ + wc_name_str: ( /"/ wildcard_name /"/ ) + | ( /'/ wildcard_name /'/ ) + wc_filter_limited: ( /"/ wc_filter_or /"/ ) + | ( /'/ wc_filter_or /'/ ) //#endif //#endif