8
8
9
9
"""
10
10
# pylint: disable=missing-docstring, no-init, too-few-public-methods
11
- # pylint: disable=anomalous-unicode-escape-in-string
11
+ # pylint: disable=anomalous-unicode-escape-in-string, bad-builtin, star-args
12
+
12
13
import re
13
14
14
15
from modgrammar import (
18
19
)
19
20
from modgrammar .extras import RE
20
21
22
+
21
23
# pylint: disable=invalid-name
22
24
def RE_LITERAL (regex , * args , regex_flags = re .I | re .MULTILINE , ** kwargs ):
23
25
""" A Literal grammar which uses a regular expression instead
@@ -31,6 +33,7 @@ def RE_LITERAL(regex, *args, regex_flags=re.I | re.MULTILINE, **kwargs):
31
33
regex = re .compile (regex , regex_flags )
32
34
return RE (regex , * args , ** kwargs )
33
35
36
+
34
37
def ignore_case_literals (* args ):
35
38
""" Receive a list of strings and return a list of grammars
36
39
for each of those strings.
@@ -181,20 +184,18 @@ class FormatOperator(Grammar):
181
184
182
185
183
186
class ComparisonOperator (Grammar ):
184
- grammar = (
185
- Dash ,
186
- OR (* ignore_case_literals (
187
- "as" , "ccontains" , "ceq" , "cge" , "cgt" , "cle" , "clike" ,
188
- "clt" , "cmatch" , "cne" , "cnotcontains" , "cnotlike" ,
189
- "cnotmatch" , "contains" , "creplace" , "csplit" , "eq" ,
190
- "ge" , "gt" , "icontains" , "ieq" , "ige" , "igt" , "ile" ,
191
- "ilike" , "ilt" , "imatch" , "in" , "ine" , "inotcontains" ,
192
- "inotlike" , "inotmatch" , "ireplace" , "is" , "isnot" ,
193
- "isplit" , "join" , "le" , "like" , "lt" , "match" , "ne" ,
194
- "notcontains" , "notin" , "notlike" , "notmatch" , "replace" ,
195
- "shl" , "shr" , "split"
196
- )
197
- ))
187
+ operators = ignore_case_literals (
188
+ "as" , "ccontains" , "ceq" , "cge" , "cgt" , "cle" , "clike" ,
189
+ "clt" , "cmatch" , "cne" , "cnotcontains" , "cnotlike" ,
190
+ "cnotmatch" , "contains" , "creplace" , "csplit" , "eq" ,
191
+ "ge" , "gt" , "icontains" , "ieq" , "ige" , "igt" , "ile" ,
192
+ "ilike" , "ilt" , "imatch" , "in" , "ine" , "inotcontains" ,
193
+ "inotlike" , "inotmatch" , "ireplace" , "is" , "isnot" ,
194
+ "isplit" , "join" , "le" , "like" , "lt" , "match" , "ne" ,
195
+ "notcontains" , "notin" , "notlike" , "notmatch" , "replace" ,
196
+ "shl" , "shr" , "split"
197
+ )
198
+ grammar = (Dash , OR (* operators ))
198
199
199
200
200
201
class FileRedirectionOperator (Grammar ):
@@ -221,8 +222,12 @@ class OperatorOrPunctuator(Grammar):
221
222
"{" , "}" , "[" , "]" , "(" , ")" , "@(" , "@{" , "$(" , ";" ,
222
223
"&&" , "||" , "&" , "|" , "," , "++" , ".." , "::" , "." ,
223
224
"!" , "*" , "/" , "%" , "+" ,
224
- (Dash , OR (Dash , * ignore_case_literals ("and" , "band" , "bnot" , "bor" ,
225
- "bxor" , "not" , "or" , "xor" ))),
225
+ (Dash ,
226
+ OR (Dash ,
227
+ * ignore_case_literals (
228
+ "and" , "band" , "bnot" , "bor" ,
229
+ "bxor" , "not" , "or" , "xor"
230
+ ))),
226
231
Dash ,
227
232
AssignmentOperator ,
228
233
MergingRedirectionOperator ,
@@ -298,8 +303,10 @@ class VariableNamespace(Grammar):
298
303
299
304
300
305
class VariableScope (Grammar ):
301
- grammar = OR (VariableNamespace ,
302
- * ignore_case_literals ("global:" , "local:" , "private:" , "script:" ))
306
+ grammar = OR (
307
+ VariableNamespace ,
308
+ * ignore_case_literals ("global:" , "local:" , "private:" , "script:" )
309
+ )
303
310
304
311
305
312
class BracedVariable (Grammar ):
@@ -763,15 +770,27 @@ class ComparisonArgumentExpression(Grammar):
763
770
764
771
765
772
class BitwiseArgumentExpression (Grammar ):
766
- grammar = LIST_OF (ComparisonArgumentExpression ,
767
- sep = (OR (RE_LITERAL ("-band" ), RE_LITERAL ("-bor" ), RE_LITERAL ("-bxor" )),
768
- OPTIONAL (NewLines )))
773
+ grammar = LIST_OF (
774
+ ComparisonArgumentExpression ,
775
+ sep = (
776
+ OR (RE_LITERAL ("-band" ),
777
+ RE_LITERAL ("-bor" ),
778
+ RE_LITERAL ("-bxor" )),
779
+ OPTIONAL (NewLines )
780
+ )
781
+ )
769
782
770
783
771
784
class LogicalArgumentExpression (Grammar ):
772
- grammar = LIST_OF (BitwiseArgumentExpression ,
773
- sep = (OR (RE_LITERAL ("-and" ), RE_LITERAL ("-or" ), RE_LITERAL ("-xor" )),
774
- OPTIONAL (NewLines )))
785
+ grammar = LIST_OF (
786
+ BitwiseArgumentExpression ,
787
+ sep = (
788
+ OR (RE_LITERAL ("-and" ),
789
+ RE_LITERAL ("-or" ),
790
+ RE_LITERAL ("-xor" )),
791
+ OPTIONAL (NewLines )
792
+ )
793
+ )
775
794
776
795
777
796
class ArgumentExpressionList (Grammar ):
@@ -1066,7 +1085,9 @@ class ParameterList(Grammar):
1066
1085
1067
1086
1068
1087
class BlockName (Grammar ):
1069
- grammar = OR (* ignore_case_literals ("dynamicparam" , "begin" , "process" , "end" ))
1088
+ grammar = OR (
1089
+ * ignore_case_literals ("dynamicparam" , "begin" , "process" , "end" )
1090
+ )
1070
1091
1071
1092
1072
1093
class NamedBlock (Grammar ):
@@ -1175,7 +1196,8 @@ class DataStatement(Grammar):
1175
1196
1176
1197
class ElseIfClause (Grammar ):
1177
1198
grammar = (
1178
- Spaces , RE_LITERAL ("elseif" ), Spaces , "(" , Spaces , Pipeline , Spaces , ")" , Spaces ,
1199
+ Spaces , RE_LITERAL ("elseif" ), Spaces ,
1200
+ "(" , Spaces , Pipeline , Spaces , ")" , Spaces ,
1179
1201
StatementBlock
1180
1202
)
1181
1203
@@ -1202,7 +1224,11 @@ class LabelExpression(Grammar):
1202
1224
1203
1225
1204
1226
class FinallyClause (Grammar ):
1205
- grammar = (OPTIONAL (NewLines ), RE_LITERAL ("finally" ), Spaces , StatementBlock )
1227
+ grammar = (
1228
+ OPTIONAL (NewLines ),
1229
+ RE_LITERAL ("finally" ),
1230
+ Spaces , StatementBlock
1231
+ )
1206
1232
1207
1233
1208
1234
class CatchTypeList (Grammar ):
@@ -1212,8 +1238,12 @@ class CatchTypeList(Grammar):
1212
1238
1213
1239
class CatchClause (Grammar ):
1214
1240
grammar_whitespace_mode = "optional"
1215
- grammar = (OPTIONAL (NewLines ), RE_LITERAL ("catch" ), OPTIONAL (CatchTypeList ),
1216
- StatementBlock )
1241
+ grammar = (
1242
+ OPTIONAL (NewLines ),
1243
+ RE_LITERAL ("catch" ),
1244
+ OPTIONAL (CatchTypeList ),
1245
+ StatementBlock
1246
+ )
1217
1247
1218
1248
1219
1249
class CatchClauses (Grammar ):
@@ -1263,8 +1293,13 @@ class FunctionName(Grammar):
1263
1293
1264
1294
class FunctionStatement (Grammar ):
1265
1295
grammar = (
1266
- OR (RE_LITERAL ("function" ), RE_LITERAL ("filter" ), RE_LITERAL ("workflow" )), Spaces ,
1267
- FunctionName , Spaces , OPTIONAL (FunctionParameterDeclaration ), Spaces ,
1296
+ OR (
1297
+ RE_LITERAL ("function" ),
1298
+ RE_LITERAL ("filter" ),
1299
+ RE_LITERAL ("workflow" )
1300
+ ),
1301
+ Spaces , FunctionName , Spaces ,
1302
+ OPTIONAL (FunctionParameterDeclaration ), Spaces ,
1268
1303
"{" , Spaces , ScriptBlock , Spaces , "}"
1269
1304
)
1270
1305
@@ -1275,7 +1310,9 @@ class WhileCondition(Grammar):
1275
1310
1276
1311
class DoStatement (Grammar ):
1277
1312
grammar = (
1278
- RE_LITERAL ("do" ), Spaces , StatementBlock , Spaces , OR (RE_LITERAL ("while" ), RE_LITERAL ("until" )),
1313
+ RE_LITERAL ("do" ),
1314
+ Spaces , StatementBlock , Spaces ,
1315
+ OR (RE_LITERAL ("while" ), RE_LITERAL ("until" )),
1279
1316
Spaces , "(" , WhileCondition , Spaces , ")"
1280
1317
)
1281
1318
0 commit comments