-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
I guess because `free()1Password nulls out freed memory there is a memory problem as when I use the following code
import Foundation
import Syntax
public enum JSON {
case object([String : JSON])
case array([JSON])
case int(Int)
case double(Double)
case bool(Bool)
case string(String)
case null
}
public struct TokenParser: RecursiveParser {
public init() {}
public var body: any Parser<JSON> {
Either {
JSONDictionaryParser().map(JSON.object)
JSONArrayParser().map(JSON.array)
StringLiteral().map(JSON.string)
IntLiteral().map(JSON.int)
DoubleLiteral().map(JSON.double)
BooleanLiteral().map(JSON.bool)
Word("null").map(to: JSON.null)
}
}
}
public struct JSONArrayParser: Parser {
// reference to the JSON parser
public var body: any Parser<[JSON]> {
"["
TokenParser().separated(by: ",")
"]"
}
}
public struct JSONDictionaryParser: Parser {
public var body: any Parser<[String : JSON]> {
"{"
// Group acts kinda like parenthesis here.
// It groups the key-value pair into one parser
Group {
StringLiteral()
":"
TokenParser()
}
.separated(by: ",")
.map { values in
// put the pairs in a dictionary
return Dictionary(values) { $1 }
}
"}"
}
}To run a simple test
final class SyntaxTokenParsing: XCTestCase {
func testSyntax() throws {
let test = """
{
"key1" : { "value": 1 },
"key2" : { "value": 2 }
}
"""
let jsonParsed = try TokenParser().parse(test)
XCTAssertEqual("\(jsonParsed)", "")
}
}andrews05
Metadata
Metadata
Assignees
Labels
No labels
