Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With Xcode 14.1 beta 1 there is a memory crash #9

Open
doozMen opened this issue Sep 23, 2022 · 1 comment
Open

With Xcode 14.1 beta 1 there is a memory crash #9

doozMen opened this issue Sep 23, 2022 · 1 comment

Comments

@doozMen
Copy link

doozMen commented Sep 23, 2022

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)", "")
  }
}

This works on Xcode 14.0 but not on 14.1
Screenshot 2022-09-23 at 11 16 09

@andrews05
Copy link

I'm getting the same error in Xcode 14.2.
Trivial example

struct TestParser: Parser {
    var body: AnyParser<(String, Int)> {
        Word("D")
        IntLiteral()
    }
}

try? TestParser().parse("D 1")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants