Skip to content

Commit a6d14bc

Browse files
committed
Initial commit
1 parent d8247e1 commit a6d14bc

11 files changed

+978
-155
lines changed

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/src
2-
/test
32
/node_modules
43
rollup.config.js
54
tsconfig.json

LICENSE

+674-21
Large diffs are not rendered by default.

README.md

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
1-
# CodeMirror 6 language package template
1+
# Homescript Language Support for CodeMirror
22

3-
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.
3+
This package implements [Homescript](https://github.com/smarthome-go/homescript)
4+
language support for the [CodeMirror](https://codemirror.net/6/) code editor.
45

5-
Things you'll need to do (see the [language support example](https://codemirror.net/6/examples/lang-package/) for a more detailed tutorial):
6-
7-
* `git grep EXAMPLE` and replace all instances with your language name.
8-
9-
* 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.
10-
11-
* Adjust the metadata in `src/index.ts` to work with your new grammar.
12-
13-
* Adjust the grammar tests in `test/cases.txt`.
14-
15-
* Build (`npm run prepare`) and test (`npm test`).
16-
17-
* Rewrite this readme file.
18-
19-
* Optionally add a license.
20-
21-
* Publish. Put your package on npm under a name like `codemirror-lang-EXAMPLE`.
6+
This code is released under the [GPL-3.0-only license](./LICENSE).

dprint.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"lineWidth": 120,
3+
"indentWidth": 4,
4+
"useTabs": false,
5+
6+
"typescript": {
7+
"semiColons": "asi",
8+
"quoteStyle": "preferSingle",
9+
"quoteProps": "asNeeded",
10+
"singleBodyPosition": "sameLine",
11+
"nextControlFlowPosition": "sameLine",
12+
"arrowFunction.useParentheses": "preferNone",
13+
"enumDeclaration.memberSpacing": "newLine"
14+
},
15+
16+
"json": {
17+
"indentWidth": 2,
18+
"array.preferSingleLine": true
19+
},
20+
21+
"markdown": {
22+
"lineWidth": 80,
23+
"textWrap": "always"
24+
},
25+
26+
"prettier": {
27+
"printWidth": 100,
28+
"tabWidth": 4,
29+
"semi": false,
30+
"singleQuote": true,
31+
"trailingComma": "all",
32+
"arrowParens": "avoid",
33+
"proseWrap": "always",
34+
35+
"plugin.jsDoc": true,
36+
"yml.tabWidth": 2,
37+
"yaml.tabWidth": 2,
38+
"json.tabWidth": 2,
39+
"jsonc.tabWidth": 2,
40+
"json5.tabWidth": 2
41+
},
42+
43+
"includes": ["**/*"],
44+
"excludes": ["**/dist", "**/node_modules", "**/*-lock.json"],
45+
"plugins": [
46+
"https://plugins.dprint.dev/typescript-0.74.0.wasm",
47+
"https://plugins.dprint.dev/json-0.15.6.wasm",
48+
"https://plugins.dprint.dev/markdown-0.14.1.wasm",
49+
"https://plugins.dprint.dev/prettier-0.12.0.json@f8c34316196cf4d0fb2f51b19073331258e15e71a934ee04a7b3328db684c98f"
50+
]
51+
}

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2-
"name": "codemirror-lang-EXAMPLE",
2+
"name": "codemirror-lang-homescript",
33
"version": "0.1.0",
4-
"description": "EXAMPLE language support for CodeMirror",
4+
"description": "Homescript language support for CodeMirror",
5+
"author": "RubixDev",
6+
"license": "GPL-3.0-only",
57
"scripts": {
6-
"test": "mocha test/test.js",
7-
"prepare": "rollup -c"
8+
"prepare": "rollup -c",
9+
"fmt": "dprint fmt"
810
},
911
"type": "module",
1012
"main": "dist/index.cjs",
@@ -22,11 +24,10 @@
2224
},
2325
"devDependencies": {
2426
"@lezer/generator": "^1.0.0",
25-
"mocha": "^9.0.1",
27+
"dprint": "^0.32.1",
2628
"rollup": "^2.60.2",
2729
"rollup-plugin-dts": "^4.0.1",
2830
"rollup-plugin-ts": "^3.0.2",
2931
"typescript": "^4.3.4"
30-
},
31-
"license": "MIT"
32+
}
3233
}

rollup.config.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import typescript from "rollup-plugin-ts"
2-
import {lezer} from "@lezer/generator/rollup"
1+
import { lezer } from '@lezer/generator/rollup'
2+
import typescript from 'rollup-plugin-ts'
33

44
export default {
5-
input: "src/index.ts",
6-
external: id => id != "tslib" && !/^(\.?\/|\w:)/.test(id),
7-
output: [
8-
{file: "dist/index.cjs", format: "cjs"},
9-
{dir: "./dist", format: "es"}
10-
],
11-
plugins: [lezer(), typescript()]
5+
input: 'src/index.ts',
6+
external: id => id != 'tslib' && !/^(\.?\/|\w:)/.test(id),
7+
output: [
8+
{ file: 'dist/index.cjs', format: 'cjs' },
9+
{ dir: './dist', format: 'es' },
10+
],
11+
plugins: [lezer(), typescript()],
1212
}

src/index.ts

+53-26
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
1-
import {parser} from "./syntax.grammar"
2-
import {LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent} from "@codemirror/language"
3-
import {styleTags, tags as t} from "@lezer/highlight"
1+
import {
2+
delimitedIndent,
3+
foldInside,
4+
foldNodeProp,
5+
indentNodeProp,
6+
LanguageSupport,
7+
LRLanguage,
8+
} from '@codemirror/language'
9+
import { styleTags, tags as t } from '@lezer/highlight'
10+
import { parser } from './syntax.grammar'
411

5-
export const EXAMPLELanguage = LRLanguage.define({
6-
parser: parser.configure({
7-
props: [
8-
indentNodeProp.add({
9-
Application: delimitedIndent({closing: ")", align: false})
10-
}),
11-
foldNodeProp.add({
12-
Application: foldInside
13-
}),
14-
styleTags({
15-
Identifier: t.variableName,
16-
Boolean: t.bool,
17-
String: t.string,
18-
LineComment: t.lineComment,
19-
"( )": t.paren
20-
})
21-
]
22-
}),
23-
languageData: {
24-
commentTokens: {line: ";"}
25-
}
12+
export const HomescriptLanguage = LRLanguage.define({
13+
parser: parser.configure({
14+
props: [
15+
indentNodeProp.add({
16+
Application: delimitedIndent({ closing: ')', align: false }),
17+
}),
18+
foldNodeProp.add({
19+
Application: foldInside,
20+
}),
21+
styleTags({
22+
'for while loop if else try catch return break continue': t.controlKeyword,
23+
in: t.operatorKeyword,
24+
'let fn': t.definitionKeyword,
25+
'import from': t.moduleKeyword,
26+
as: t.keyword,
27+
Bool: t.bool,
28+
null: t.null,
29+
Type: t.typeName,
30+
'VariableName/Ident': t.variableName,
31+
'CallExpr/VariableName/Ident': t.function(t.variableName),
32+
Property: t.propertyName,
33+
'CallExpr/MemberExpr/Property': t.function(t.propertyName),
34+
'FnExpr/Ident': t.function(t.variableName),
35+
'Parameters/Ident': t.local(t.variableName),
36+
Comment: t.lineComment,
37+
Number: t.number,
38+
String: t.string,
39+
'+ - "*" "/" % "**"': t.arithmeticOperator,
40+
'|| &&': t.logicOperator,
41+
'< <= > >= "!=" ==': t.compareOperator,
42+
'=': t.definitionOperator,
43+
'( ) { }': t.bracket,
44+
'. , ;': t.separator,
45+
BuiltinFunc: t.standard(t.function(t.variableName)),
46+
BuiltinVar: t.standard(t.variableName),
47+
}),
48+
],
49+
}),
50+
languageData: {
51+
commentTokens: { line: '#' },
52+
},
2653
})
2754

28-
export function EXAMPLE() {
29-
return new LanguageSupport(EXAMPLELanguage)
55+
export function Homescript() {
56+
return new LanguageSupport(HomescriptLanguage)
3057
}

0 commit comments

Comments
 (0)