Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new @flok/lang-punctual package; Do not autoclose on < and > #329

Merged
merged 5 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 61 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/lang-punctual/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
package-lock.json
/dist
5 changes: 5 additions & 0 deletions packages/lang-punctual/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/src
/test
/node_modules
rollup.config.js
tsconfig.json
21 changes: 21 additions & 0 deletions packages/lang-punctual/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 26 additions & 0 deletions packages/lang-punctual/README.md
Original file line number Diff line number Diff line change
@@ -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`.
33 changes: 33 additions & 0 deletions packages/lang-punctual/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
12 changes: 12 additions & 0 deletions packages/lang-punctual/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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()],
};
14 changes: 14 additions & 0 deletions packages/lang-punctual/src/indentation.ts
Original file line number Diff line number Diff line change
@@ -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;
}
});
}
7 changes: 7 additions & 0 deletions packages/lang-punctual/src/index.ts
Original file line number Diff line number Diff line change
@@ -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)];
}
10 changes: 10 additions & 0 deletions packages/lang-punctual/src/punctual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { haskell } from "@codemirror/legacy-modes/mode/haskell";

export const punctualLanguage = {
...haskell,
name: "punctual",
languageData: {
...haskell.languageData,
closeBrackets: { brackets: ["(", "[", "{", '"'], before: ')]}"' },
},
};
11 changes: 11 additions & 0 deletions packages/lang-punctual/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"strict": true,
"target": "es6",
"module": "es2020",
"newLine": "lf",
"declaration": true,
"moduleResolution": "node"
},
"include": ["src/*.ts"]
}
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -48,6 +49,7 @@ const langExtensionsByLanguage: { [lang: string]: any } = {
javascript: javascript,
python: python,
tidal: tidal,
punctual: punctual,
};
const panicCodes = panicCodesUntyped as { [target: string]: string };

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"hydra": "javascript",
"mercury-web": "javascript",
"mercury": "javascript",
"punctual": "tidal",
"punctual": "punctual",
"renardo": "python",
"sardine": "python",
"sclang": "javascript",
Expand Down
Loading