Compare changes

Choose any two refs to compare.

+1
.gitignore
···
#
# SPDX-License-Identifier: MPL-2.0
+
.jj/*
.DS_Store
/.build
/Packages
+2 -11
Package.swift
···
)
],
dependencies: [
-
// .package(url: "https://github.com/ChimeHQ/LanguageServer", branch: "main"),
-
.package(url: "https://github.com/ChimeHQ/LanguageServerProtocol", branch: "main"),
-
.package(url: "https://github.com/apple/swift-llbuild2.git", branch: "main"),
-
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0")
+
.package(url: "https://github.com/apple/swift-llbuild2.git", branch: "main")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
···
name: "PterodactylKernel",
),
.target(
-
name: "PterodactylSyntax",
-
dependencies: [
-
.product(name: "Algorithms", package: "swift-algorithms"),
-
"LanguageServerProtocol"
-
]
+
name: "PterodactylSyntax"
),
.target(
name: "PterodactylBuild",
dependencies: [
-
"PterodactylSyntax",
.product(name: "llbuild2fx", package: "swift-llbuild2")
]
),
···
name: "PterodactylBuildTests",
dependencies: [
"PterodactylBuild",
-
"PterodactylSyntax",
.product(name: "llbuild2fx", package: "swift-llbuild2")
]
),
-15
Sources/PterodactylBuild/FXValue+Conformances.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
import llbuild2fx
-
import PterodactylSyntax
-
-
extension SyntaxTree: FXValue {}
-
extension Token: FXValue {}
-
extension Graph: FXValue where Vertex: Codable {}
-
-
extension String: @retroactive FXValue {}
-
extension Set: @retroactive FXValue where Element: Codable {}
-
extension LLBDataID: @retroactive FXValue {}
+34
Sources/PterodactylBuild/Keys/AnalyseImports.swift
···
+
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
+
//
+
// SPDX-License-Identifier: MPL-2.0
+
+
import Foundation
+
import TSCBasic
+
import llbuild2fx
+
+
extension Keys {
+
struct AnalyseImports: BuildKey {
+
typealias ValueType = [UnitName]
+
let blobId: LLBDataID
+
+
func computeValue(_ ctx: BuildContext<Self>) async throws -> [UnitName] {
+
let contents = try await ctx.load(blobId)
+
let code = try await String(decoding: Data(ctx.read(blob: contents.blob!)), as: UTF8.self)
+
+
var results: [UnitName] = []
+
let lines = code.split(separator: "\n", omittingEmptySubsequences: false)
+
+
for line in lines {
+
let trimmed = line.trimmingCharacters(in: .whitespaces)
+
guard trimmed.hasPrefix("import ") else { continue }
+
let parts = trimmed.split(separator: " ", maxSplits: 1, omittingEmptySubsequences: true)
+
if parts.count == 2 {
+
let name = parts[1].trimmingCharacters(in: .whitespaces)
+
results.append(UnitName(name: name))
+
}
+
}
+
+
return results
+
}
+
}
+
}
-22
Sources/PterodactylBuild/Keys/Blob-local operations/BlobContents.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
import TSCBasic
-
import llbuild2fx
-
-
extension Keys {
-
struct BlobContents: BuildKey {
-
typealias ValueType = String
-
-
let blobId: LLBDataID
-
-
static let versionDependencies: [any FXVersioning.Type] = []
-
-
func computeValue(_ ctx: BuildContext<Self>) async throws -> String {
-
let contents = try await ctx.load(blobId)
-
return try await String(decoding: Data(ctx.read(blob: contents.blob!)), as: UTF8.self)
-
}
-
}
-
}
-65
Sources/PterodactylBuild/Keys/Blob-local operations/BlobImports.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
import TSCBasic
-
import llbuild2fx
-
import PterodactylSyntax
-
-
private struct ImportParser {
-
private var lexer: PterodactylSyntax.Lexer
-
public private(set) var imports: [String] = []
-
-
public init(input: String) {
-
self.lexer = PterodactylSyntax.Lexer(input: input)
-
}
-
-
public mutating func parseHeader() {
-
while true {
-
guard let token = nextSignificantToken() else { return }
-
switch token.kind {
-
case .keyword(.import): parseImportStatement()
-
default: return
-
}
-
}
-
}
-
-
/// Returns the next non-whitespace token.
-
private mutating func nextSignificantToken() -> Token? {
-
var token = lexer.nextToken()
-
while token?.kind.isTrivia == true {
-
token = lexer.nextToken()
-
}
-
-
guard let token else { return nil}
-
return Token(kind: token.kind, text: token.text)
-
}
-
-
/// Parses a single `import xyz` line.
-
private mutating func parseImportStatement() {
-
guard let next = nextSignificantToken() else { return }
-
guard next.kind == .identifier else { return }
-
imports.append(next.text)
-
}
-
}
-
-
-
extension Keys {
-
struct BlobImports: BuildKey {
-
typealias ValueType = [UnitName]
-
let blobId: LLBDataID
-
-
static let versionDependencies: [any FXVersioning.Type] = [BlobContents.self]
-
-
func computeValue(_ ctx: BuildContext<Self>) async throws -> [UnitName] {
-
let code = try await ctx.request(BlobContents(blobId: blobId))
-
var importParser = ImportParser(input: code)
-
importParser.parseHeader()
-
-
return importParser.imports.map { name in
-
UnitName(basename: name)
-
}
-
}
-
}
-
}
-26
Sources/PterodactylBuild/Keys/Blob-local operations/BlobSyntaxTree.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
import PterodactylSyntax
-
import TSCBasic
-
import llbuild2fx
-
-
extension Keys {
-
struct BlobSyntaxTree: BuildKey {
-
typealias ValueType = SyntaxTree
-
-
let blobId: LLBDataID
-
-
static let versionDependencies: [any FXVersioning.Type] = [BlobContents.self, BlobTokens.self]
-
-
func computeValue(_ ctx: BuildContext<Self>) async throws -> ValueType {
-
let code = try await ctx.request(BlobContents(blobId: blobId))
-
let tokens = try await ctx.request(BlobTokens(blobId: blobId))
-
var parser = Parser(source: code, tokens: tokens)
-
PterodactylSyntax.Document.parse(&parser)
-
return parser.tree
-
}
-
}
-
}
-25
Sources/PterodactylBuild/Keys/Blob-local operations/BlobTokens.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
import TSCBasic
-
import llbuild2fx
-
import PterodactylSyntax
-
-
extension Keys {
-
struct BlobTokens: BuildKey {
-
typealias ValueType = [Token]
-
-
let blobId: LLBDataID
-
-
static let versionDependencies: [any FXVersioning.Type] = [BlobContents.self]
-
-
func computeValue(_ ctx: BuildContext<Self>) async throws -> ValueType {
-
let code = try await ctx.request(BlobContents(blobId: blobId))
-
var lexer = PterodactylSyntax.Lexer(input: code)
-
let flatTokens = lexer.tokenize()
-
return BlockLayoutProcessor(tokens: flatTokens).layout()
-
}
-
}
-
}
-1
Sources/PterodactylBuild/Keys/Blob-local operations/README.md
···
-
Certain operations do not require knowledge of the entire source tree, only a specific blob inside the source tree. These include import analysis, tokenisation, line maps, parsing, etc.
+4 -2
Sources/PterodactylBuild/Keys/DependencyGraphOfSourceTree.swift
···
import TSCBasic
import llbuild2fx
+
extension Graph: FXValue where Vertex: Codable {}
+
extension Keys {
struct DependencyGraphOfSourceTree: BuildKey {
typealias ValueType = Graph<UnitName>
let sourceTreeId: LLBDataID
-
static let versionDependencies: [any FXVersioning.Type] = [Keys.UnitMapOfSourceTree.self, Keys.BlobImports.self]
+
static let versionDependencies: [any FXVersioning.Type] = [Keys.UnitMapOfSourceTree.self, Keys.AnalyseImports.self]
func computeValue(_ ctx: BuildContext<Self>) async throws -> Graph<UnitName> {
let unitMap = try await ctx.request(Keys.UnitMapOfSourceTree(sourceTreeId: sourceTreeId))
···
for (unitName, unitInfo) in unitMap.units {
if edges[unitName] == nil { edges[unitName] = [] }
-
let imports = try await ctx.request(Keys.BlobImports(blobId: unitInfo.blobId))
+
let imports = try await ctx.request(Keys.AnalyseImports(blobId: unitInfo.blobId))
for importedUnitName in imports {
edges[unitName]!.insert(importedUnitName)
}
+7
Sources/PterodactylBuild/Keys/Keys.swift
···
+
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
+
//
+
// SPDX-License-Identifier: MPL-2.0
+
+
import Foundation
+
+
enum Keys {}
+6 -4
Sources/PterodactylBuild/Keys/NarrowSourceTree.swift
···
extension Keys {
/// Narrows a source tree to just the transitive dependencies of a given unit
struct NarrowSourceTree: BuildKey {
-
typealias ValueType = LLBDataID
-
+
struct ValueType: Codable, FXValue {
+
let sourceTreeId: LLBDataID
+
}
+
let sourceTreeId: LLBDataID
let unitName: UnitName
static let versionDependencies: [any FXVersioning.Type] = [TransitiveDependencies.self, UnitMapOfSourceTree.self]
func computeValue(_ ctx: BuildContext<Self>) async throws -> ValueType {
-
let dependencies = try await ctx.request(TransitiveDependencies(sourceTreeId: sourceTreeId, unitName: unitName))
+
let dependencies = try await ctx.request(TransitiveDependencies(sourceTreeId: sourceTreeId, unitName: unitName)).dependencies
let unitMap = try await ctx.request(UnitMapOfSourceTree(sourceTreeId: sourceTreeId))
var sourceTree = try await LLBCASFileTree.load(id: sourceTreeId, in: ctx)
···
}
}
-
return sourceTree.id
+
return ValueType(sourceTreeId: sourceTree.id)
}
}
}
+32
Sources/PterodactylBuild/Keys/SourceCode.swift
···
+
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
+
//
+
// SPDX-License-Identifier: MPL-2.0
+
+
import Foundation
+
import TSCBasic
+
import llbuild2fx
+
+
extension Keys {
+
struct SourceCode: BuildKey {
+
struct ValueType: Codable, FXValue {
+
let code: String
+
}
+
+
enum SourceCodeError: Error {
+
case unitNotFound
+
}
+
+
let sourceTreeId: LLBDataID
+
let unitName: UnitName
+
+
static let versionDependencies: [any FXVersioning.Type] = [UnitMapOfSourceTree.self]
+
+
func computeValue(_ ctx: BuildContext<Self>) async throws -> ValueType {
+
let unitMap = try await ctx.request(UnitMapOfSourceTree(sourceTreeId: sourceTreeId))
+
guard let unitInfo = unitMap.units[unitName] else { throw SourceCodeError.unitNotFound }
+
let contents = try await ctx.load(unitInfo.blobId)
+
let code = try await String(decoding: Data(ctx.read(blob: contents.blob!)), as: UTF8.self)
+
return ValueType(code: code)
+
}
+
}
+
}
+4 -2
Sources/PterodactylBuild/Keys/TransitiveDependencies.swift
···
extension Keys {
struct TransitiveDependencies: BuildKey {
-
typealias ValueType = Set<UnitName>
+
struct ValueType: Codable, FXValue {
+
var dependencies: Set<UnitName>
+
}
let sourceTreeId: LLBDataID
let unitName: UnitName
···
func computeValue(_ ctx: BuildContext<Self>) async throws -> ValueType {
let graph = try await ctx.request(Keys.DependencyGraphOfSourceTree(sourceTreeId: sourceTreeId))
-
return graph.verticesReachableFrom(unitName)
+
return ValueType(dependencies: graph.verticesReachableFrom(unitName))
}
}
}
-7
Sources/PterodactylBuild/Keys.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum Keys {}
+5 -5
Sources/PterodactylBuild/Types/UnitName.swift
···
// SPDX-License-Identifier: MPL-2.0
import Foundation
-
import TSCBasic
import llbuild2fx
+
import TSCBasic
struct UnitName: Codable, Equatable, Hashable {
-
var basename: String
+
var name: String
}
extension UnitName: FXValue {}
extension UnitName {
-
static func fromPath(_ path: AbsolutePath) -> Self {
-
Self(basename: path.basenameWithoutExt)
-
}
+
static func fromPath(_ path: AbsolutePath) -> Self {
+
Self(name: path.basenameWithoutExt)
+
}
}
-100
Sources/PterodactylSyntax/BlockLayoutProcessor.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
fileprivate struct TokenLocation {
-
let startLine: Int
-
let startColumn: Int
-
}
-
-
fileprivate struct LocatedToken {
-
let token: Token
-
let location: TokenLocation
-
let lines: [String.SubSequence]
-
-
init(token: Token, location: TokenLocation) {
-
self.token = token
-
self.location = location
-
self.lines = token.text.split(separator: "\n", omittingEmptySubsequences: false)
-
}
-
-
var nextLocation: TokenLocation {
-
let startLine = location.startLine + lines.count - 1
-
let startColumn = if lines.count > 1 { lines.last!.utf16.count } else { lines.last?.utf16.count ?? location.startColumn }
-
return TokenLocation(startLine: startLine, startColumn: startColumn)
-
}
-
}
-
-
public struct BlockLayoutProcessor {
-
private let locatedTokens: [LocatedToken]
-
-
public init(tokens: [Token]) {
-
var locatedTokens: [LocatedToken] = []
-
var location = TokenLocation(startLine: 0, startColumn: 0)
-
for token in tokens {
-
let locatedToken = LocatedToken(token: token, location: location)
-
locatedTokens.append(locatedToken)
-
location = locatedToken.nextLocation
-
}
-
-
self.locatedTokens = locatedTokens
-
}
-
-
-
public func layout() -> [Token] {
-
var result: [Token] = []
-
var indentStack: [Int] = [0]
-
var previousLine = 0
-
var firstTokenInBlock = false
-
-
for (index, locatedToken) in locatedTokens.enumerated() {
-
guard locatedToken.token.kind != .eof else { break }
-
guard locatedToken.token.kind.canDetermineLayoutColumn else {
-
result.append(locatedToken.token)
-
continue
-
}
-
-
if locatedToken.location.startLine > previousLine {
-
while indentStack.count > 1 && locatedToken.location.startColumn < indentStack.last! {
-
indentStack.removeLast()
-
result.append(Token(kind: .blockEnd, text: ""))
-
}
-
-
if !firstTokenInBlock && indentStack.count > 1 && locatedToken.location.startColumn == indentStack.last! {
-
result.append(Token(kind: .blockSep, text: ""))
-
}
-
}
-
-
result.append(locatedToken.token)
-
-
if locatedToken.token.kind.isBlockHerald {
-
firstTokenInBlock = true
-
-
if let nextToken = locatedTokens[index...].first(where: { $0.location.startLine > locatedToken.location.startLine && $0.token.kind.canDetermineLayoutColumn }) {
-
result.append(Token(kind: .blockBegin, text: ""))
-
indentStack.append(nextToken.location.startColumn)
-
} else {
-
result.append(Token(kind: .blockBegin, text: ""))
-
result.append(Token(kind: .blockEnd, text: ""))
-
}
-
} else {
-
firstTokenInBlock = false
-
}
-
-
previousLine = locatedToken.location.startLine
-
}
-
-
while indentStack.count > 1 {
-
indentStack.removeLast()
-
result.append(Token(kind: .blockEnd, text: ""))
-
}
-
-
if let eof = locatedTokens.last, eof.token.kind == .eof {
-
result.append(eof.token)
-
}
-
-
return result
-
}
-
}
+16 -44
Sources/PterodactylSyntax/Cursor.swift
···
// SPDX-License-Identifier: MPL-2.0
import Foundation
-
import LanguageServerProtocol
-
-
extension SyntaxTree {
-
public final class Cursor {
-
public let lineMap: LineMap
-
public let node: SyntaxTree.Child
-
public let utf16Offset: Int
-
-
public private(set) lazy var children: [Cursor] = {
-
var children: [Cursor] = []
-
var utf16Offset = utf16Offset
-
for childNode in node.children {
-
children.append(Self(lineMap: lineMap, node: childNode, utf16Offset: utf16Offset))
-
utf16Offset += childNode.utf16Length
-
}
-
-
return children
-
}()
-
-
public var utf16Range: Range<Int> {
-
utf16Offset..<utf16Offset + node.utf16Length
-
}
-
-
init(lineMap: LineMap, node: SyntaxTree.Child, utf16Offset: Int) {
-
self.lineMap = lineMap
-
self.node = node
-
self.utf16Offset = utf16Offset
-
}
-
}
-
}
-
extension SyntaxTree.Cursor {
-
public func firstChild<T>(mapping: (SyntaxTree.Cursor) -> T?) -> T? {
-
for child in children {
-
if let result = mapping(child) {
-
return result
-
} else {
-
continue
-
}
-
}
-
return nil
-
}
+
public struct Cursor: Sendable {
+
let node: SyntaxTree.Child
+
let utf16Offset: Int
+
let children: [Cursor]
-
public func children<T>(mapping: (SyntaxTree.Cursor) -> T?) -> [T] {
-
children.compactMap(mapping)
+
init(node: SyntaxTree.Child, utf16Offset: Int) {
+
self.node = node
+
self.utf16Offset = utf16Offset
+
+
var children: [Cursor] = []
+
var utf16Offset = utf16Offset
+
for childNode in node.children {
+
children.append(Self(node: childNode, utf16Offset: utf16Offset))
+
utf16Offset += childNode.utf16Length
+
}
+
+
self.children = children
}
}
-
-25
Sources/PterodactylSyntax/Diagnostic.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
public struct Diagnostic: Equatable {
-
enum Severity: Equatable {
-
case error
-
case warning
-
case note
-
}
-
let message: String
-
let severity: Severity
-
/// Absolute UTF-16 code unit offsets from start of source
-
let absoluteRange: Range<Int>
-
-
init(message: String, severity: Severity, absoluteRange: Range<Int>) {
-
self.message = message
-
self.severity = severity
-
self.absoluteRange = absoluteRange
-
}
-
-
init(message: String, absoluteRange: Range<Int>) {
-
self.init(message: message, severity: Severity.error, absoluteRange: absoluteRange)
-
}
-
}
-63
Sources/PterodactylSyntax/FoldingRanges.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
import LanguageServerProtocol
-
-
private enum ArraySymmetry {
-
case identity
-
case reverse
-
}
-
-
extension Array {
-
fileprivate func apply(symmetry: ArraySymmetry) -> any Collection<Element> {
-
switch symmetry {
-
case .identity: self
-
case .reverse: reversed()
-
}
-
}
-
}
-
-
extension SyntaxTree.Cursor {
-
private func firstVisibleNode(under symmetry: ArraySymmetry) -> SyntaxTree.Cursor? {
-
switch node {
-
case .token(let token, _):
-
return token.kind.isVisible ? self : nil
-
case .tree:
-
for child in children.apply(symmetry: symmetry) {
-
if let visibleChild = child.firstVisibleNode(under: symmetry) { return visibleChild }
-
continue
-
}
-
-
return nil
-
}
-
}
-
-
private var visibleUtf16Range: Range<Int>? {
-
guard
-
let firstNode = firstVisibleNode(under: .identity),
-
let lastNode = firstVisibleNode(under: .reverse)
-
else { return nil }
-
return firstNode.utf16Range.lowerBound..<lastNode.utf16Range.upperBound
-
}
-
-
private func collectFoldingRanges(_ sink: inout [FoldingRange]) {
-
if let foldingRangeKind = node.tree?.metadata?.delimitedFoldingRangeKind, let visibleUtf16Range {
-
let startLocation = lineMap.location(at: visibleUtf16Range.lowerBound)
-
let endLocation = lineMap.location(at: visibleUtf16Range.upperBound)
-
let foldingRange = FoldingRange(startLine: startLocation.line, endLine: endLocation.line, kind: foldingRangeKind)
-
sink.append(foldingRange)
-
}
-
-
for child in children {
-
child.collectFoldingRanges(&sink)
-
}
-
}
-
-
public var foldingRanges: [FoldingRange] {
-
var sink: [FoldingRange] = []
-
collectFoldingRanges(&sink)
-
return sink
-
}
-
}
-46
Sources/PterodactylSyntax/Grammar/Document/Import.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum ImportName: Grammar {
-
static let kind = SyntaxTreeKind(name: "import.name")
-
static let kinds = [kind]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
parser.isAt(kind: .identifier)
-
}
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.expect(kind: .identifier, metadata: TokenMetadata(semanticTokenType: .namespace))
-
return ParseResult(kind: Self.kind)
-
}
-
}
-
-
enum Import: Grammar {
-
static let kind = SyntaxTreeKind(name: "import")
-
static let kinds = [kind]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
parser.isAt(kind: .keyword(.import))
-
}
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.expect(kind: .keyword(.import), metadata: TokenMetadata(semanticTokenType: .keyword))
-
parser.eatTrivia()
-
ImportName.parse(&parser)
-
return ParseResult(kind: Self.kind)
-
}
-
}
-
-
-
extension SyntaxView<ImportName> {
-
var text: String { cursor.node.text }
-
}
-
-
extension SyntaxView<Import> {
-
var name: SyntaxView<ImportName>? {
-
matchingSubview()
-
}
-
}
-19
Sources/PterodactylSyntax/Grammar/Document/Theory/Declaration/Lhs.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum Lhs: Grammar {
-
static let kind = SyntaxTreeKind(name: "declaration.lhs")
-
static let kinds = [kind]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
parser.isAt(kind: .identifier)
-
}
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.expect(kind: .identifier, metadata: TokenMetadata(semanticTokenType: .method))
-
return ParseResult(kind: Self.kind)
-
}
-
}
-19
Sources/PterodactylSyntax/Grammar/Document/Theory/Declaration/Rhs.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum Rhs: Grammar {
-
static let kind = SyntaxTreeKind(name: "declaration.lhs")
-
static let kinds = [kind]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
parser.isAt(kind: .identifier)
-
}
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.expect(kind: .identifier, metadata: TokenMetadata(semanticTokenType: .method))
-
return ParseResult(kind: Self.kind)
-
}
-
}
-52
Sources/PterodactylSyntax/Grammar/Document/Theory/Declaration.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum Declaration: Grammar {
-
enum Kinds {
-
static let claim = SyntaxTreeKind(name: "decl.claim")
-
static let refine = SyntaxTreeKind(name: "decl.refine")
-
static let define = SyntaxTreeKind(name: "decl.define")
-
}
-
-
static let kinds = [Kinds.claim, Kinds.refine, Kinds.define]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
Lhs.before(&parser)
-
}
-
-
static let punctuationMap: [Punctuation: SyntaxTreeKind] = [
-
.colon: Kinds.claim,
-
.doubleLeftArrow: Kinds.refine,
-
.doubleRightArrow: Kinds.define
-
]
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
Lhs.parse(&parser)
-
parser.eatTrivia()
-
-
var kind: SyntaxTreeKind = .error
-
for cell in punctuationMap {
-
if parser.eat(kind: .punctuation(cell.key), metadata: TokenMetadata(semanticTokenType: .operator)) {
-
kind = cell.value
-
break
-
}
-
}
-
-
if kind == .error {
-
parser.advance(error: "Expected one of \(punctuationMap.keys.map(\.rawValue)) in declaration")
-
}
-
-
parser.eatTrivia()
-
Rhs.parse(&parser)
-
-
return ParseResult(kind: kind)
-
}
-
}
-
-
extension SyntaxView<Declaration> {
-
var lhs: SyntaxView<Lhs>? { matchingSubview() }
-
var rhs: SyntaxView<Rhs>? { matchingSubview() }
-
}
-46
Sources/PterodactylSyntax/Grammar/Document/Theory/TheoryBlock.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum TheoryBlock: Grammar {
-
static let kind = SyntaxTreeKind(name: "theory.block")
-
static let kinds = [kind]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
parser.isAt(kind: .keyword(.where))
-
}
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.expect(kind: .keyword(.where), metadata: TokenMetadata(semanticTokenType: .keyword))
-
-
parser.eatTrivia()
-
if parser.eat(kind: .blockBegin, metadata: nil) {
-
parser.eatTrivia()
-
-
while Declaration.tryParse(&parser) {
-
parser.eatTrivia()
-
if parser.eat(kind: .blockSep, metadata: nil) {
-
parser.eatTrivia()
-
continue
-
} else {
-
break
-
}
-
}
-
-
_ = parser.eat(kind: .blockEnd, metadata: nil)
-
}
-
-
var metadata = SyntaxTreeMetadata()
-
metadata.delimitedFoldingRangeKind = .region
-
-
return ParseResult(kind: kind, metadata: metadata)
-
}
-
}
-
-
extension SyntaxView<TheoryBlock> {
-
var declarations: [SyntaxView<Declaration>] {
-
matchingSubviews()
-
}
-
}
-23
Sources/PterodactylSyntax/Grammar/Document/Theory/TheoryName.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum TheoryName: Grammar {
-
static let kind = SyntaxTreeKind(name: "theory.name")
-
static let kinds = [kind]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
parser.isAt(kind: .identifier)
-
}
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.advance(metadata: TokenMetadata(semanticTokenType: .interface))
-
return ParseResult(kind: Self.kind)
-
}
-
}
-
-
extension SyntaxView<TheoryName> {
-
var text: String { cursor.node.text }
-
}
-33
Sources/PterodactylSyntax/Grammar/Document/Theory.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
enum Theory: Grammar {
-
static let kind = SyntaxTreeKind(name: "theory")
-
static let kinds = [kind]
-
-
static func before(_ parser: inout Parser) -> Bool {
-
parser.isAt(kind: .keyword(.theory))
-
}
-
-
static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.expect(kind: .keyword(.theory), metadata: TokenMetadata(semanticTokenType: .keyword))
-
parser.eatTrivia()
-
if !TheoryName.tryParse(&parser) {
-
parser.advance(error: "Expected theory name")
-
}
-
-
parser.eatTrivia()
-
-
TheoryBlock.parse(&parser)
-
-
return ParseResult(kind: Self.kind)
-
}
-
}
-
-
extension SyntaxView<Theory> {
-
var name: SyntaxView<TheoryName>? { matchingSubview() }
-
var block: SyntaxView<TheoryBlock>? { matchingSubview() }
-
}
-51
Sources/PterodactylSyntax/Grammar/Document.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
public enum Document: Grammar {
-
public static let kind = SyntaxTreeKind(name: "document")
-
public static let kinds = [kind]
-
-
public static func before(_ parser: inout Parser) -> Bool {
-
true
-
}
-
-
public static func inside(_ parser: inout Parser) -> ParseResult {
-
parser.eatTrivia()
-
-
// Parse imports
-
while !parser.isAt(kind: .eof) {
-
parser.eatTrivia()
-
if Theory.before(&parser) { break }
-
-
if !Import.tryParse(&parser) {
-
parser.advance(error: "Expected to see either an import or a theory declaration, but instead got \(parser.currentToken.kind): \(parser.currentToken.text)")
-
}
-
}
-
-
// Theories section
-
while !parser.isAt(kind: .eof) {
-
if !Theory.tryParse(&parser) {
-
if parser.isAt(kindSatisfying: \.isVisible) {
-
let token = parser.currentToken
-
parser.advance(error: "Unexpected token: \(token.kind)")
-
} else {
-
parser.advance(metadata: nil)
-
}
-
}
-
parser.eatTrivia()
-
}
-
-
parser.eatTrivia()
-
_ = parser.eat(kind: .eof, metadata: nil)
-
-
return ParseResult(kind: Self.kind)
-
}
-
}
-
-
extension SyntaxView<Document> {
-
var imports: [SyntaxView<Import>] { matchingSubviews() }
-
var theories: [SyntaxView<Theory>] { matchingSubviews() }
-
}
-36
Sources/PterodactylSyntax/Grammar.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
public protocol Grammar: Sendable {
-
static var kinds: [SyntaxTreeKind] { get }
-
static func before(_ parser: inout Parser) -> Bool
-
static func inside(_ parser: inout Parser) -> ParseResult
-
}
-
-
public struct ParseResult {
-
public var kind: SyntaxTreeKind
-
public var metadata: SyntaxTreeMetadata? = nil
-
-
public init(kind: SyntaxTreeKind, metadata: SyntaxTreeMetadata? = nil) {
-
self.kind = kind
-
self.metadata = metadata
-
}
-
}
-
-
-
public extension Grammar {
-
static func tryParse(_ parser: inout Parser) -> Bool {
-
guard !parser.isEndOfFile && before(&parser) else { return false }
-
parse(&parser)
-
return true
-
}
-
-
static func parse(_ parser: inout Parser) {
-
let mark = parser.open()
-
let result = inside(&parser)
-
parser.close(mark: mark, kind: result.kind, metadata: result.metadata)
-
}
-
}
-137
Sources/PterodactylSyntax/Lexer.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
public struct Lexer {
-
private let input: String
-
private var index: String.Index
-
private var tokens: [PterodactylSyntax.Token]
-
-
public init(input: String) {
-
self.input = input
-
self.index = input.startIndex
-
self.tokens = []
-
}
-
-
private var isAtEnd: Bool { index >= input.endIndex }
-
-
private var peek: Character? {
-
guard index < input.endIndex else { return nil }
-
return input[index]
-
}
-
-
private func lookahead() -> Character? {
-
guard index < input.endIndex else { return nil }
-
let next = input.index(after: index)
-
guard next < input.endIndex else { return nil }
-
return input[next]
-
}
-
-
private mutating func advance() -> Character {
-
let c = input[index]
-
index = input.index(after: index)
-
-
return c
-
}
-
-
private mutating func consume(while predicate: (Character) -> Bool) {
-
while let c = peek, predicate(c) {
-
_ = advance()
-
}
-
}
-
-
func text(from start: String.Index) -> String {
-
let range = start..<index
-
return String(input[range])
-
}
-
-
public mutating func nextToken() -> (kind: TokenKind, text: String)? {
-
guard let c = peek else {
-
return nil
-
}
-
-
let start = index
-
-
if c.isNewline {
-
_ = advance()
-
return (kind: .newline, text: text(from: start))
-
}
-
-
if c.isWhitespace && !c.isNewline {
-
consume { $0.isWhitespace && !$0.isNewline }
-
return (kind: .whitespace, text: text(from: start))
-
}
-
-
if c == "/" && lookahead() == "/" {
-
_ = advance()
-
_ = advance()
-
consume { $0 != "\n" }
-
return (kind: .lineComment, text: text(from: start))
-
}
-
-
if c == "/" && lookahead() == "*" {
-
_ = advance() // consume '/'
-
_ = advance() // consume '*'
-
var terminated = false
-
-
while let ch = peek {
-
if ch == "*" && lookahead() == "/" {
-
_ = advance() // consume '*'
-
_ = advance() // consume '/'
-
terminated = true
-
break
-
}
-
_ = advance()
-
}
-
-
return (kind: .blockComment(terminated: terminated), text: text(from: start))
-
}
-
-
if c == "<" && lookahead() == "=" {
-
_ = advance()
-
_ = advance()
-
return (kind: .punctuation(.doubleLeftArrow), text: text(from: start))
-
}
-
-
if c == "=" && lookahead() == ">" {
-
_ = advance()
-
_ = advance()
-
return (kind: .punctuation(.doubleRightArrow), text: text(from: start))
-
}
-
-
if let punct = Punctuation(rawValue: String(c)) {
-
_ = advance()
-
return (.punctuation(punct), String(c))
-
} else if c.isLetter || c == "_" {
-
_ = advance()
-
consume { $0.isLetter || $0.isNumber || $0 == "_" }
-
let text = text(from: start)
-
if let keyword = Keyword(rawValue: text) {
-
return (kind: .keyword(keyword), text: text)
-
}
-
return (kind: .identifier, text: text)
-
}
-
-
// Invalid single char (donโ€™t drop input)
-
let ch = advance()
-
return (kind: .error, text: String(ch))
-
}
-
-
public mutating func tokenize() -> [Token] {
-
var tokens: [Token] = []
-
-
while !isAtEnd {
-
guard let token = nextToken() else { break }
-
tokens.append(
-
Token(kind: token.kind, text: token.text)
-
)
-
}
-
-
let eofToken = Token(kind: .eof, text: "")
-
tokens.append(eofToken)
-
-
return tokens
-
}
-
}
-30
Sources/PterodactylSyntax/LineMap.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Algorithms
-
import Foundation
-
-
public struct LineMap: Codable {
-
private var utf16LineOffsets: [Int] = [0]
-
-
public init(source: String) {
-
for idx in source.indices {
-
let c = source[idx]
-
if c == "\n" || c == "\r\n" || c == "\r" {
-
let next = source.index(after: idx)
-
let utf16Offset = next.utf16Offset(in: source)
-
utf16LineOffsets.append(utf16Offset)
-
}
-
}
-
}
-
-
public func location(at utf16Offset: Int) -> (line: Int, column: Int) {
-
let partitioningIndex = utf16LineOffsets.partitioningIndex { $0 > utf16Offset }
-
let lineIndex = partitioningIndex == 0 ? 0 : partitioningIndex - 1
-
let lineStart = utf16LineOffsets[lineIndex]
-
let lineNumber = lineIndex + 1
-
let columnNumber = utf16Offset - lineStart + 1
-
return (lineNumber, columnNumber)
-
}
-
}
-188
Sources/PterodactylSyntax/Parser.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
public struct Parser {
-
enum Event: Equatable {
-
case open(kind: SyntaxTreeKind, metadata: SyntaxTreeMetadata?)
-
case close
-
case advance(metadata: TokenMetadata?)
-
}
-
-
public struct MarkOpened {
-
internal let index: Int
-
}
-
-
let source: String
-
let tokens: [Token]
-
-
public init(source: String, tokens: [Token]) {
-
self.source = source
-
self.tokens = tokens
-
}
-
-
public private(set) var diagnostics: [Diagnostic] = []
-
-
private var fuel: Int = 0
-
private var position: Int = 0
-
private var events: [Event] = []
-
private var absoluteUtf16Offset: Int = 0
-
public var absoluteRangeAtCursor: Range<Int> {
-
return absoluteUtf16Offset..<absoluteUtf16Offset
-
}
-
-
public var absoluteRangeOfCurrentToken: Range<Int> {
-
return absoluteUtf16Offset..<absoluteUtf16Offset + currentToken.utf16Length
-
}
-
-
public var isEndOfFile: Bool {
-
position == tokens.count
-
}
-
-
public var currentToken: Token {
-
if tokens.indices.contains(position) {
-
return tokens[position]
-
} else {
-
return Token(
-
kind: .eof,
-
text: "",
-
)
-
}
-
}
-
-
public func isAt(kind: TokenKind) -> Bool {
-
currentToken.kind == kind
-
}
-
-
public func isAt(kindSatisfying predicate: (TokenKind) -> Bool) -> Bool {
-
return predicate(currentToken.kind)
-
}
-
-
-
public mutating func open() -> MarkOpened {
-
let mark = MarkOpened(index: events.count)
-
events.append(.open(kind: .error, metadata: nil))
-
return mark
-
}
-
-
public mutating func close(mark: MarkOpened, kind: SyntaxTreeKind, metadata: SyntaxTreeMetadata?) {
-
events[mark.index] = .open(kind: kind, metadata: metadata)
-
events.append(.close)
-
}
-
-
public mutating func advance(metadata: TokenMetadata?) {
-
precondition(!isEndOfFile)
-
events.append(.advance(metadata: metadata))
-
absoluteUtf16Offset += currentToken.utf16Length
-
position += 1
-
fuel = 256
-
}
-
-
public mutating func advance(error: String?, metadata: TokenMetadata? = nil) {
-
let mark = open()
-
if let error {
-
let diagnostic = Diagnostic(
-
message: error,
-
absoluteRange: absoluteRangeOfCurrentToken
-
)
-
-
diagnostics.append(diagnostic)
-
}
-
advance(metadata: metadata)
-
close(mark: mark, kind: .error, metadata: nil)
-
}
-
-
public mutating func lookahead(_ k: Int) -> TokenKind? {
-
precondition(fuel > 0, "Parser is stuck!")
-
fuel -= 1
-
let index = position + k
-
guard tokens.indices.contains(index) else { return nil }
-
return tokens[index].kind
-
}
-
-
public mutating func eat(kindSatisfying predicate: (TokenKind) -> Bool, metadata: TokenMetadata?) -> Bool {
-
guard !isEndOfFile && isAt(kindSatisfying: predicate) else { return false }
-
advance(metadata: metadata)
-
return true
-
}
-
-
public mutating func eat(kind: TokenKind, metadata: TokenMetadata?) -> Bool {
-
eat(kindSatisfying: { $0 == kind }, metadata: metadata)
-
}
-
-
public mutating func expect(kind: TokenKind, metadata: TokenMetadata?, error: String? = nil) {
-
if eat(kind: kind, metadata: metadata) { return }
-
let diagnostic = Diagnostic(
-
message: error ?? "Expected \(kind) but got \(currentToken.kind): `\(currentToken.text)`",
-
absoluteRange: absoluteRangeAtCursor
-
)
-
diagnostics.append(diagnostic)
-
}
-
-
public var tree: SyntaxTree {
-
var events = events
-
var stack: [SyntaxTree.Builder] = []
-
var cursor: Int = 0
-
-
precondition(events.popLast() == .close)
-
-
for event in events {
-
switch event {
-
case .open(let kind, let metadata):
-
stack.append(SyntaxTree.Builder(kind: kind, metadata: metadata, children: []))
-
case .close:
-
let tree = stack.popLast()!
-
stack.modifyLast { last in
-
last.children.append(.tree(tree.tree))
-
}
-
case .advance(let metadata):
-
let token = tokens[cursor]
-
cursor += 1
-
stack.modifyLast { last in
-
last.children.append(.token(token, metadata: metadata))
-
}
-
}
-
}
-
-
assert(stack.count == 1)
-
return stack.popLast()!.tree
-
}
-
-
mutating func eatTrivium() -> Bool {
-
switch currentToken.kind {
-
case .whitespace:
-
advance(metadata: nil)
-
return true
-
case .blockComment(let terminated):
-
let metadata = TokenMetadata(
-
semanticTokenType: .comment,
-
delimitedFoldingRangeKind: .comment
-
)
-
if terminated {
-
advance(metadata: metadata)
-
} else {
-
advance(error: "Block comment was not terminated")
-
}
-
return true
-
case .lineComment:
-
advance(metadata: TokenMetadata(semanticTokenType: .comment))
-
return true
-
default:
-
return false
-
}
-
}
-
-
mutating func eatTrivia() {
-
while !isEndOfFile && eatTrivium() {}
-
}
-
-
}
-
-
extension Array {
-
fileprivate mutating func modifyLast(_ modifier: (inout Element) -> Void) {
-
if var last = popLast() {
-
modifier(&last)
-
append(last)
-
}
-
}
-
}
-69
Sources/PterodactylSyntax/SemanticToken.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
import LanguageServerProtocol
-
-
extension SemanticTokenTypes {
-
public var index: Int {
-
Self.allCases.firstIndex(of: self)!
-
}
-
}
-
-
extension SemanticTokenModifiers {
-
private static let modifierBitPositions: [SemanticTokenModifiers: Int] = {
-
var dict: [SemanticTokenModifiers: Int] = [:]
-
for (i, modifier) in SemanticTokenModifiers.allCases.enumerated() {
-
dict[modifier] = i
-
}
-
return dict
-
}()
-
-
static func encodeBitset(_ modifiers: Set<SemanticTokenModifiers>) -> UInt32 {
-
var bitset: UInt32 = 0
-
for modifier in modifiers {
-
if let bit = modifierBitPositions[modifier] {
-
bitset |= (1 << bit)
-
}
-
}
-
return bitset
-
}
-
}
-
-
-
struct SingleLineRange {
-
let line: Int
-
let char: Int
-
let length: Int
-
}
-
-
-
extension TokenMetadata {
-
func semanticToken(range: SingleLineRange) -> SemanticToken? {
-
guard range.length > 0 else { return nil }
-
return SemanticToken(
-
line: UInt32(range.line),
-
char: UInt32(range.char),
-
length: UInt32(range.length),
-
type: UInt32(semanticTokenType.index),
-
modifiers: SemanticTokenModifiers.encodeBitset(semanticTokenModifiers)
-
)
-
}
-
}
-
-
extension SyntaxTree.Cursor {
-
var singleLineRanges: [SingleLineRange] {
-
var result: [SingleLineRange] = []
-
var location = lineMap.location(at: utf16Offset)
-
-
for line in node.text.split(omittingEmptySubsequences: false, whereSeparator: \.isNewline) {
-
let length = line.utf16.count
-
result.append(SingleLineRange(line: location.line, char: location.column, length: length))
-
location.line += 1
-
location.column = 0
-
}
-
-
return result
-
}
-
}
+8 -35
Sources/PterodactylSyntax/SyntaxTree.swift
···
public let metadata: SyntaxTreeMetadata?
public let children: [Child]
public let utf16Length: Int
+
+
public enum Child: Codable, Sendable {
+
case token(Token, metadata: TokenMetadata?)
+
case tree(SyntaxTree)
+
}
-
public enum Child: Codable, Sendable {
-
case token(Token, metadata: TokenMetadata?)
-
case tree(SyntaxTree)
-
}
-
-
public init(kind: SyntaxTreeKind, metadata: SyntaxTreeMetadata? = nil, children: [SyntaxTree.Child]) {
+
public init(kind: SyntaxTreeKind, metadata: SyntaxTreeMetadata?, children: [SyntaxTree.Child]) {
self.kind = kind
self.metadata = metadata
self.children = children
···
}
extension SyntaxTree {
-
/// A mutable version of ``SyntaxTree`` that does not keep track of textual length, for use when constructing trees.
-
public struct Builder {
-
public var kind: SyntaxTreeKind
-
public var metadata: SyntaxTreeMetadata?
-
public var children: [Child]
-
-
var tree: SyntaxTree {
-
SyntaxTree(kind: kind, metadata: metadata, children: children)
-
}
-
}
-
}
-
-
extension SyntaxTree {
public var text: String {
children.map(\.text).joined()
}
}
extension SyntaxTree.Child {
-
public var text: String {
+
var text: String {
switch self {
case let .token(tok, _): tok.text
case let .tree(tree): tree.text
}
}
-
-
public var tree: SyntaxTree? {
-
switch self {
-
case let .tree(tree): tree
-
default: nil
-
}
-
}
-
var token: (Token, TokenMetadata?)? {
-
switch self {
-
case let .token(token, metadata): (token, metadata)
-
default: nil
-
}
-
}
-
var utf16Length: Int {
switch self {
case let .token(token, _): token.utf16Length
case let .tree(tree): tree.utf16Length
}
}
-
+
var children: [Self] {
switch self {
case .token: []
-21
Sources/PterodactylSyntax/SyntaxView.swift
···
-
// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
-
//
-
// SPDX-License-Identifier: MPL-2.0
-
-
import Foundation
-
-
struct SyntaxView<G: Grammar> {
-
let cursor: SyntaxTree.Cursor
-
init?(_ cursor: SyntaxTree.Cursor) {
-
guard let kind = cursor.node.tree?.kind, G.kinds.contains(kind) else { return nil }
-
self.cursor = cursor
-
}
-
-
func matchingSubview<X: Grammar>() -> SyntaxView<X>? {
-
return cursor.firstChild(mapping: SyntaxView<X>.init)
-
}
-
-
func matchingSubviews<X: Grammar>() -> [SyntaxView<X>] {
-
return cursor.children(mapping: SyntaxView<X>.init)
-
}
-
}
+1 -1
Sources/PterodactylSyntax/Token.swift
···
public let text: String
public let utf16Length: Int
-
public init(kind: TokenKind, text: String) {
+
init(kind: TokenKind, text: String) {
self.kind = kind
self.text = text
self.utf16Length = text.utf16.count
+5 -80
Sources/PterodactylSyntax/Types.swift
···
// SPDX-License-Identifier: MPL-2.0
import Foundation
-
import LanguageServerProtocol
-
-
public enum Keyword: String, Codable, Sendable, CaseIterable {
-
case theory = "theory"
-
case `where` = "where"
-
case `import` = "import"
-
}
-
-
public enum Punctuation: String, CaseIterable, Codable, Equatable, Sendable {
-
case lparen = "("
-
case rparen = ")"
-
case lbrace = "{"
-
case rbrace = "}"
-
case comma = ","
-
case dot = "."
-
case colon = ":"
-
case doubleLeftArrow = "<="
-
case doubleRightArrow = "=>"
-
case equal = "="
-
}
public enum TokenKind: Codable, Equatable, Sendable {
-
case eof
-
case keyword(Keyword)
-
case punctuation(Punctuation)
-
case error
-
case identifier
-
case newline
-
case whitespace
-
case blockBegin
-
case blockEnd
-
case blockSep
-
case lineComment
-
case blockComment(terminated: Bool)
+
case eof
}
-
extension TokenKind {
-
public var isTrivia: Bool {
-
switch self {
-
case .whitespace, .newline, .lineComment, .blockComment: true
-
default: false
-
}
-
}
-
-
public var isVisible: Bool {
-
switch self {
-
case .whitespace, .blockBegin, .blockSep, .blockEnd, .newline: false
-
default: true
-
}
-
}
-
public var canDetermineLayoutColumn: Bool {
-
switch self {
-
case .whitespace, .eof: false
-
default: true
-
}
-
}
-
-
public var isBlockHerald: Bool {
-
switch self {
-
case .keyword(.where): true
-
default: false
-
}
-
}
-
+
public enum SyntaxTreeKind: Codable, Equatable, Sendable {
+
case error
}
-
public final class SyntaxTreeKind: Codable, Equatable, Sendable {
-
static let error: SyntaxTreeKind = .init(name: "error")
-
-
public static func == (lhs: SyntaxTreeKind, rhs: SyntaxTreeKind) -> Bool {
-
lhs === rhs
-
}
-
-
let name: String
-
var description: String { name }
-
-
required init(name: String) {
-
self.name = name
-
}
-
}
-
-
public struct TokenMetadata: Equatable, Codable, Sendable {
-
public var semanticTokenType: SemanticTokenTypes
-
public var semanticTokenModifiers: Set<SemanticTokenModifiers> = []
-
public var delimitedFoldingRangeKind: FoldingRangeKind? = nil
+
public struct TokenMetadata: Codable, Equatable, Sendable {
}
public struct SyntaxTreeMetadata: Codable, Equatable, Sendable {
-
public var delimitedFoldingRangeKind: FoldingRangeKind? = nil
+
}
+4 -4
Tests/PterodactylBuildTests/Test.swift
···
let treeID: LLBDataID = try await client.store(declTree, ctx).get()
let dependencyGraph = try await engine.build(key: Keys.DependencyGraphOfSourceTree(sourceTreeId: treeID), ctx).get()
-
let foo = UnitName(basename: "foo")
-
let bar = UnitName(basename: "bar")
-
let baz = UnitName(basename: "baz")
+
let foo = UnitName(name: "foo")
+
let bar = UnitName(name: "bar")
+
let baz = UnitName(name: "baz")
#expect(
dependencyGraph.edges == [
···
]
)
-
let dependenciesOfBaz = try await engine.build(key: Keys.TransitiveDependencies(sourceTreeId: treeID, unitName: baz), ctx).get()
+
let dependenciesOfBaz = try await engine.build(key: Keys.TransitiveDependencies(sourceTreeId: treeID, unitName: baz), ctx).get().dependencies
#expect(dependenciesOfBaz == [foo, bar])
return
}
-4
license.sh
···
-
#!/bin/bash
-
-
reuse annotate --recursive --license MPL-2.0 --copyright "The Project Pterodactyl Developers" Tests Sources
-