@@ -33,10 +33,15 @@ public enum ParserError: Error, CustomStringConvertible {
33
33
/// normal circumstances, and it should be reported as a bug.
34
34
case invalidSyntaxData
35
35
36
+ /// The SwiftSyntax parser library isn't compatible with this client
37
+ case parserCompatibilityCheckFailed
38
+
36
39
public var description : String {
37
40
switch self {
38
41
case . invalidSyntaxData:
39
42
return " parser created invalid syntax data "
43
+ case . parserCompatibilityCheckFailed:
44
+ return " SwiftSyntax parser library isn't compatible "
40
45
}
41
46
}
42
47
}
@@ -61,6 +66,11 @@ public protocol IncrementalParseLookup {
61
66
62
67
/// Namespace for functions to parse swift source and retrieve a syntax tree.
63
68
public struct SyntaxParser {
69
+
70
+ /// True if the parser library is compatible with the SwiftSyntax client;
71
+ /// false otherwise.
72
+ fileprivate static var nodeHashVerifyResult : Bool = verifyNodeDeclarationHash ( )
73
+
64
74
/// Parses the string into a full-fidelity Syntax tree.
65
75
///
66
76
/// - Parameters:
@@ -73,6 +83,9 @@ public struct SyntaxParser {
73
83
source: String ,
74
84
parseLookup: IncrementalParseLookup ? = nil
75
85
) throws -> SourceFileSyntax {
86
+ guard nodeHashVerifyResult else {
87
+ throw ParserError . parserCompatibilityCheckFailed
88
+ }
76
89
// Get a native UTF8 string for efficient indexing with UTF8 byte offsets.
77
90
// If the string is backed by an NSString then such indexing will become
78
91
// extremely slow.
@@ -109,7 +122,6 @@ public struct SyntaxParser {
109
122
parseLookup: IncrementalParseLookup ?
110
123
) -> RawSyntax {
111
124
assert ( source. isNativeUTF8)
112
-
113
125
let c_parser = swiftparse_parser_create ( )
114
126
defer {
115
127
swiftparse_parser_dispose ( c_parser)
0 commit comments