Skip to content

Commit

Permalink
Add swift 5.9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kenji21 committed Sep 29, 2023
1 parent ef34553 commit e2547c3
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 0 deletions.
Expand Up @@ -191,6 +191,7 @@ declaration
| constantDeclaration ';'?
| variableDeclaration ';'?
| typealiasDeclaration ';'?
| macroDeclaration ';'?
| functionDeclaration ';'?
| enumDeclaration ';'?
| structDeclaration ';'?
Expand Down Expand Up @@ -277,6 +278,10 @@ typealiasHead : attributes? accessLevelModifier? 'typealias' typealiasName gener
typealiasName : identifier ;
typealiasAssignment : '=' sType ;

// GRAMMAR OF A MACRO DECLARATION

macroDeclaration: '#' identifier ;

// GRAMMAR OF A FUNCTION DECLARATION

/* HACK: functionBody? is intentionally not used to force the parser to try and match a functionBody first
Expand Down
Expand Up @@ -62,6 +62,11 @@ public void testSwift56() {
doTest("Swift5.6");
}

@Test
public void testSwift59() {
doTest("Swift5.9");
}

@Test
public void testStackoverflowOnLongLiteral() {
doTest("Issue628");
Expand Down
@@ -0,0 +1,37 @@
import SwiftUI

struct ContentView: View {
var body: some View {
TabBarView()
}
}

#Preview {
ContentView()
}

// https://www.swift.org/blog/swift-5.9-released/
// Macors
let _: Font = #fontLiteral(name: "SF Mono", size: 14, weight: .regular)

// Parameter packs
func all<each Wrapped>(_ optional: repeat (each Wrapped)?) -> (repeat each Wrapped)?

func useAll() {
if let (int, double, string, bool) = all(optionalInt, optionalDouble, optionalString, optionalBool) {
print(int, double, string, bool)
}
else {
print("got a nil")
}
}

// return value on if/else if/else
statusBar.text = if !hasConnection { "Disconnected" }
else if let error = lastError { error.localizedDescription }
else { "Ready" }

// https://docs.swift.org/swift-book/documentation/the-swift-programming-language/macros/
@attached(member)
@attached(conformance)
public macro OptionSet<RawType>() = #externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
@@ -0,0 +1,199 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[import] 1 6
[SwiftUI] 8 14
L3
[struct] 1 6
[ContentView] 8 18
[:] 19 19
[View] 21 24
[{] 26 26
L4
[var] 5 7
[body] 9 12
[:] 13 13
[some] 15 18
[View] 20 23
[{] 25 25
L5
[TabBarView] 9 18
[(] 19 19
[)] 20 20
L6
[}] 5 5
L7
[}] 1 1
L9
[#] 1 1
[Preview] 2 8
[{] 10 10
L10
[ContentView] 5 15
[(] 16 16
[)] 17 17
L11
[}] 1 1
L15
[let] 1 3
[_] 5 5
[:] 6 6
[Font] 8 11
[=] 13 13
[#] 15 15
[fontLiteral] 16 26
[(] 27 27
[name] 28 31
[:] 32 32
["SF Mono"] 34 42
[,] 43 43
[size] 45 48
[:] 49 49
[14] 51 52
[,] 53 53
[weight] 55 60
[:] 61 61
[.] 63 63
[regular] 64 70
[)] 71 71
L18
[func] 1 4
[all] 6 8
[<] 9 9
[each] 10 13
[Wrapped] 15 21
[>] 22 22
[(] 23 23
[_] 24 24
[optional] 26 33
[:] 34 34
[repeat] 36 41
[(] 43 43
[each] 44 47
[Wrapped] 49 55
[)] 56 56
[?] 57 57
[)] 58 58
[->] 60 61
[(] 63 63
[repeat] 64 69
[each] 71 74
[Wrapped] 76 82
[)] 83 83
[?] 84 84
L20
[func] 1 4
[useAll] 6 11
[(] 12 12
[)] 13 13
[{] 15 15
L21
[if] 5 6
[let] 8 10
[(] 12 12
[int] 13 15
[,] 16 16
[double] 18 23
[,] 24 24
[string] 26 31
[,] 32 32
[bool] 34 37
[)] 38 38
[=] 40 40
[all] 42 44
[(] 45 45
[optionalInt] 46 56
[,] 57 57
[optionalDouble] 59 72
[,] 73 73
[optionalString] 75 88
[,] 89 89
[optionalBool] 91 102
[)] 103 103
[{] 105 105
L22
[print] 5 9
[(] 10 10
[int] 11 13
[,] 14 14
[double] 16 21
[,] 22 22
[string] 24 29
[,] 30 30
[bool] 32 35
[)] 36 36
L23
[}] 5 5
L24
[else] 5 8
[{] 10 10
L25
[print] 5 9
[(] 10 10
["got a nil"] 11 21
[)] 22 22
L26
[}] 5 5
L27
[}] 1 1
L30
[statusBar] 1 9
[.] 10 10
[text] 11 14
[=] 16 16
[if] 18 19
[!] 21 21
[hasConnection] 22 34
[{] 36 36
["Disconnected"] 38 51
[}] 53 53
L31
[else] 18 21
[if] 23 24
[let] 26 28
[error] 30 34
[=] 36 36
[lastError] 38 46
[{] 48 48
[error] 50 54
[.] 55 55
[localizedDescription] 56 75
[}] 77 77
L32
[else] 18 21
[{] 23 23
["Ready"] 25 31
[}] 33 33
L35
[@] 1 1
[attached] 2 9
[(] 10 10
[member] 11 16
[)] 17 17
L36
[@] 1 1
[attached] 2 9
[(] 10 10
[conformance] 11 21
[)] 22 22
L37
[public] 1 6
[macro] 8 12
[OptionSet] 14 22
[<] 23 23
[RawType] 24 30
[>] 31 31
[(] 32 32
[)] 33 33
[=] 35 35
[#] 37 37
[externalMacro] 38 50
[(] 51 51
[module] 52 57
[:] 58 58
["SwiftMacros"] 60 72
[,] 73 73
[type] 75 78
[:] 79 79
["OptionSetMacro"] 81 96
[)] 97 97
EOF

0 comments on commit e2547c3

Please sign in to comment.