{"_id":"@codincod/codemirror-lang-dc","_rev":"3-17cbbff59dfe2f7c76212c82880ad696","name":"@codincod/codemirror-lang-dc","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"@codincod/codemirror-lang-dc","version":"0.1.0","keywords":["calculator","code","codemirror","dc","editor"],"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","_id":"@codincod/codemirror-lang-dc@0.1.0","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"homepage":"https://codincod.com/","dist":{"shasum":"0c08e83b6539ab9140dc4a208dc72be8b9a064b1","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-dc/-/codemirror-lang-dc-0.1.0.tgz","fileCount":13,"integrity":"sha512-AOyGQKyg2ZPHBBvw8nImdJZaUXk7p0LSDc17jesJ0PxmjQp457FynjKgOQOT5ehEvKNK97Ja7evp51fckIUPxg==","signatures":[{"sig":"MEUCIHHj6SbqYmgZkoJlNwnEdV5ewyrQTm/mu5uQKXwyQKClAiEAz1JiM3ua4HDKGkxxvWSFu7QWfDmW/E7hoC4NhE/qxI8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":42823},"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":"82509c78caf907c15f219fd5e937bd7bf2f2f8cb","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/dc.grammar -o src/parser.js && cm-buildhelper src/dc.ts","corpus":"npm run build && node ../lezer-survey/src/cli.ts measure --group parent","prepare":"npm run build","build-debug":"lezer-generator src/dc.grammar --names -o src/parser.js && cm-buildhelper src/dc.ts"},"_npmUser":{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"},"repository":{"url":"https://codeberg.org/reeven/codemirror-lang-dc","type":"git"},"_npmVersion":"11.6.2","description":"dc 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"},"_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-dc_0.1.0_1786135753825_0.2941370803918386","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@codincod/codemirror-lang-dc","version":"0.2.0","keywords":["calculator","code","codemirror","dc","editor"],"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","_id":"@codincod/codemirror-lang-dc@0.2.0","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"homepage":"https://codincod.com/","dist":{"shasum":"3664aa120027b159d19d91fe999f56c880df4eb1","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-dc/-/codemirror-lang-dc-0.2.0.tgz","fileCount":13,"integrity":"sha512-f5CwG457sTxAtOwHGK7pQcMv0zBGUV0eiZ36SsBZ4X14nCfrMqSOy7Mu7Iw87EGAgJlvvNwfLXGxY8hlXn1ejw==","signatures":[{"sig":"MEUCICeCXTJrVK2gOhSCjaUk0Q7nsjitWd1L9cjpscN8EN4/AiEAtk7N52V9imaUkmz5Q0kRX9OdiyZy8lP6YCZSG+Vf/YU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":52366},"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":"f55cdea01f1696615c787fff9f51bca6897507c0","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/dc.grammar -o src/parser.js && cm-buildhelper src/dc.ts","corpus":"npm run build && node ../lezer-survey/src/cli.ts measure --group parent","prepare":"npm run build","build-debug":"lezer-generator src/dc.grammar --names -o src/parser.js && cm-buildhelper src/dc.ts"},"_npmUser":{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"},"repository":{"url":"https://codeberg.org/reeven/codemirror-lang-dc","type":"git"},"_npmVersion":"11.6.2","description":"dc 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"},"_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-dc_0.2.0_1786139713257_0.6726340497218035","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@codincod/codemirror-lang-dc","version":"0.3.0","description":"dc language support for the CodeMirror code editor","keywords":["calculator","code","codemirror","dc","editor"],"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/dc.grammar -o src/parser.js && cm-buildhelper src/dc.ts","build-debug":"lezer-generator src/dc.grammar --names -o src/parser.js && cm-buildhelper src/dc.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/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-dc"},"gitHead":"f44e9d5ecdc96c021eed76c3834afee425e78167","_id":"@codincod/codemirror-lang-dc@0.3.0","_nodeVersion":"25.0.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-Xyh95cW8/U1ESRGnCc6S+lUVeJcPrzL95b+qJQrSIGSQKtYyQ9s/n4FvQqtcchxW3CfE15k8HkGKAaljLGAARQ==","shasum":"a5435a573b40c2684f311caab3fba6b15a1ed976","tarball":"https://registry.npmjs.org/@codincod/codemirror-lang-dc/-/codemirror-lang-dc-0.3.0.tgz","fileCount":13,"unpackedSize":52405,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBtyhVVTsSOTcYGPmcD9R0Ws0xKHocWzZW8ZtUPp5p4aAiAgE3VGIb0JXHUs+0mpVtRL8eAdxkWoW6kZupRYmSlisg=="}]},"_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-dc_0.3.0_1786759589383_0.7137076661298252"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-07T20:49:13.706Z","modified":"2026-08-15T02:06:29.694Z","0.1.0":"2026-08-07T20:49:13.987Z","0.2.0":"2026-08-07T21:55:13.554Z","0.3.0":"2026-08-15T02:06:29.523Z"},"author":{"name":"CodinCod","email":"hello@codincod.com"},"license":"MIT","homepage":"https://codincod.com/","keywords":["calculator","code","codemirror","dc","editor"],"repository":{"type":"git","url":"https://codeberg.org/reeven/codemirror-lang-dc"},"description":"dc language support for the CodeMirror code editor","maintainers":[{"name":"juicemitapfelndrin","email":"juicemitapfelndrin@gmail.com"}],"readme":"# @codincod/codemirror-lang-dc\n\nThis package implements [dc](https://en.wikipedia.org/wiki/Dc_(computer_program))\nlanguage support for the [CodeMirror](https://codemirror.net/) code editor: a\n[Lezer](https://lezer.codemirror.net/) grammar and highlighting.\n\ndc is the reverse-Polish desk calculator that ships with every Unix, and it is\na programming language because of one character: `[` collects everything up to\nits matching `]` into a string, and `x` executes a string.\n\nNo grammar for dc existed anywhere before this one, in the Lezer generation,\nin the CodeMirror 5 modes, or in tree-sitter.\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-dc/src/branch/master/LICENSE).\n\n## Usage\n\n```javascript\nimport {EditorView, basicSetup} from \"codemirror\"\nimport {dc} from \"@codincod/codemirror-lang-dc\"\n\nconst view = new EditorView({\n  parent: document.body,\n  doc: `[d lp * sp 1 - d 1 <f]Sf   [product = product * n]sz\n1 Sp 50 lfx Lp p\n`,\n  extensions: [basicSetup, dc()]\n})\n```\n\n## What it reads\n\nA bracket holds code, or it holds text, and dc cannot tell which until\nsomething executes one. All three uses are written the same way:\n\n```\n[d lp * sp 1 - d 1 <f]sf   a macro, stored to be called\n[Take one down, ]P         a string, printed\n[product = 1]sz            a comment: pushed, stored nowhere, forgotten\n```\n\nReading all three as strings leaves a dc program with almost no colour in it,\nbecause 84% of the characters in real dc code sit inside brackets. Reading all\nthree as code turns every sentence into a rainbow, because `P`, `r`, `i`, `n`\nand `t` are each a command.\n\nSo the tokenizer decides, on a fact about the language rather than a guess\nabout English: a bracket holds code when every character in it is one dc has a\nmeaning for. `Take one down` cannot be code, because dc has no `T`. `mul: `\ncannot, because it has no `m`. A register command with nothing left to name is\nnot code either, which is what gives `[Loop:]` away as a heading. And a bracket\nthat is printed rather than executed is text whatever it is spelled with, which\nis why `[Fizz]P` is a word and not four commands.\n\nRegisters are the other half. The character after `s`, `l`, `:`, `;`, `<`, `>`\nor `=` is the name of a register, whatever character it happens to be: real\nprograms use `s!`, `S@`, `s.` and `s#`, and dc will take a space if you leave\none. Nothing about that character may be interpreted, which is why this is a\ngrammar rather than a table of one-character tokens.\n\nThe alphabet is GNU's, and the commands BSD dc adds are in it where they can\nbe: `G`, `J`, `M`, `N` and `R`, the four bracket comparisons `(`, `)`, `{` and\n`}`, and the else. An uppercase letter is rare in the middle of an English\nsentence and a bracket is rarer, so none of those cost anything. The BSD\ncommands spelled with a lowercase letter (`m`, `t`, `u`, `w`, `y`) are left\nout, because a lowercase letter is what prose is made of: admitting them costs\nmore sentences than it explains programs, and each was measured before it was\nleft out.\n\nThe else is the exception, and the one character in dc with no token of its\nown. `>ReS` runs `S` when the comparison fails, so an `e` is a command\nimmediately after a comparison and its register, and a letter everywhere else.\nAn external tokenizer reads what stands behind it.\n\n## What it was measured on\n\nTwo bodies of dc, because they are written by different people for different\nreasons.\n\nThe first is every dc program on Rosetta Code, which is very nearly all the dc\nanybody has published: 101 files, 1201 lines. 97 parse with no error node. The\nfour that do not are shell command lines someone pasted above their program\n(`dc -e '22 7/p'`, `echo '12345678899' | dc inc.dc`), so every actual dc\nprogram in it parses clean.\n\nThe second is the dc that implementers write: Gavin Howard's bc test suite and\nOpenBSD's dc regression tests, 70 files of working dc. 69 parse clean. The one\nthat does not stores into OpenBSD's extended registers, which are named by the\nraw byte 255 and the two bytes behind it, on 514 of its 570 lines. A raw byte\nis not a character and an editor holds decoded text, so that file cannot be put\nin a CodeMirror document at all, let alone parsed in one.\n\nNeither figure means as much as it looks. A character dc has no answer for is a\nnode of its own rather than a failure, so this grammar has almost nothing to\nfail at. 30 of the 33 files in Howard's suite that exist to be rejected by dc\nparse clean here. A C file gives one error node, a JSON file one, a page of\nEnglish four. Treat a clean parse as evidence of very little, and 101 files as\nwhat they are: enough to say the true rate is above 97%, and nothing stronger.\n\nThe number that means something is the one the grammar exists to decide. Across\nthe Rosetta corpus it reads 371 brackets as code and 392 as text, no dense run\nof commands is read as text, and 55% of the characters end up coloured as text.\nNearly three quarters of that is the comment convention: a sentence pushed and\ndropped into a register nothing reads. dc programs really are that much\nEnglish, and one colour covers all of it, because dc has no comment syntax and\nno way to tell a comment from a string it means to print.\n\nThe second corpus was worth fetching. It found the four commands above, and\none bug: an else was read after any command that names a register rather than\nonly after a comparison, which made code of `[A = R[54] = seed]` by reading the\n`se` of \"seed\" as a store and the `e` behind it as an else.\n\n`#` is a comment to the end of the line in GNU dc, and almost nothing in the\nwild uses it. One program in the corpus contains a `#`, as the name of a\nregister.\n","readmeFilename":"README.md"}