SourceFile
public struct SourceFile : Sendable
extension SourceFile: ExpressibleByStringLiteral
extension SourceFile: Hashable
extension SourceFile: Codable
extension SourceFile: CustomStringConvertible
A Hylo source file, a synthesized fragment of Hylo source, or a fragment Hylo source embedded in a Swift string literal.
-
The notional stored properties of
self; distinguished for encoding/decoding purposes.Note
the instance is owned by a global dictionary,Storage.allInstances.Declaration
Swift
private unowned let storage: Storage -
A position in the source text.
Declaration
Swift
public typealias Index = String.Index -
The contents of the source file.
Declaration
Swift
public var text: Substring { get } -
The URL of the source file.
Declaration
Swift
public var url: URL { get } -
The start position of each line.
Declaration
Swift
private var lineStarts: [Index] { get } -
Creates an instance representing the file at
filePath.Declaration
Swift
public init(contentsOf filePath: URL) throws -
Creates an instance representing the file at
filePath.Declaration
Swift
public init(at filePath: String) throws -
Creates an instance for the
textgiven by a multiline string literal in the givenswiftFile, the literal’s textual content (the line after the opening quotes) being startLine.The text of the instance will literally be what’s in the Swift file, including its indentation and any embedded special characters, even if the literal itself is not a raw literal or has had indentation stripped by the Swift compiler.
Declaration
Swift
fileprivate init( diagnosableLiteral text: String, swiftFile: String, startLine: Int ) throws -
Creates an instance representing the at
filePath.Declaration
Swift
public init<S>(path filePath: S) throws where S : StringProtocol -
Creates a synthetic source file with the specified contents and base name.
Declaration
Swift
public init(synthesizedText text: String) -
The name of the source file, sans path qualification or extension.
Declaration
Swift
public var baseName: String { get } -
trueifselfis synthesized.Declaration
Swift
public var isSynthesized: Bool { get } -
The number of lines in the file.
Declaration
Swift
public var lineCount: Int { get } -
A range covering the whole contents of this instance.
Declaration
Swift
public var wholeRange: SourceRange { get } -
Returns a range starting and ending at
index.Declaration
Swift
public func emptyRange(at index: String.Index) -> SourceRange -
Returns the contents of the file in the specified range.
Requires
The bounds ofrangeare valid positions inself.Declaration
Swift
public subscript(range: SourceRange) -> Substring { get } -
Declaration
Swift
public func position(_ i: Index) -> SourcePosition -
Returns the position immediately before
p.Requires
pis a valid position inself.Declaration
Swift
public func position(before p: SourcePosition) -> SourcePosition -
Returns the position corresponding to the given 1-based line and column indices.
Requires
the line and column exist inself.Declaration
Swift
public func position(line: Int, column: Int) -> SourcePosition -
Returns the region of
selfcorresponding tor.Requires
ris a valid range inself.Declaration
Swift
public func range(_ r: Range<Index>) -> SourceRange -
Returns the line containing
i.Requires
iis a valid index incontents.Complexity
O(log N) where N is the number of lines inself.Declaration
Swift
public func line(containing i: Index) -> SourceLine -
Returns the line at 1-based index
lineNumber.Declaration
Swift
public func line(_ lineNumber: Int) -> SourceLine -
The bounds of given
line, including any trailing newline.Declaration
Swift
public func bounds(of line: SourceLine) -> SourceRange -
Returns the 1-based line and column numbers corresponding to
i.Requires
iis a valid index incontents.Complexity
O(log N) + O© where N is the number of lines in
selfand C is the returned column number.Declaration
Swift
func lineAndColumn(_ i: Index) -> (line: Int, column: Int) -
Declaration
Swift
public init(stringLiteral text: String) -
Declaration
Swift
public func hash(into hasher: inout Hasher) -
Declaration
Swift
public static func == (lhs: SourceFile, rhs: SourceFile) -> Bool -
The state that must be maintained on behalf of
See moreSourceFiles while they are encoded.Declaration
Swift
struct EncodingState : Sendable -
The state that must be maintained on behalf of
See moreSourceFiles while they are decoded.Declaration
Swift
struct DecodingState : Codable -
Declaration
Swift
public init(from decoder: Decoder) throws -
Declaration
Swift
public func encode(to encoder: Encoder) throws -
Declaration
Swift
public var description: String { get } -
The shared, immutable storage of a
SourceFile.
See moreunowned Storagecan be used safely anywhere, because everyStorageinstance is owned by a threadsafe global dictionary,Storage.allInstances,and never deallocated.Declaration
Swift
public final class Storage : Codable, FactoryInitializable
View on GitHub