Skip to content

Commit dcdebf3

Browse files
Align the latest SwiftSyntax changes
1 parent 2199243 commit dcdebf3

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/parsers/trunk/Sources/parser/SyntaxParser.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Foundation
2+
import SwiftSyntax
3+
import SwiftOperators
4+
import SwiftParser
5+
6+
struct SyntaxParser {
7+
static func parse(code: String, options: [String] = []) throws -> SyntaxResponse {
8+
let sourceFile = Parser.parse(source: code)
9+
10+
let syntax: Syntax
11+
if options.contains("fold") {
12+
syntax = OperatorTable.standardOperators.foldAll(sourceFile, errorHandler: { _ in })
13+
} else {
14+
syntax = Syntax(sourceFile)
15+
}
16+
17+
let visitor = TokenVisitor(
18+
locationConverter: SourceLocationConverter(fileName: "", tree: sourceFile),
19+
showMissingTokens: options.contains("showmissing")
20+
)
21+
_ = visitor.rewrite(syntax)
22+
23+
let html = "\(visitor.list.joined())"
24+
25+
let tree = visitor.tree
26+
let encoder = JSONEncoder()
27+
let json = String(decoding: try encoder.encode(tree), as: UTF8.self)
28+
29+
return SyntaxResponse(syntaxHTML: html, syntaxJSON: json, swiftVersion: "5.9")
30+
}
31+
}

0 commit comments

Comments
 (0)