{"id":19830400,"url":"https://github.com/mgadda/swift-parse","last_synced_at":"2025-07-15T12:35:17.868Z","repository":{"id":55098059,"uuid":"69323528","full_name":"mgadda/swift-parse","owner":"mgadda","description":"A small parser combinator library written in Swift 5","archived":false,"fork":false,"pushed_at":"2024-04-14T14:39:56.000Z","size":103,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-21T16:43:48.351Z","etag":null,"topics":["combinators","parse","parser","swift"],"latest_commit_sha":null,"homepage":"","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/mgadda.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-27T05:45:25.000Z","updated_at":"2024-04-14T14:40:01.000Z","dependencies_parsed_at":"2024-11-12T11:29:11.694Z","dependency_job_id":"1343639f-f7f1-4f03-a7c1-1284f76e73d4","html_url":"https://github.com/mgadda/swift-parse","commit_stats":{"total_commits":87,"total_committers":3,"mean_commits":29.0,"dds":"0.10344827586206895","last_synced_commit":"ad07d9c33029aefed2916dfda852192e0d94327f"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/mgadda/swift-parse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgadda%2Fswift-parse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgadda%2Fswift-parse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgadda%2Fswift-parse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgadda%2Fswift-parse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgadda","download_url":"https://codeload.github.com/mgadda/swift-parse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgadda%2Fswift-parse/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265436856,"owners_count":23765045,"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":["combinators","parse","parser","swift"],"created_at":"2024-11-12T11:23:26.283Z","updated_at":"2025-07-15T12:35:17.846Z","avatar_url":"https://github.com/mgadda.png","language":"Swift","readme":"## Overview\n\nSwiftParse is a parser combinator library. This project is still iterating rapidly and is not stable.\n\n[![Build Status](https://travis-ci.org/mgadda/swift-parse.svg?branch=master)](https://travis-ci.org/mgadda/swift-parse)\n\n## Example\n\nLet's build a parser for the brainfuck language. It's a terrible language but\nmakes for a nice example of how to use SwiftParse.\n\n```swift\nimport SwiftParse\n\nenum Instruction {\n  case incPointer, decPointer, incByte, decByte, writeByte, readByte\n  case loop([Instruction])\n}\n\ntypealias LoopParser = StandardParser\u003cString, Instruction\u003e\n\nstruct BrainfuckParser {  \n  static let incPointer = match(\"\u003e\") ^^ { _ in Instruction.incPointer }\n  static let decPointer = match(\"\u003c\") ^^ { _ in Instruction.decPointer }\n  static let incByte = match(\"+\") ^^ { _ in Instruction.incByte }\n  static let decByte = match(\"-\") ^^ { _ in Instruction.decByte }\n  static let writeByte = match(\".\") ^^ { _ in Instruction.writeByte }\n  static let readByte = match(\",\") ^^ { _ in Instruction.readByte }\n\n  static let pointerOps = incPointer | decPointer\n  static let byteOps = incByte | decByte\n  static let ioOps = writeByte | readByte\n  static let operation = pointerOps | byteOps | ioOps | loop()\n  \n  // loop must defined as a static function because it references\n  // operation which in turn references loop.\n  static let loop: () -\u003e LoopParser = {\n    loopStart ~ operation* ~ loopEnd ^^ { Instruction.loop($0.0.1) }\n  }\n  \n  static let loopStart = match(\"[\")\n  static let loopEnd = match(\"]\")\n  \n  static let program = operation+\n}\n```\n\nNow let's execute it and see what it parsed:\n```swift\nlet result = BrainfuckParser.program(AnyCollection(\"+[\u003e,]\"))\nlet parseTree = try! result.get().value\n```\n\nThis generates a parse tree of:\n\n```swift\n[\n  SwiftParse.Brainfuck.incByte,\n  SwiftParse.Brainfuck.loop([\n    SwiftParse.Brainfuck.incPointer,\n    SwiftParse.Brainfuck.readByte\n  ])\n]\n```\n\nAnd no unparsed characters left over. Neat!\n\nFor more complete examples check out https://github.com/mgadda/swift-parse-examples\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgadda%2Fswift-parse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgadda%2Fswift-parse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgadda%2Fswift-parse/lists"}