@@ -69,6 +69,9 @@ struct PendingBlockDirective {
6969 /// The location of the last character accepted into the block directive.
7070 var endLocation : SourceLocation
7171
72+ /// The pending line of the block directive
73+ var pendingLine : TrimmedLine ?
74+
7275 /// `true` if the block directive container is expecting child content,
7376 /// i.e. it has parsed an opening curly brace `{`.
7477 var isAwaitingChildContent : Bool {
@@ -164,14 +167,35 @@ struct PendingBlockDirective {
164167
165168 /// Continue parsing from the `contentsEnd` state.
166169 @discardableResult
167- mutating func parseContentsEnd( from line: TrimmedLine ) -> Bool {
170+ mutating func parseContentsEnd( from line: TrimmedLine ) -> Bool {
168171 precondition ( isAwaitingChildContent)
169172 var line = line
170173 line. lexWhitespace ( )
171174 if line. lex ( " } " ) != nil {
172175 parseState = . done
173176 endLocation = line. location!
174177 } 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+ }
175199 return false
176200 }
177201 return true
@@ -815,6 +839,9 @@ struct ParseContainerStack {
815839 push ( . blockDirective( newBlockDirective, [ ] ) )
816840 }
817841 }
842+ if let pendingLine = newBlockDirective. pendingLine {
843+ push ( . lineRun( [ pendingLine] , isInCodeFence: false ) )
844+ }
818845 if case . done = newBlockDirective. parseState {
819846 closeTop ( )
820847 }
0 commit comments