{"id":15066972,"url":"https://github.com/johnpatrickmorgan/sparse","last_synced_at":"2025-04-10T13:54:02.495Z","repository":{"id":62455840,"uuid":"78791049","full_name":"johnpatrickmorgan/Sparse","owner":"johnpatrickmorgan","description":"Sparse is a simple parser-combinator library written in Swift.","archived":false,"fork":false,"pushed_at":"2019-11-07T17:07:40.000Z","size":66,"stargazers_count":116,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T12:39:24.689Z","etag":null,"topics":["cocoapods","ios","macos","parser","spm","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnpatrickmorgan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-12T22:04:06.000Z","updated_at":"2025-03-10T23:24:42.000Z","dependencies_parsed_at":"2022-11-02T00:16:56.036Z","dependency_job_id":null,"html_url":"https://github.com/johnpatrickmorgan/Sparse","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpatrickmorgan%2FSparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpatrickmorgan%2FSparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpatrickmorgan%2FSparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpatrickmorgan%2FSparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnpatrickmorgan","download_url":"https://codeload.github.com/johnpatrickmorgan/Sparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248229314,"owners_count":21068875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","ios","macos","parser","spm","swift"],"created_at":"2024-09-25T01:14:38.991Z","updated_at":"2025-04-10T13:54:02.468Z","avatar_url":"https://github.com/johnpatrickmorgan.png","language":"Swift","readme":"# ✂️ Sparse ✂️\n\n[![Version](https://img.shields.io/cocoapods/v/Sparse.svg?style=flat)](http://cocoapods.org/pods/Sparse)\n[![License](https://img.shields.io/cocoapods/l/Sparse.svg?style=flat)](http://cocoapods.org/pods/Sparse)\n![Swift](https://img.shields.io/badge/Swift-5.1-orange.svg)\n\nSparse is a simple parsing library, written in Swift. It is based on the parser-combinator approach used by Haskell's [Parsec](https://github.com/aslatter/parsec). Its focus is on natural language parser creation and descriptive error messages.\n\n## Example\n\nHere is a CSV parser:\n\n```swift\nlet quote = character(\"\\\"\")\n\nlet illegalCellCharacters = CharacterSet.newlines.union(CharacterSet(charactersIn: \",\"))\nlet unquotedCellCharacter = characterNot(in: illegalCellCharacters)\n    .named(\"cell character\")\nlet unquotedCell = many(unquotedCellCharacter).asString()\n    .map { $0.trimmingCharacters(in: .whitespaces) }\n\nlet escapedQuote = quote.skipThen(quote)\n    .named(\"escaped quote\")\nlet quotedCellCharacter = characterNot(\"\\\"\")\n    .named(\"quoted cell character\")\n    .otherwise(escapedQuote)\n\nlet quotedCell = many(quotedCellCharacter, boundedBy: quote).asString()\n\nlet cell = quotedCell.otherwise(unquotedCell)\n\nlet cellSeparator = whitespaces().then(character(\",\")).then(whitespaces())\n    .named(\"cell separator\")\nlet line = many(cell, separator: cellSeparator)\n\nlet ending = optional(newline()).then(end())\nlet csv = many(line, separator: newline()).thenSkip(ending)\n\npublic func parseCSV(input: String) throws -\u003e [[String]] {\n    return try csv.parse(input)\n}\n```\n\nNaming the component parsers allows for more descriptive error messages, e.g.:\n\n    Line 8, Column 12\n    r8c1 , \"r8\"c2\" , r8c3 ,r8c4,r8c5,r8c6,r8c7 , r8c8\n    ~~~~~~~~~~~^\n    Expected: '\"' in escaped quote\n    Expected: whitespace in cell separator\n    Expected: ',' in cell separator\n    Expected: newline\n    Expected: EOF: file\n\n## Installation\n\n### Swift Package Manager\n\nAdd Sparse as a dependency in Package.swift:\n\n```swift\n.package(url: \"https://github.com/johnpatrickmorgan/sparse.git\", from: \"0.3.0\"),\n```\n\n### CocoaPods\n\nAdd the following line to your Podfile:\n\n```ruby\npod \"Sparse\"\n```\n\n## Credit\n\nSparse is based on Haskell's [Parsec](https://github.com/aslatter/parsec).\n\n## License\n\nSparse is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnpatrickmorgan%2Fsparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnpatrickmorgan%2Fsparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnpatrickmorgan%2Fsparse/lists"}