diff --git a/lang/semgrep-grammars/src/semgrep-swift/grammar.js b/lang/semgrep-grammars/src/semgrep-swift/grammar.js index 743b7dda..3b5276ee 100644 --- a/lang/semgrep-grammars/src/semgrep-swift/grammar.js +++ b/lang/semgrep-grammars/src/semgrep-swift/grammar.js @@ -83,5 +83,11 @@ module.exports = grammar(base_grammar, { field("suffix", $.semgrep_ellipsis), ), ), + + parameter: ($, previous) => choice ( + previous, + $.semgrep_ellipsis, + $.semgrep_ellipsis_metavar + ) } }); diff --git a/lang/semgrep-grammars/src/semgrep-swift/test/corpus/semgrep.txt b/lang/semgrep-grammars/src/semgrep-swift/test/corpus/semgrep.txt index 5b483312..f55c958a 100644 --- a/lang/semgrep-grammars/src/semgrep-swift/test/corpus/semgrep.txt +++ b/lang/semgrep-grammars/src/semgrep-swift/test/corpus/semgrep.txt @@ -21,9 +21,60 @@ Unbounded range operator (source_file (additive_expression - (tuple_expression (fully_open_range)) + (tuple_expression + (fully_open_range)) (integer_literal))) +================================================================================ +Parameter Ellipsis +================================================================================ + +func $F(..., $X: $T, ...) { + ... +} + +-------------------------------------------------------------------------------- + +(source_file + (function_declaration + (simple_identifier) + (parameter + (semgrep_ellipsis)) + (parameter + (simple_identifier) + (user_type + (type_identifier))) + (parameter + (semgrep_ellipsis)) + (function_body + (statements + (fully_open_range))))) + +================================================================================ +Parameter Metavariable Ellipsis +================================================================================ + +func $F($...ARGS1, $X: $T, $...ARGS2) { + ... +} + +-------------------------------------------------------------------------------- + +(source_file + (function_declaration + (simple_identifier) + (parameter + (semgrep_ellipsis_metavar)) + (parameter + (simple_identifier) + (user_type + (type_identifier))) + (parameter + (semgrep_ellipsis_metavar)) + (function_body + (statements + (fully_open_range))))) + ================================================================================ Argument Ellipsis ================================================================================ @@ -37,14 +88,19 @@ foo(..., 1, ...); (call_expression (simple_identifier) (call_suffix - (value_arguments (value_argument (fully_open_range))))) + (value_arguments + (value_argument + (fully_open_range))))) (call_expression (simple_identifier) (call_suffix (value_arguments - (value_argument (fully_open_range)) - (value_argument (integer_literal)) - (value_argument (fully_open_range)))))) + (value_argument + (fully_open_range)) + (value_argument + (integer_literal)) + (value_argument + (fully_open_range)))))) ================================================================================ Ellipsis Metavariable @@ -60,14 +116,19 @@ $...FOO + 1; (call_expression (simple_identifier) (call_suffix - (value_arguments (value_argument (semgrep_ellipsis_metavar))))) + (value_arguments + (value_argument + (semgrep_ellipsis_metavar))))) (call_expression (simple_identifier) (call_suffix (value_arguments - (value_argument (semgrep_ellipsis_metavar)) - (value_argument (integer_literal)) - (value_argument (semgrep_ellipsis_metavar))))) + (value_argument + (semgrep_ellipsis_metavar)) + (value_argument + (integer_literal)) + (value_argument + (semgrep_ellipsis_metavar))))) (additive_expression (semgrep_ellipsis_metavar) (integer_literal))) @@ -98,13 +159,16 @@ func foo() { } (function_declaration (simple_identifier) (type_parameters - (type_parameter (semgrep_ellipsis))) + (type_parameter + (semgrep_ellipsis))) (function_body)) (function_declaration (simple_identifier) (type_parameters - (type_parameter (type_identifier)) - (type_parameter (semgrep_ellipsis))) + (type_parameter + (type_identifier)) + (type_parameter + (semgrep_ellipsis))) (function_body))) ================================================================================ @@ -115,7 +179,10 @@ Deep Ellipsis -------------------------------------------------------------------------------- -(source_file (semgrep_deep_ellipsis (integer_literal) (custom_operator))) +(source_file + (semgrep_deep_ellipsis + (integer_literal) + (custom_operator))) ================================================================================ Deep Ellipsis with custom operator (should not parse, but does because of a hack @@ -126,7 +193,10 @@ necessary to work around custom operators getting scanned by the custom scanner) -------------------------------------------------------------------------------- -(source_file (semgrep_deep_ellipsis (integer_literal) (custom_operator))) +(source_file + (semgrep_deep_ellipsis + (integer_literal) + (custom_operator))) ================================================================================ Deep Ellipsis with custom operator (this parses due to parens) @@ -155,10 +225,14 @@ class ClassName { -------------------------------------------------------------------------------- -(source_file (class_declaration (type_identifier) (class_body (semgrep_ellipsis)))) +(source_file + (class_declaration + (type_identifier) + (class_body + (semgrep_ellipsis)))) ================================================================================ -Class Ellipsis Sandwiched +Class Ellipsis Sandwiched ================================================================================ class ClassName { @@ -169,7 +243,17 @@ class ClassName { -------------------------------------------------------------------------------- -(source_file (class_declaration (type_identifier) (class_body (semgrep_ellipsis) (property_declaration (value_binding_pattern) (pattern (simple_identifier)) (integer_literal)) (semgrep_ellipsis)))) +(source_file + (class_declaration + (type_identifier) + (class_body + (semgrep_ellipsis) + (property_declaration + (value_binding_pattern) + (pattern + (simple_identifier)) + (integer_literal)) + (semgrep_ellipsis)))) ================================================================================ Statement Ellipsis with semicolon