-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
386 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Tangram Yume on 2024/1/17. | ||
// | ||
|
||
import SwiftSyntax | ||
import SwiftParser | ||
|
||
public final class SourceConverter { | ||
public let path: String | ||
public let sourceFile: SourceFileSyntax | ||
public let converter: SourceLocationConverter | ||
|
||
public init(path: String, code: String) { | ||
self.path = path | ||
self.sourceFile = Parser.parse(source: code) | ||
self.converter = SourceLocationConverter(fileName: path, tree: sourceFile) | ||
} | ||
|
||
public init(path: String, sourceFile: SourceFileSyntax) { | ||
self.path = path | ||
self.sourceFile = sourceFile | ||
self.converter = SourceLocationConverter(fileName: path, tree: sourceFile) | ||
} | ||
|
||
public convenience init(path: String) throws { | ||
let code = try String(contentsOfFile: path, encoding: .utf8) | ||
self.init(path: path, code: code) | ||
} | ||
|
||
public func sourceLocation(_ syntax: SyntaxProtocol) -> SwiftSyntax.SourceLocation { | ||
return self.converter.location(for: syntax.positionAfterSkippingLeadingTrivia) | ||
} | ||
|
||
public func codeLocation(_ syntax: SyntaxProtocol) -> CodeLocation { | ||
return CodeLocation(path: path, location: sourceLocation(syntax), syntax: syntax) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.