@@ -69,6 +69,9 @@ struct PendingBlockDirective {
69
69
/// The location of the last character accepted into the block directive.
70
70
var endLocation : SourceLocation
71
71
72
+ /// The pending line of the block directive
73
+ var pendingLine : TrimmedLine ?
74
+
72
75
/// `true` if the block directive container is expecting child content,
73
76
/// i.e. it has parsed an opening curly brace `{`.
74
77
var isAwaitingChildContent : Bool {
@@ -164,14 +167,35 @@ struct PendingBlockDirective {
164
167
165
168
/// Continue parsing from the `contentsEnd` state.
166
169
@discardableResult
167
- mutating func parseContentsEnd( from line: TrimmedLine ) -> Bool {
170
+ mutating func parseContentsEnd( from line: TrimmedLine ) -> Bool {
168
171
precondition ( isAwaitingChildContent)
169
172
var line = line
170
173
line. lexWhitespace ( )
171
174
if line. lex ( " } " ) != nil {
172
175
parseState = . done
173
176
endLocation = line. location!
174
177
} else {
178
+ // If there is still some content on this line
179
+ // Consider them to be lineRun
180
+ // "@xx { yy": "yy" will be ignored
181
+ // "@xx { yy }": "yy" will be parsed
182
+ // "@xx { yy } zz }" "yy } zz" will be parsed
183
+
184
+ var reversedRemainingContent = TrimmedLine ( Substring ( line. text. reversed ( ) ) , source: line. source, lineNumber: line. lineNumber)
185
+ if !line. text. isEmpty,
186
+ reversedRemainingContent. lex ( " } " ) != nil {
187
+ let trailingWhiteSpaceCount = reversedRemainingContent. lexWhitespace ( ) ? . text. count ?? 0
188
+ let textCount = line. text. count - trailingWhiteSpaceCount - 1
189
+ let leadingSpacingCount = line. untrimmedText. count - textCount - trailingWhiteSpaceCount - 1
190
+ innerIndentationColumnCount = leadingSpacingCount // Should we add a new property for this kind of usage?
191
+
192
+ let startIndex = line. untrimmedText. startIndex
193
+ let endIndex = line. untrimmedText. index ( startIndex, offsetBy: leadingSpacingCount)
194
+ let newLine = line. untrimmedText. replacingCharacters ( in: startIndex..< endIndex, with: String ( repeating: " " , count: leadingSpacingCount) ) . dropLast ( trailingWhiteSpaceCount + 1 )
195
+ pendingLine = TrimmedLine ( newLine. dropFirst ( 0 ) , source: line. source, lineNumber: line. lineNumber)
196
+ parseState = . done
197
+ endLocation = SourceLocation ( line: line. lineNumber ?? 0 , column: line. untrimmedText. count + 1 , source: line. source)
198
+ }
175
199
return false
176
200
}
177
201
return true
@@ -815,6 +839,9 @@ struct ParseContainerStack {
815
839
push ( . blockDirective( newBlockDirective, [ ] ) )
816
840
}
817
841
}
842
+ if let pendingLine = newBlockDirective. pendingLine {
843
+ push ( . lineRun( [ pendingLine] , isInCodeFence: false ) )
844
+ }
818
845
if case . done = newBlockDirective. parseState {
819
846
closeTop ( )
820
847
}
0 commit comments