ParsingDecoder
public struct ParsingDecoder
A standard decoder that can use any supplied Parser
to decode Data
into a Decodable
conforming type.
do{
let command : Command = try ParsingDecoder().decode(Command.self, from: userInput.data(using: .utf8) ?? Data(), with: Bork.generatedLanguage)
...
} catch {
print("Something went wrong: \(error.localizedDescription)")
}
The names of the Token
s generated by the supplied Parser
are used as keys into the Decodable
type being populated.
-
Create an instance of
ParsingDecoder
Declaration
Swift
public init()
-
Decodes the supplied data using the supplied parser into the specified object. The names of the
TokenType
s generated by the suppliedParser
are used as keys into theDecodable
type being populated.Declaration
Swift
public func decode<T>(_ type: T.Type, using ast: DecodeableAbstractSyntaxTree) throws -> T where T : Decodable
Parameters
type
A type conforming to
Decodable
ast
The AbstractSyntaxTree representation
Return Value
An instance of the type
-
Decodes the supplied data using the supplied parser into the specified object. The names of the
TokenType
s generated by the suppliedParser
are used as keys into theDecodable
type being populated.Declaration
Swift
public func decode<T>(_ type: T.Type, from source: String, using language: Grammar) throws -> T where T : Decodable
Parameters
type
A type conforming to
Decodable
ast
The AbstractSyntaxTree representation
Return Value
An instance of the type