{"_id":"@codincod/codemirror-lang-swift","_rev":"5-0c3a315c40742714525b671e20eeb179","name":"@codincod/codemirror-lang-swift","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"@codincod/codemirror-lang-swift","version":"0.1.0","keywords":["editor","code","swift","codemirror"],"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","_id":"@codincod/codemirror-lang-swift@0.1.0","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"dist":{"shasum":"ea0bdeb74fddc8a56067cc716d8a161b16d8dc35","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-swift/-/codemirror-lang-swift-0.1.0.tgz","fileCount":14,"integrity":"sha512-lGxMDT9mYLqdz6dsfjyvQT5xq0/fQQ9vcc7tQuRHlkJGAW/AnjNs5Te70sXroxSYMn1/4D7AjlGgsTACTKhM+g==","signatures":[{"sig":"MEQCIF+5xpdU0akqH7GCUe6vJk8d75mP5U5AQ0828Be6/fW0AiAm5tLCOvOrripVYB8E60K99U0brqIK1PKDGYQsb3d0vg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":363629},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{"import":"./dist/index.js","require":"./dist/index.cjs"},"gitHead":"07186026ef348db1aed6b2a7b8b7931be2841601","scripts":{"test":"npm run build && node --test \"test/*.test.ts\"","build":"rm -rf dist && lezer-generator src/swift.grammar -o src/parser.js && cm-buildhelper src/swift.ts","corpus":"npm run build && node test/corpus.ts","prepare":"npm run build","build-debug":"lezer-generator src/swift.grammar --names -o src/parser.js && cm-buildhelper src/swift.ts"},"_npmUser":{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"},"repository":{"url":"git+https://codeberg.org/reeven/codemirror-lang-swift.git","type":"git"},"_npmVersion":"11.6.2","description":"Swift language support for the CodeMirror code editor","directories":{},"sideEffects":false,"_nodeVersion":"25.0.0","dependencies":{"@lezer/lr":"^1.0.0","@lezer/common":"^1.0.0","@lezer/highlight":"^1.0.0","@codemirror/language":"^6.0.0","@codemirror/autocomplete":"^6.0.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.6.0","@lezer/generator":"^1.7.0","@codemirror/state":"^6.7.1","@codemirror/buildhelper":"^1.0.2"},"_npmOperationalInternal":{"tmp":"tmp/codemirror-lang-swift_0.1.0_1785148621339_0.6916146204024674","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@codincod/codemirror-lang-swift","version":"0.1.1","keywords":["editor","code","swift","codemirror"],"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","_id":"@codincod/codemirror-lang-swift@0.1.1","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"homepage":"https://codincod.com/","dist":{"shasum":"522f58a06bb1b59594aa1b8b1f27db7e75769501","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-swift/-/codemirror-lang-swift-0.1.1.tgz","fileCount":14,"integrity":"sha512-moiou6PTgFIAA1yaFKQyfsUk2kjF1c5gxg8tYMr4UqwJ9BSw1r1i7vI41g0ToLR2LK14qSHGJEzuZmhQXbuM7g==","signatures":[{"sig":"MEQCIAeaMsjWdmMZqMaJZLl/rKnt2jMp799WahkBCwaoHMuEAiACZaa+3dEzA7YWLZ/R3uYJAxBp/xH7OK2wHucW1ys3dA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":363808},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{"import":"./dist/index.js","require":"./dist/index.cjs"},"gitHead":"4f0000c854d0917c0866068f86e2a204977382f0","scripts":{"test":"npm run build && node --test \"test/*.test.ts\"","build":"rm -rf dist && lezer-generator src/swift.grammar -o src/parser.js && cm-buildhelper src/swift.ts","corpus":"npm run build && node test/corpus.ts","prepare":"npm run build","build-debug":"lezer-generator src/swift.grammar --names -o src/parser.js && cm-buildhelper src/swift.ts"},"_npmUser":{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"},"repository":{"url":"git+https://codeberg.org/reeven/codemirror-lang-swift.git","type":"git"},"_npmVersion":"11.6.2","description":"Swift language support for the CodeMirror code editor","directories":{},"sideEffects":false,"_nodeVersion":"25.0.0","dependencies":{"@lezer/lr":"^1.0.0","@lezer/common":"^1.0.0","@lezer/highlight":"^1.0.0","@codemirror/language":"^6.0.0","@codemirror/autocomplete":"^6.0.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.6.0","@lezer/generator":"^1.7.0","@codemirror/state":"^6.7.1","@codemirror/buildhelper":"^1.0.2"},"_npmOperationalInternal":{"tmp":"tmp/codemirror-lang-swift_0.1.1_1785287105009_0.3241108343424919","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@codincod/codemirror-lang-swift","version":"0.1.2","keywords":["editor","code","swift","codemirror"],"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","_id":"@codincod/codemirror-lang-swift@0.1.2","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"homepage":"https://codincod.com/","dist":{"shasum":"091933e5fa675cfcd1234319564a855548e6f025","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-swift/-/codemirror-lang-swift-0.1.2.tgz","fileCount":14,"integrity":"sha512-j5FVGe+ZuB9bRJTQLInrqR2STYUSUsQ8YgK5H0DBstdA9sJLP4aGvwmthfN2xzw5U6f1yabey42IhsDKAoHE2w==","signatures":[{"sig":"MEQCIBs12KpIF6IRnhLtGjsa8ayVJya919OGV5wkonqdjR1yAiBh3Q50ZIkSDkPUK6IY3XQmfxOV7SmhU2tGiFKTjyJ4Hw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":363919},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{"import":"./dist/index.js","require":"./dist/index.cjs"},"gitHead":"6aeaf8c600597ba25be42e6e25b3b3fbdda17cbd","scripts":{"gaps":"npm run build && node ../lezer-survey/src/cli.ts gaps --group parent","test":"npm run build && node --test \"test/*.test.ts\"","build":"rm -rf dist && lezer-generator src/swift.grammar -o src/parser.js && cm-buildhelper src/swift.ts","corpus":"npm run build && node ../lezer-survey/src/cli.ts measure --group parent","prepare":"npm run build","build-debug":"lezer-generator src/swift.grammar --names -o src/parser.js && cm-buildhelper src/swift.ts"},"_npmUser":{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"},"repository":{"url":"https://codeberg.org/reeven/codemirror-lang-swift","type":"git"},"_npmVersion":"11.6.2","description":"Swift language support for the CodeMirror code editor","directories":{},"sideEffects":false,"_nodeVersion":"25.0.0","dependencies":{"@lezer/lr":"^1.0.0","@lezer/common":"^1.0.0","@lezer/highlight":"^1.0.0","@codemirror/language":"^6.0.0","@codemirror/autocomplete":"^6.0.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.6.0","@lezer/generator":"^1.7.0","@codemirror/state":"^6.7.1","@codemirror/buildhelper":"^1.0.2"},"_npmOperationalInternal":{"tmp":"tmp/codemirror-lang-swift_0.1.2_1785971098387_0.2110225892919826","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@codincod/codemirror-lang-swift","version":"0.2.0","keywords":["editor","code","swift","codemirror"],"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","_id":"@codincod/codemirror-lang-swift@0.2.0","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"homepage":"https://codincod.com/","dist":{"shasum":"f65a36bf323e5e3ddc8f190dc0b4b9d16bc2cd40","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-swift/-/codemirror-lang-swift-0.2.0.tgz","fileCount":14,"integrity":"sha512-NhPsIyzWV+DYxX4qlVkAiFxdBomD0xBc4icKQjZhi3k0cJFakxgvBYrBf/zDEAHRls/pme9uWhq7Db77dEDt0w==","signatures":[{"sig":"MEYCIQDiEW2HO5jELoqZJn/ARM5Yx3I8iFp7lLRhF4SDoOpUAgIhAKZ9JMzjXzs83flOn18v092VZ31oYYkEL5Q7N0odc1+C","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":443280},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{"import":"./dist/index.js","require":"./dist/index.cjs"},"gitHead":"f79c52d2e79a0d8fe2a28df448965befba809964","scripts":{"gaps":"npm run build && node ../lezer-survey/src/cli.ts gaps --group parent","test":"npm run build && node --test \"test/*.test.ts\"","build":"rm -rf dist && lezer-generator src/swift.grammar -o src/parser.js && cm-buildhelper src/swift.ts","corpus":"npm run build && node ../lezer-survey/src/cli.ts measure --group parent","prepare":"npm run build","build-debug":"lezer-generator src/swift.grammar --names -o src/parser.js && cm-buildhelper src/swift.ts"},"_npmUser":{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"},"repository":{"url":"https://codeberg.org/reeven/codemirror-lang-swift","type":"git"},"_npmVersion":"11.6.2","description":"Swift language support for the CodeMirror code editor","directories":{},"sideEffects":false,"_nodeVersion":"25.0.0","dependencies":{"@lezer/lr":"^1.0.0","@lezer/common":"^1.0.0","@lezer/highlight":"^1.0.0","@codemirror/language":"^6.0.0","@codemirror/autocomplete":"^6.0.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.6.0","@lezer/generator":"^1.7.0","@codemirror/state":"^6.7.1","@codemirror/buildhelper":"^1.0.2"},"_npmOperationalInternal":{"tmp":"tmp/codemirror-lang-swift_0.2.0_1786369543201_0.9236225895935735","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@codincod/codemirror-lang-swift","version":"0.3.0","description":"Swift language support for the CodeMirror code editor","keywords":["editor","code","swift","codemirror"],"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","type":"module","main":"dist/index.cjs","exports":{"import":"./dist/index.js","require":"./dist/index.cjs"},"module":"dist/index.js","types":"dist/index.d.ts","sideEffects":false,"scripts":{"build":"rm -rf dist && lezer-generator src/swift.grammar -o src/parser.js && cm-buildhelper src/swift.ts","build-debug":"lezer-generator src/swift.grammar --names -o src/parser.js && cm-buildhelper src/swift.ts","prepare":"npm run build","test":"npm run build && node --test \"test/*.test.ts\"","measure":"npm run build && node ../lezer-survey/src/cli.ts measure --group parent","fuzz":"npm run build && node ../lezer-survey/src/cli.ts fuzz","gaps":"npm run build && node ../lezer-survey/src/cli.ts gaps --group parent"},"dependencies":{"@codemirror/autocomplete":"^6.0.0","@codemirror/language":"^6.0.0","@lezer/highlight":"^1.0.0","@lezer/lr":"^1.0.0"},"devDependencies":{"@codemirror/buildhelper":"^1.0.2","@codemirror/state":"^6.7.1","@lezer/generator":"^1.7.0","typescript":"^5.6.0"},"homepage":"https://codincod.com/","repository":{"type":"git","url":"https://codeberg.org/reeven/codemirror-lang-swift"},"gitHead":"3bbed8ec5f27a6eefc2efb5e7de7e626583a00ab","_id":"@codincod/codemirror-lang-swift@0.3.0","_nodeVersion":"25.0.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-KUZWGAnkAPTYUC96bys7dhVNDClZi34/cSURjk/tVz0ZovEDT5yPNDTX8fLl/nCvnyI1XI4PqrsuLaFMT72wIA==","shasum":"ac16929287878e0ada5113334673a199480b536f","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-swift/-/codemirror-lang-swift-0.3.0.tgz","fileCount":14,"unpackedSize":443319,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIB/2n67yzqdPTGAItaQnS78iyKpVWLY+pXZ4oAmG3deNAiBsFufR0Fmue+SPkq2a9NmABEWqRt+MgCfDAJ+casTw8Q=="}]},"_npmUser":{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"},"directories":{},"maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/codemirror-lang-swift_0.3.0_1786761089695_0.0972912891054134"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-27T10:37:01.151Z","modified":"2026-08-15T02:31:30.029Z","0.1.0":"2026-07-27T10:37:01.488Z","0.1.1":"2026-07-29T01:05:05.189Z","0.1.2":"2026-08-05T23:04:58.562Z","0.2.0":"2026-08-10T13:45:43.367Z","0.3.0":"2026-08-15T02:31:29.839Z"},"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","homepage":"https://codincod.com/","keywords":["editor","code","swift","codemirror"],"repository":{"type":"git","url":"https://codeberg.org/reeven/codemirror-lang-swift"},"description":"Swift language support for the CodeMirror code editor","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"readme":"# @codincod/codemirror-lang-swift [![NPM version](https://img.shields.io/npm/v/@codincod/codemirror-lang-swift.svg)](https://www.npmjs.org/package/@codincod/codemirror-lang-swift)\n\n[ [**CHANGELOG**](https://codeberg.org/reeven/codemirror-lang-swift/src/branch/master/CHANGELOG.md) ]\n\nThis package implements Swift language support for the\n[CodeMirror](https://codemirror.net/) code editor, using a\n[Lezer](https://lezer.codemirror.net/) grammar written for this package.\n\nCodeMirror 6 has never shipped Swift. What it offers is the stream mode ported\nfrom CodeMirror 5, which colours a list of keywords and leaves no tree behind,\nso nothing above it can fold a function, indent a switch or ask what the word\nunder the cursor is. No Lezer grammar for Swift existed anywhere before this\none.\n\nWritten in part for [CodinCod](https://codincod.com/), a competitive coding\nplatform, where it colours the editor people solve puzzles in.\n\nThis code is released under an\n[MIT license](https://codeberg.org/reeven/codemirror-lang-swift/src/branch/master/LICENSE).\n\n## Usage\n\n```javascript\nimport {EditorView, basicSetup} from \"codemirror\"\nimport {swift} from \"@codincod/codemirror-lang-swift\"\n\nconst view = new EditorView({\n  parent: document.body,\n  doc: `struct Greeter {\n    let name: String\n\n    func greet() {\n        print(\"Hello, \\\\(name)!\")\n    }\n}\n`,\n  extensions: [basicSetup, swift()]\n})\n```\n\n## Coverage\n\nSwift 6.2. Async and await, actors, structured concurrency, opaque and\nexistential types (`some` and `any`), property wrappers, result builders,\nmacros, parameter packs, pattern matching, generics with where clauses, key\npaths, multi-line and raw strings, operator and precedence group declarations,\ntyped throws, suppressed conformances (`~Copyable`), `if` and `switch` as\nexpressions, more than one trailing closure on a call, and the trailing comma\n6.1 allows behind the last item of a list.\n\nThe Swift 1 and 2 spellings a decade of published code still carries are in\ntoo: `inout` in front of a parameter name, `var` parameters, curried functions,\nconstraints written inside the angle brackets, and the C-style `for` loop\nSwift 3 removed, written with its parentheses or without them.\n\nMeasured against 8620 files of Swift people ship, which is Apple's standard\nlibrary, swift-package-manager, swift-syntax, swift-nio, swift-collections,\nswift-corelibs-foundation, swift-crypto, swift-argument-parser,\nswift-algorithms, swift-composable-architecture, Alamofire, Vapor, RxSwift,\nReactiveSwift, lottie-ios, Kingfisher, Charts, realm-swift, Moya, SnapKit,\nSQLite.swift, SwiftyJSON and swift-log: 95.01% parse with no error node. The\n725 Swift files on Rosetta Code read 97.24%, and they are the softer of the two\nmeasurements, being task programs rather than packages.\n\nThe compiler's own `test` and `validation-test` trees are left out of that\ncorpus on purpose. They are inputs written to be rejected, and a parser is not\njudged on source the language refuses.\n\n## What a tokenizer has to settle\n\nAlmost all of Swift can be written down as a grammar. Eight things cannot, and\nthey are the whole of `tokens.ts`.\n\n**Whitespace decides what an operator is.** Swift's operator set is open, so\n`a - b`, `a -b` and `a-b` cannot be told apart by spelling. The language settles\nit by spacing: an operator with space on both sides or neither is infix, one\nwith space only in front is prefix, and one with space only behind is postfix.\nThe same rule separates `x!` from `!x`, and `a ?? b` from `x?.y`.\n\n**An angle bracket is two different things.** `Array<Int>` opens a generic\nargument list and `a < b` compares. Where a type is expected the parser has\nalready ruled the comparison out. Where an expression is expected, the tokenizer\nreads ahead for the closing bracket and takes the call or member access that\nfollows it as the proof, or the end of the line, which is what stands behind\n`typealias Result = Either<A, B>` and behind no chain of comparisons anybody\nwrites.\n\n**A second trailing closure carries a name.** `f { } onCancel: { }` has been in\nthe language since 5.3, and that name stands exactly where the next statement's\nfirst word would. Only the brace behind the colon tells them apart, so the\ntokenizer reads ahead for it, and asks the parser first: a label can stand only\nwhere a closure has just closed. Read as an ordinary label it would take every\n`var x: T {` in the language with it.\n\n**A function may be named by its argument labels.** `min(by: closer(lhs:rhs:))`\nhands over no arguments at all, and nothing tells that list from an ordinary one\nuntil the closing bracket, so the whole of it is one token.\n\n**A `#if` inside a switch holds whole cases.** The same directive holds\nstatements everywhere else, both can stand at the end of a case body, and the\ndirective says nothing about which. What settles it is the first word inside.\n\n**A brace is two different things.** `if x { }` is a condition and a body;\n`xs.map { }` is a call and a closure. Swift tells them apart by where the brace\nstands, so the tokenizer asks the parser whether a body could stand here and\nlets the answer decide. A closure that opens with a signature (`{ x in ... }`)\nis a third case, found by reading ahead for the `in` over nothing but what a\nsignature may hold.\n\n**Block comments nest.** A comment opened inside a comment has to be closed\ntwice, which no regular token can count.\n\n**A string holds code.** `\"total: \\(a + b)\"` is a string with an expression\ninside it, and that expression may hold another string. The tokenizer cuts the\nstring into pieces and the grammar parses what lies between them.\n\n## What the tree does not say\n\nTwo things are deliberately shallower than the language reference.\n\n**Operator precedence is flat.** Swift lets anybody declare an operator and give\nit a precedence group, so no fixed table here could be right about a program it\nhas not seen. Infix operators are one left-associative level, which is wrong\nabout the shape of `a + b * c` and right about every operator this grammar has\nnever heard of. A highlighter reads tokens rather than shapes.\n\n**Patterns are expressions.** `case .some(let x)` holds a binding that only\nappears in a pattern. Rather than carry a second grammar for patterns, `let x`\nis accepted as an expression and the tree says `BindingPattern` where a pattern\nwas written.\n\nRaw strings (`#\"...\"#`) are one token rather than a parsed string, because the\ndelimiter's pound count would have to be carried from the opening token to the\nclosing one. Nothing interpolates inside them anyway.\n","readmeFilename":"README.md"}