@@ -57,34 +57,42 @@ private func parseASTString(astString: String) -> [Node] {
57
57
var stack = Array < Node > ( )
58
58
var data = " "
59
59
var quoteStarted = false
60
+ var quoteChar : Character ? = nil
60
61
var sources : [ Node ] = [ ]
62
+
61
63
for char in astString. characters {
64
+
62
65
if char == " ( " && !quoteStarted {
63
66
let node = Node ( )
64
- if let chuzzledData = data. chuzzle ( ) , lastNode = stack. last where chuzzledData. characters . count > 0 {
67
+ if data. characters . count > 0 , let lastNode = stack. last, let chuzzledData = data . chuzzle ( ) {
65
68
lastNode. contents = chuzzledData
66
69
if lastNode. contents == " source_file " { sources += [ lastNode] }
67
70
}
68
71
stack. append ( node)
69
72
data = " "
70
73
} else if char == " ) " && !quoteStarted {
71
- var poppedNode : Node ?
72
- if stack. count > 0 {
73
- poppedNode = stack. removeLast ( )
74
- if let chuzzledData = data. chuzzle ( ) , poppedNode = poppedNode where chuzzledData. characters . count > 0 {
74
+ if case let poppedNode = stack. removeLast ( ) where stack. count > 0 {
75
+ if data. characters. count > 0 , let chuzzledData = data. chuzzle ( ) {
75
76
poppedNode. contents = chuzzledData
76
77
}
77
- data = " "
78
- }
79
- if let last = stack. last, let poppedNode = poppedNode {
80
- last. nodes += [ poppedNode]
78
+ stack. last!. nodes += [ poppedNode]
79
+
81
80
}
81
+ data = " "
82
82
} else {
83
83
data = data + String( char)
84
- if char == " \" " || char == " ' " {
85
- quoteStarted = !quoteStarted
86
- }
84
+ if data == " (source_file " { print ( " Yes " ) }
85
+ if char == " \" " || char == " ' " {
86
+ if quoteChar == nil {
87
+ quoteChar = char
88
+ quoteStarted = true
89
+ } else if char == quoteChar {
90
+ quoteChar = nil
91
+ quoteStarted = false
92
+ }
93
+ }
87
94
}
95
+
88
96
}
89
97
return sources
90
98
}
0 commit comments