@exercism/highlightjs-jikiscript 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Exercism
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # JikiScript language support for Highlightjs
2
+
3
+ ![NPM Version](https://img.shields.io/npm/v/@exercism/highlightjs-jikiscript)
4
+
5
+ This repo contains the grammar for the JikiScript language.
6
+ The repo comes with a tiny grammar that shows some basic grammar that you can tweak for your purposes.
7
+
8
+ ⚠️ To ensure that the package can be integrated on the Exercism website, don't change the packages' versions:
9
+
10
+ ```json
11
+ "highlight.js": "^11.10.0"
12
+ ```
13
+
14
+ ## Install
15
+
16
+ - NPM: `npm install @exercism/highlightjs-jikiscript`
17
+ - Yarn: `yarn add @exercism/highlightjs-jikiscript`
18
+ - Bun: `bun add @exercism/highlightjs-jikiscript`
19
+
20
+ ## Prerequisites
21
+
22
+ - [Bun](https://bun.sh/)
23
+
24
+ ## Structure
25
+
26
+ The repo's source files are defined in [TypeScript](https://www.typescriptlang.org/).
27
+
28
+ The repo is structured as follows:
29
+
30
+ ```text
31
+ .
32
+ ├── src
33
+ │ ├── index.ts (the main plugin)
34
+ │ ├── syntax.grammar (the Lezer grammar)
35
+ │ └── syntax.grammar.d.ts (the grammar typings)
36
+ ├── test
37
+ │ ├── cases (test cases)
38
+ │ │ └ *.txt (test case)
39
+ │ └── grammar.test.ts (test file)
40
+ ├── index.html (dev server file)
41
+ ├── rollup.config.js (bundling config)
42
+ ├── tsconfig.json (typescript confif)
43
+ └── vite.config.js (vite dev server config)
44
+ ```
45
+
46
+ ## Setup
47
+
48
+ Run `bun install` to install all dependencies.
49
+
50
+ ## Developing
51
+
52
+ To help with development, run `bun run dev`.
53
+ This will start a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders the `index.html` file.
54
+ The `#editor` element gets populated with some sample source code of your choosing and then it will get transformed by the grammar defined in `src/syntax.grammar`.
55
+ Any changes to the grammar will auto-refresh the dev server's rendered contents.
56
+
57
+ ## Testing
58
+
59
+ The `test/cases` directory contains the tests files.
60
+ Run `bun test` to run these tests.
61
+
62
+ Note: test (case) files should be relatively small and focus on a single aspect of a grammar.
63
+
64
+ ## Publishing
65
+
66
+ Run `bun publish` to publish the plugin to NPM.
@@ -0,0 +1,74 @@
1
+ # replace-this-with-the-track-name language support for Highlightjs
2
+
3
+ ![NPM Version](https://img.shields.io/npm/v/@exercism/highlightjs-replace-this-with-the-track-slug)
4
+
5
+ This repo contains the grammar for the replace-this-with-the-track-name language.
6
+ The repo comes with a tiny grammar that shows some basic grammar that you can tweak for your purposes.
7
+
8
+ ⚠️ To ensure that the package can be integrated on the Exercism website, don't change the packages' versions:
9
+
10
+ ```json
11
+ "highlight.js": "^11.10.0"
12
+ ```
13
+
14
+ ## Install
15
+
16
+ - NPM: `npm install @exercism/highlightjs-replace-this-with-the-track-slug`
17
+ - Yarn: `yarn add @exercism/highlightjs-replace-this-with-the-track-slug`
18
+ - Bun: `bun add @exercism/highlightjs-replace-this-with-the-track-slug`
19
+
20
+ ## Prerequisites
21
+
22
+ - [Bun](https://bun.sh/)
23
+
24
+ ## Resources
25
+
26
+ - [CodeMirror](https://codemirror.net/docs/)
27
+ - [Lezer](https://lezer.codemirror.net/docs/guide/)
28
+ - [Writing a Grammar](https://lezer.codemirror.net/docs/guide/#writing-a-grammar)
29
+ - [Examples](https://lezer.codemirror.net/examples/)
30
+ - [Existing grammar files](https://github.com/search?q=org%3Alezer-parser+path%3A%2F.grammar%24%2F&type=code)
31
+
32
+ ## Structure
33
+
34
+ The repo's source files are defined in [TypeScript](https://www.typescriptlang.org/).
35
+
36
+ The repo is structured as follows:
37
+
38
+ ```text
39
+ .
40
+ ├── src
41
+ │ ├── index.ts (the main plugin)
42
+ │ ├── syntax.grammar (the Lezer grammar)
43
+ │ └── syntax.grammar.d.ts (the grammar typings)
44
+ ├── test
45
+ │ ├── cases (test cases)
46
+ │ │ └ *.txt (test case)
47
+ │ └── grammar.test.ts (test file)
48
+ ├── index.html (dev server file)
49
+ ├── rollup.config.js (bundling config)
50
+ ├── tsconfig.json (typescript confif)
51
+ └── vite.config.js (vite dev server config)
52
+ ```
53
+
54
+ ## Setup
55
+
56
+ Run `bun install` to install all dependencies.
57
+
58
+ ## Developing
59
+
60
+ To help with development, run `bun run dev`.
61
+ This will start a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders the `index.html` file.
62
+ The `#editor` element gets populated with some sample source code of your choosing and then it will get transformed by the grammar defined in `src/syntax.grammar`.
63
+ Any changes to the grammar will auto-refresh the dev server's rendered contents.
64
+
65
+ ## Testing
66
+
67
+ The `test/cases` directory contains the tests files.
68
+ Run `bun test` to run these tests.
69
+
70
+ Note: test (case) files should be relatively small and focus on a single aspect of a grammar.
71
+
72
+ ## Publishing
73
+
74
+ Run `bun publish` to publish the plugin to NPM.
@@ -0,0 +1,2 @@
1
+ import { type HLJSApi, type Language } from "highlight.js";
2
+ export default function (hljs: HLJSApi): Language;
@@ -0,0 +1 @@
1
+ function m(e){let a={scope:"string",begin:'"',end:'"'},o=e.C_LINE_COMMENT_MODE,t={controlKeyword:"repeat times repeat_until_game_over repeat_forever for each in with to return",definitionKeyword:"function set change",logicOperator:"and or is equals",keyword:"log do end for each if else function with set change to",literal:["false","true"]},r=Object.values(t).join(" ").split(" "),i=e.C_NUMBER_MODE,c=["true","false"],n={relevance:0,match:e.regex.either(...c),className:"bool"},d="> < >= <= == !=",s={relevance:0,match:e.regex.either(..."> < >= <= == !="),className:"operator"},g=[/\(/,/\)/],E={relevance:0,match:e.regex.either(...g),className:"paren"},l=[/\[/,/\]/],A={relevance:0,match:e.regex.either(...l),className:"squareBracket"},R=[/\*/,"%",/\+/,/\-/,/\//],p={relevance:0,match:e.regex.either(...R),className:"arithmeticOperator"},O={relevance:0,match:e.regex.concat("\\b(?!",r.join("|"),"\\b)",/[a-zA-Z_]\w*(?:[?!]|\b)/),className:"variableName"};return{name:"JikiScript",case_insensitive:!1,keywords:t,contains:[a,o,i,s,p,E,A,n,O]}}export{m as default};
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@exercism/highlightjs-jikiscript",
3
+ "module": "dist/jikiscript.ts",
4
+ "main": "dist/jikiscript.js",
5
+ "types": "dist/jikiscript.d.ts",
6
+ "type": "module",
7
+ "version": "0.0.1",
8
+ "author": {
9
+ "name": "Jeremy Walker"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "prepublishOnly": "bun build --minify src/jikiscript.ts --outdir dist",
16
+ "test": "bun test",
17
+ "dev": "vite"
18
+ },
19
+ "devDependencies": {
20
+ "@types/bun": "latest",
21
+ "@types/highlight.js": "^10.1.0",
22
+ "highlight.js": "^11.10.0",
23
+ "vite": "^5.4.11"
24
+ },
25
+ "peerDependencies": {
26
+ "typescript": "^5.4.5"
27
+ }
28
+ }
@@ -0,0 +1,91 @@
1
+ /*
2
+ Language: JikiScript
3
+ Description: A hightlightJS Package for JikiScript
4
+ Category: scripting
5
+ Authors: @iHiD and @erikschierboom
6
+ Maintainer: @iHiD
7
+ Website: https://exericsm.org/
8
+ */
9
+
10
+ import { type HLJSApi, type Language, type Mode } from "highlight.js";
11
+
12
+ export default function (hljs: HLJSApi): Language {
13
+
14
+ const STRING: Mode = {
15
+ scope: 'string',
16
+ begin: '"', end: '"'
17
+ }
18
+ const COMMENT: Mode = hljs.C_LINE_COMMENT_MODE
19
+ const KEYWORDS = {
20
+ controlKeyword: "repeat times repeat_until_game_over repeat_forever for each in with to return",
21
+ definitionKeyword: "function set change",
22
+ logicOperator: "and or is equals",
23
+ keyword: 'log do end for each if else function with set change to',
24
+ literal: ['false','true'],
25
+ }
26
+ const ALL_KWS = Object.values(KEYWORDS).join(" ").split(" ")
27
+
28
+ const NUMBERS: Mode = hljs.C_NUMBER_MODE
29
+
30
+ const BOOLEANS = ["true", "false"]
31
+ const BOOLEAN: Mode = {
32
+ relevance: 0,
33
+ match: hljs.regex.either(...BOOLEANS),
34
+ className: "bool"
35
+ };
36
+
37
+ const OPERATORS = "> < >= <= == !="
38
+ const OPERATOR: Mode = {
39
+ relevance: 0,
40
+ match: hljs.regex.either(...OPERATORS),
41
+ className: "operator"
42
+ };
43
+
44
+ const PARENS = [/\(/, /\)/];
45
+ const PAREN: Mode = {
46
+ relevance: 0,
47
+ match: hljs.regex.either(...PARENS),
48
+ className: "paren"
49
+ };
50
+
51
+ const SQUARE_BRACKETS = [/\[/, /\]/];
52
+ const SQUARE_BRACKET: Mode = {
53
+ relevance: 0,
54
+ match: hljs.regex.either(...SQUARE_BRACKETS),
55
+ className: "squareBracket"
56
+ };
57
+
58
+ const ARITHMETIC_OPERATORS = [/\*/, "%", /\+/, /\-/, /\//];
59
+ const ARITHMETIC_OPERATOR: Mode = {
60
+ relevance: 0,
61
+ match: hljs.regex.either(...ARITHMETIC_OPERATORS),
62
+ className: "arithmeticOperator"
63
+ };
64
+ const VARIABLE = {
65
+ relevance: 0,
66
+ match: hljs.regex.concat(
67
+ "\\b(?!",
68
+ ALL_KWS.join("|"),
69
+ "\\b)",
70
+ /[a-zA-Z_]\w*(?:[?!]|\b)/
71
+ ),
72
+ className: "variableName"
73
+ };
74
+
75
+ return {
76
+ name: "JikiScript",
77
+ case_insensitive: false,
78
+ keywords: KEYWORDS,
79
+ contains: [
80
+ STRING,
81
+ COMMENT,
82
+ NUMBERS,
83
+ OPERATOR,
84
+ ARITHMETIC_OPERATOR,
85
+ PAREN,
86
+ SQUARE_BRACKET,
87
+ BOOLEAN,
88
+ VARIABLE,
89
+ ],
90
+ };
91
+ }