{"id":46940613,"url":"https://github.com/1amageek/swift-yaml","last_synced_at":"2026-03-11T07:00:43.102Z","repository":{"id":343595820,"uuid":"1174339449","full_name":"1amageek/swift-yaml","owner":"1amageek","description":"A pure Swift YAML parser with no external dependencies","archived":false,"fork":false,"pushed_at":"2026-03-11T05:27:07.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-11T05:54:40.252Z","etag":null,"topics":["parser","swift","swift-package-manager","yaml"],"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/1amageek.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-06T10:28:26.000Z","updated_at":"2026-03-11T05:27:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/1amageek/swift-yaml","commit_stats":null,"previous_names":["1amageek/swift-yaml"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/1amageek/swift-yaml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-yaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-yaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-yaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-yaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1amageek","download_url":"https://codeload.github.com/1amageek/swift-yaml/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-yaml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30373505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["parser","swift","swift-package-manager","yaml"],"created_at":"2026-03-11T07:00:22.192Z","updated_at":"2026-03-11T07:00:43.086Z","avatar_url":"https://github.com/1amageek.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swift-yaml\n\nA pure Swift YAML 1.2.2 parser with zero dependencies. Parses YAML strings into a typed `Node` tree with full spec compliance, verified by 569 tests.\n\n## Installation\n\nAdd to your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/1amageek/swift-yaml.git\", from: \"0.3.0\")\n]\n```\n\nThen add `\"YAML\"` to your target's dependencies:\n\n```swift\n.target(name: \"YourTarget\", dependencies: [\"YAML\"])\n```\n\n## Usage\n\n```swift\nimport YAML\n\nlet node = try compose(yaml: \"\"\"\nserver:\n  host: localhost\n  port: 8080\n  features: [auth, logging]\n\"\"\")\n\nif case .mapping(let root) = node,\n   case .mapping(let server) = root[\"server\"] {\n    print(server[\"host\"])      // Optional(.scalar(\"localhost\"))\n    print(server[\"port\"])      // Optional(.scalar(\"8080\"))\n    print(server[\"features\"])  // Optional(.sequence([...]))\n}\n```\n\n### Node Types\n\nThe parser produces a recursive `Node` tree with three cases:\n\n| Case | Type | Description |\n|---|---|---|\n| `.scalar(Scalar)` | `Node.Scalar` | String value with optional source position |\n| `.mapping(Mapping)` | `Node.Mapping` | Ordered key-value pairs (`RandomAccessCollection`) |\n| `.sequence(Sequence)` | `Node.Sequence` | Ordered list of nodes (`RandomAccessCollection`) |\n\nAccess values using computed properties:\n\n```swift\nnode.scalar?.string     // \"value\" or nil\nnode.mapping?[\"key\"]    // Node? or nil\nnode.sequence?[0]       // Node or nil\n```\n\n### Supported YAML Features\n\n| Feature | Example |\n|---|---|\n| Block mapping | `key: value` |\n| Block sequence | `- item` |\n| Flow sequence | `[a, b, c]` |\n| Flow mapping | `{key: value}` |\n| Literal block scalar | \u003ccode\u003e\u0026#124;\u003c/code\u003e, \u003ccode\u003e\u0026#124;-\u003c/code\u003e, \u003ccode\u003e\u0026#124;+\u003c/code\u003e |\n| Folded block scalar | `\u003e`, `\u003e-`, `\u003e+` |\n| Single-quoted string | `'it''s escaped'` |\n| Double-quoted string | `\"hello\\nworld\"` |\n| Anchors \u0026 aliases | `\u0026anchor` / `*anchor` |\n| Tags | `!!str`, `!custom`, `!\u003cverbatim\u003e` |\n| Multi-document | `---` / `...` |\n| Directives | `%YAML 1.2`, `%TAG` |\n| Comments | `# comment` |\n| Complex mapping keys | `{flow: map}: value`, `[seq]: value` |\n| Escape sequences | All 18 YAML escapes + `\\xNN`, `\\uNNNN`, `\\UNNNNNNNN` |\n| Nested structures | Arbitrary depth |\n\n### Error Handling\n\nAll parse errors are reported as `YAMLError` with source position:\n\n```swift\ndo {\n    let node = try compose(yaml: invalidYAML)\n} catch let error as YAMLError {\n    print(error) // \"3:12: scanner error: unterminated double-quoted string\"\n}\n```\n\n### Type Safety\n\nAll public types conform to `Sendable`, `Hashable`, and `Equatable`:\n\n```swift\n// Use nodes as dictionary keys or set elements\nvar seen: Set\u003cNode\u003e = []\nseen.insert(node)\n\n// Compare nodes\nif node == .scalar(Node.Scalar(\"expected\")) { ... }\n```\n\n## Architecture\n\nThe parser uses a classic three-stage pipeline:\n\n```\nYAML String → Scanner → Parser → Node Tree\n               (tokens)  (recursive descent)\n```\n\n1. **Scanner** — Tokenizes YAML input with indentation tracking, flow/block context switching, and block scalar processing\n2. **Parser** — Recursive descent parser that consumes tokens and builds the `Node` tree with anchor resolution\n3. **Compose** — Public entry point (`compose(yaml:)`) that wires Scanner and Parser together\n\n## API Reference\n\n### Entry Point\n\n```swift\npublic func compose(yaml: String) throws -\u003e Node?\n```\n\nReturns `nil` for empty documents. Throws `YAMLError` on invalid input.\n\n### Node\n\n```swift\npublic enum Node: Sendable, Hashable {\n    case scalar(Scalar)\n    case mapping(Mapping)\n    case sequence(Sequence)\n\n    var scalar: Scalar?     { get }\n    var mapping: Mapping?   { get }\n    var sequence: Sequence? { get }\n}\n```\n\n### Node.Scalar\n\n```swift\npublic struct Scalar: Sendable, Hashable {\n    public let string: String\n    public let mark: Mark?\n    public init(_ string: String, mark: Mark? = nil)\n}\n```\n\n### Node.Mapping\n\n```swift\npublic struct Mapping: Sendable, Hashable, RandomAccessCollection {\n    // Element = (key: Node, value: Node)\n    public subscript(key: String) -\u003e Node?          // lookup by string key\n    public subscript(position: Int) -\u003e (Node, Node)  // access by index\n    public var first: (key: Node, value: Node)?\n    public var isEmpty: Bool\n}\n```\n\n### Node.Sequence\n\n```swift\npublic struct Sequence: Sendable, Hashable, RandomAccessCollection {\n    // Element = Node\n    public subscript(position: Int) -\u003e Node\n}\n```\n\n### Mark\n\n```swift\npublic struct Mark: Sendable, Hashable, CustomStringConvertible {\n    public let line: Int    // 1-based\n    public let column: Int  // 1-based\n}\n```\n\n### YAMLError\n\n```swift\npublic enum YAMLError: Error, Sendable, CustomStringConvertible {\n    case scanner(message: String, mark: Mark)\n    case parser(message: String, mark: Mark)\n    case unexpectedEndOfInput(mark: Mark)\n}\n```\n\n## Requirements\n\n- Swift 6.2+\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1amageek%2Fswift-yaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1amageek%2Fswift-yaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1amageek%2Fswift-yaml/lists"}