diff --git a/package-lock.json b/package-lock.json index 5886647..6a29914 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1179,6 +1179,10 @@ "resolved": "packages/cm-eval", "link": true }, + "node_modules/@flok-editor/lang-punctual": { + "resolved": "packages/lang-punctual", + "link": true + }, "node_modules/@flok-editor/lang-tidal": { "resolved": "packages/lang-tidal", "link": true @@ -17031,22 +17035,54 @@ } }, "node_modules/rollup": { - "version": "3.20.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.20.2.tgz", - "integrity": "sha512-3zwkBQl7Ai7MFYQE0y1MeQ15+9jsi7XxfrqwTb/9EK8D9C9+//EBR4M+CuA1KODRaNbFez/lWxA5vhEGZp4MUg==", + "version": "2.79.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.2.tgz", + "integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==", "dev": true, - "peer": true, "bin": { "rollup": "dist/bin/rollup" }, "engines": { - "node": ">=14.18.0", - "npm": ">=8.0.0" + "node": ">=10.0.0" }, "optionalDependencies": { "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-dts": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-4.2.3.tgz", + "integrity": "sha512-jlcpItqM2efqfIiKzDB/IKOS9E9fDvbkJSGw5GtK/PqPGS9eC3R3JKyw2VvpTktZA+TNgJRMu1NTv244aTUzzQ==", + "dev": true, + "dependencies": { + "magic-string": "^0.26.6" + }, + "engines": { + "node": ">=v12.22.12" + }, + "funding": { + "url": "https://github.com/sponsors/Swatinem" + }, + "optionalDependencies": { + "@babel/code-frame": "^7.18.6" + }, + "peerDependencies": { + "rollup": "^2.55", + "typescript": "^4.1" + } + }, + "node_modules/rollup-plugin-dts/node_modules/magic-string": { + "version": "0.26.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.7.tgz", + "integrity": "sha512-hX9XH3ziStPoPhJxLq1syWuZMxbDvGNbVchfrdCtanC7D13888bMFow61x8axrx+GfHLtVeAx2kxL7tTGRl+Ow==", + "dev": true, + "dependencies": { + "sourcemap-codec": "^1.4.8" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/rollup-plugin-ts": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/rollup-plugin-ts/-/rollup-plugin-ts-3.2.0.tgz", @@ -19895,8 +19931,8 @@ "typescript": "^4.3.4" } }, - "packages/lang-tidal": { - "name": "@flok-editor/lang-tidal", + "packages/lang-punctual": { + "name": "@flok-editor/lang-punctual", "version": "1.3.0", "license": "MIT", "dependencies": { @@ -19915,53 +19951,24 @@ "typescript": "^4.3.4" } }, - "packages/lang-tidal/node_modules/magic-string": { - "version": "0.26.7", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.7.tgz", - "integrity": "sha512-hX9XH3ziStPoPhJxLq1syWuZMxbDvGNbVchfrdCtanC7D13888bMFow61x8axrx+GfHLtVeAx2kxL7tTGRl+Ow==", - "dev": true, - "dependencies": { - "sourcemap-codec": "^1.4.8" - }, - "engines": { - "node": ">=12" - } - }, - "packages/lang-tidal/node_modules/rollup": { - "version": "2.79.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", - "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", - "dev": true, - "bin": { - "rollup": "dist/bin/rollup" - }, - "engines": { - "node": ">=10.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.2" - } - }, - "packages/lang-tidal/node_modules/rollup-plugin-dts": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-4.2.3.tgz", - "integrity": "sha512-jlcpItqM2efqfIiKzDB/IKOS9E9fDvbkJSGw5GtK/PqPGS9eC3R3JKyw2VvpTktZA+TNgJRMu1NTv244aTUzzQ==", - "dev": true, + "packages/lang-tidal": { + "name": "@flok-editor/lang-tidal", + "version": "1.3.0", + "license": "MIT", "dependencies": { - "magic-string": "^0.26.6" - }, - "engines": { - "node": ">=v12.22.12" - }, - "funding": { - "url": "https://github.com/sponsors/Swatinem" - }, - "optionalDependencies": { - "@babel/code-frame": "^7.18.6" + "@codemirror/language": "^6.0.0", + "@codemirror/legacy-modes": "^6.3.2", + "@lezer/highlight": "^1.0.0", + "@lezer/lr": "^1.0.0" }, - "peerDependencies": { - "rollup": "^2.55", - "typescript": "^4.1" + "devDependencies": { + "@lezer/generator": "^1.0.0", + "mocha": "^9.0.1", + "prettier": "^3.4.2", + "rollup": "^2.60.2", + "rollup-plugin-dts": "^4.0.1", + "rollup-plugin-ts": "^3.0.2", + "typescript": "^4.3.4" } }, "packages/pubsub": { @@ -20115,6 +20122,7 @@ "@codemirror/state": "^6.4.0", "@codemirror/view": "^6.23.0", "@flok-editor/cm-eval": "^1.3.0", + "@flok-editor/lang-punctual": "^1.3.0", "@flok-editor/lang-tidal": "^1.3.0", "@flok-editor/session": "^1.3.0", "@radix-ui/react-dialog": "^1.1.4", diff --git a/packages/lang-punctual/.gitignore b/packages/lang-punctual/.gitignore new file mode 100644 index 0000000..29d2e39 --- /dev/null +++ b/packages/lang-punctual/.gitignore @@ -0,0 +1,3 @@ +/node_modules +package-lock.json +/dist diff --git a/packages/lang-punctual/.npmignore b/packages/lang-punctual/.npmignore new file mode 100644 index 0000000..9bd9760 --- /dev/null +++ b/packages/lang-punctual/.npmignore @@ -0,0 +1,5 @@ +/src +/test +/node_modules +rollup.config.js +tsconfig.json diff --git a/packages/lang-punctual/LICENSE b/packages/lang-punctual/LICENSE new file mode 100644 index 0000000..4f66e82 --- /dev/null +++ b/packages/lang-punctual/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Damián Silvani and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/lang-punctual/README.md b/packages/lang-punctual/README.md new file mode 100644 index 0000000..e6ac469 --- /dev/null +++ b/packages/lang-punctual/README.md @@ -0,0 +1,26 @@ +# CodeMirror 6 language package template + +This is an example repository containing a minimal +[CodeMirror](https://codemirror.net/6/) language support package. The idea is to +clone it, rename it, and edit it to create support for a new language. + +Things you'll need to do (see the [language support example](https://codemirror.net/6/examples/lang-package/) +for a more detailed tutorial): + +- `git grep EXAMPLE` and replace all instances with your language name. + +- Rewrite the grammar in `src/syntax.grammar` to cover your language. See the + [Lezer system guide](https://lezer.codemirror.net/docs/guide/#writing-a-grammar) + for information on this file format. + +- Adjust the metadata in `src/index.ts` to work with your new grammar. + +- Adjust the grammar tests in `test/cases.txt`. + +- Build (`npm run prepare`) and test (`npm test`). + +- Rewrite this readme file. + +- Optionally add a license. + +- Publish. Put your package on npm under a name like `codemirror-lang-EXAMPLE`. diff --git a/packages/lang-punctual/package.json b/packages/lang-punctual/package.json new file mode 100644 index 0000000..677ff27 --- /dev/null +++ b/packages/lang-punctual/package.json @@ -0,0 +1,33 @@ +{ + "name": "@flok-editor/lang-punctual", + "version": "1.3.0", + "description": "Punctual language support for CodeMirror", + "scripts": { + "build": "rollup -c" + }, + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "types": "dist/index.d.ts", + "sideEffects": false, + "dependencies": { + "@codemirror/language": "^6.0.0", + "@codemirror/legacy-modes": "^6.3.2", + "@lezer/highlight": "^1.0.0", + "@lezer/lr": "^1.0.0" + }, + "devDependencies": { + "@lezer/generator": "^1.0.0", + "mocha": "^9.0.1", + "prettier": "^3.4.2", + "rollup": "^2.60.2", + "rollup-plugin-dts": "^4.0.1", + "rollup-plugin-ts": "^3.0.2", + "typescript": "^4.3.4" + }, + "license": "MIT" +} diff --git a/packages/lang-punctual/rollup.config.js b/packages/lang-punctual/rollup.config.js new file mode 100644 index 0000000..0c50c8c --- /dev/null +++ b/packages/lang-punctual/rollup.config.js @@ -0,0 +1,12 @@ +import typescript from "rollup-plugin-ts"; +import { lezer } from "@lezer/generator/rollup"; + +export default { + input: "src/index.ts", + external: (id) => id != "tslib" && !/^(\.?\/|\w:)/.test(id), + output: [ + { file: "dist/index.cjs", format: "cjs" }, + { dir: "./dist", format: "es" }, + ], + plugins: [lezer(), typescript()], +}; diff --git a/packages/lang-punctual/src/indentation.ts b/packages/lang-punctual/src/indentation.ts new file mode 100644 index 0000000..a8abfb6 --- /dev/null +++ b/packages/lang-punctual/src/indentation.ts @@ -0,0 +1,14 @@ +import { indentService } from "@codemirror/language"; + +export function indentation() { + return indentService.of((context, pos) => { + let { text, from } = context.lineAt(pos, -1); + let parse = text.slice(0, pos - from).match(/^([^$#]+)\$.*/); + + if (parse) { + return Math.min(parse[1].length, 8); + } else { + return 0; + } + }); +} diff --git a/packages/lang-punctual/src/index.ts b/packages/lang-punctual/src/index.ts new file mode 100644 index 0000000..3a90b42 --- /dev/null +++ b/packages/lang-punctual/src/index.ts @@ -0,0 +1,7 @@ +import { StreamLanguage } from "@codemirror/language"; +import { punctualLanguage } from "./punctual"; +import { indentation } from "./indentation"; + +export function punctual() { + return [indentation(), StreamLanguage.define(punctualLanguage)]; +} diff --git a/packages/lang-punctual/src/punctual.ts b/packages/lang-punctual/src/punctual.ts new file mode 100644 index 0000000..6ebad8c --- /dev/null +++ b/packages/lang-punctual/src/punctual.ts @@ -0,0 +1,10 @@ +import { haskell } from "@codemirror/legacy-modes/mode/haskell"; + +export const punctualLanguage = { + ...haskell, + name: "punctual", + languageData: { + ...haskell.languageData, + closeBrackets: { brackets: ["(", "[", "{", '"'], before: ')]}"' }, + }, +}; diff --git a/packages/lang-punctual/tsconfig.json b/packages/lang-punctual/tsconfig.json new file mode 100644 index 0000000..d876152 --- /dev/null +++ b/packages/lang-punctual/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es6", + "module": "es2020", + "newLine": "lf", + "declaration": true, + "moduleResolution": "node" + }, + "include": ["src/*.ts"] +} diff --git a/packages/web/package.json b/packages/web/package.json index d8dd33d..4d13d3a 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -45,6 +45,7 @@ "@codemirror/view": "^6.23.0", "@flok-editor/cm-eval": "^1.3.0", "@flok-editor/lang-tidal": "^1.3.0", + "@flok-editor/lang-punctual": "^1.3.0", "@flok-editor/session": "^1.3.0", "@radix-ui/react-dialog": "^1.1.4", "@radix-ui/react-dropdown-menu": "^2.1.4", diff --git a/packages/web/src/components/editor.tsx b/packages/web/src/components/editor.tsx index ce11684..2e850f9 100644 --- a/packages/web/src/components/editor.tsx +++ b/packages/web/src/components/editor.tsx @@ -29,6 +29,7 @@ import { } from "@codemirror/view"; import { evalKeymap, flashField, remoteEvalFlash } from "@flok-editor/cm-eval"; import { tidal } from "@flok-editor/lang-tidal"; +import { punctual } from "@flok-editor/lang-punctual"; import type { Document } from "@flok-editor/session"; import { highlightExtension } from "@strudel/codemirror"; import CodeMirror, { @@ -48,6 +49,7 @@ const langExtensionsByLanguage: { [lang: string]: any } = { javascript: javascript, python: python, tidal: tidal, + punctual: punctual, }; const panicCodes = panicCodesUntyped as { [target: string]: string }; diff --git a/packages/web/src/settings.json b/packages/web/src/settings.json index def74b6..fb4eb9a 100644 --- a/packages/web/src/settings.json +++ b/packages/web/src/settings.json @@ -18,7 +18,7 @@ "hydra": "javascript", "mercury-web": "javascript", "mercury": "javascript", - "punctual": "tidal", + "punctual": "punctual", "renardo": "python", "sardine": "python", "sclang": "javascript",