Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftAstGenLib/SyntaxParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct SyntaxParser {
let loc = countLines(in: code)
let opPrecedence = OperatorTable.standardOperators
let ast = Parser.parse(source: code)
let folded = try opPrecedence.foldAll(ast)
let folded = opPrecedence.foldAll(ast) { _ in }

let locationConverter = SourceLocationConverter(fileName: fileUrl.path, tree: folded)
let treeNode = folded.toJson(converter: locationConverter)
Expand Down
25 changes: 25 additions & 0 deletions Tests/SwiftAstGenTests/SwiftAstGenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class SwiftAstGenTests: XCTestCase, TestUtils {
("testIgnoresTestTargetPathsFromPackageSwift", testIgnoresTestTargetPathsFromPackageSwift),
("testIgnoresMultipleTestTargetPaths", testIgnoresMultipleTestTargetPaths),
("testIgnoresCustomTestTargetPath", testIgnoresCustomTestTargetPath),
("testCustomOperatorDoesNotFailParsing", testCustomOperatorDoesNotFailParsing),
]

func testJsonSourceFileSyntax() throws {
Expand Down Expand Up @@ -191,6 +192,30 @@ final class SwiftAstGenTests: XCTestCase, TestUtils {
)
}

func testCustomOperatorDoesNotFailParsing() throws {
try withCode(
code: """
infix operator <<<: AdditionPrecedence
func <<< (lhs: Int, rhs: Int) -> Int { lhs + rhs }
let result = 1 <<< 2
"""
) { srcDir, outputDir, jsonFile in

try SwiftAstGenerator(
srcDir: srcDir,
outputDir: outputDir,
prettyPrint: false
).generate()

XCTAssertTrue(FileManager.default.fileExists(atPath: jsonFile.path))
if let treeNode = loadJson(file: jsonFile) {
XCTAssertEqual(treeNode.nodeType, "SourceFileSyntax")
} else {
XCTFail("Could not create the JSON containing the Swift AST.")
}
}
}

func testIgnoresCustomTestTargetPath() throws {
let tempDir = createTemporaryDirectory()
defer { cleanup(directory: tempDir) }
Expand Down
Loading