Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift5] grammar fixes #4388

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion swift/swift5/Swift5Lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ HASH_IMAGE_LITERAL : '#imageLiteral';
GETTER : 'getter';
SETTER : 'setter';

UNDERSCORE : '_';

Identifier:
Identifier_head Identifier_characters?
| Implicit_parameter_name
Expand Down Expand Up @@ -249,7 +251,6 @@ COLON : ':';
SEMI : ';';
LT : '<';
GT : '>';
UNDERSCORE : '_';
BANG : '!';
QUESTION : '?';
AT : '@';
Expand Down
3 changes: 2 additions & 1 deletion swift/swift5/Swift5Parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ closure_parameter_list
;

closure_parameter
: closure_parameter_name = identifier (type_annotation range_operator?)?
: UNDERSCORE? closure_parameter_name = identifier (type_annotation range_operator?)?
;

capture_list
Expand Down Expand Up @@ -1573,6 +1573,7 @@ identifier
)
| Identifier
| BACKTICK (keyword | Identifier | DOLLAR) BACKTICK
| UNDERSCORE
;

identifier_list
Expand Down
11 changes: 11 additions & 0 deletions swift/swift5/examples/Functions and Closures/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ print(mappedNumbers)
let sortedNumbers = numbers.sorted { $0 > $1 }
print(sortedNumbers)

// : Accepts trailing closure with 2 string parameters and call it
func printTwoStrings(_ closure: (String, String) -> Void) {
closure("Hello", "World")
}

//: Closure parameter name with an underscore before (closures don't have external parameter names, but underscore is allowed)
printTwoStrings { (_ x: String, _ y: String) in
print(x, y)
}




//: [Previous](@previous) | [Next](@next)
Loading