lang-feel 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 +21 -0
- package/README.md +11 -0
- package/dist/index.cjs +120 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +112 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2022-current Nico Rehwaldt <https://github.com/nikku>
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# lang-feel
|
|
2
|
+
|
|
3
|
+
[](https://github.com/nikku/lang-feel/actions/workflows/CI.yml)
|
|
4
|
+
|
|
5
|
+
This package implements the [DMN](https://www.omg.org/spec/DMN/) FEEL language support for the [CodeMirror code editor](https://codemirror.net/).
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Related
|
|
9
|
+
|
|
10
|
+
* [lezer-feel](https://github.com/nikku/lezer-feel) - FEEL grammar
|
|
11
|
+
* [feelin](https://github.com/nikku/feelin) - FEEL parser + interpreter
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var lezerFeel = require('lezer-feel');
|
|
6
|
+
var language = require('@codemirror/language');
|
|
7
|
+
var autocomplete = require('@codemirror/autocomplete');
|
|
8
|
+
|
|
9
|
+
// / A collection of FEEL-related
|
|
10
|
+
// / [snippets](#autocomplete.snippet).
|
|
11
|
+
const snippets = [
|
|
12
|
+
autocomplete.snippetCompletion('function(${params})\n\t${body}', {
|
|
13
|
+
label: 'function',
|
|
14
|
+
detail: 'definition',
|
|
15
|
+
type: 'keyword'
|
|
16
|
+
}),
|
|
17
|
+
autocomplete.snippetCompletion('for\n\t${a} in ${b}\nreturn\n\t${a}', {
|
|
18
|
+
label: 'for',
|
|
19
|
+
detail: 'expression',
|
|
20
|
+
type: 'keyword'
|
|
21
|
+
}),
|
|
22
|
+
autocomplete.snippetCompletion('every\n\t${a} in ${}\nsatisfies\n\t${a}', {
|
|
23
|
+
label: 'every',
|
|
24
|
+
detail: 'expression',
|
|
25
|
+
type: 'keyword'
|
|
26
|
+
}),
|
|
27
|
+
autocomplete.snippetCompletion('some\n\t${a} in ${}\nsatisfies\n\t${a}', {
|
|
28
|
+
label: 'some',
|
|
29
|
+
detail: 'expression',
|
|
30
|
+
type: 'keyword'
|
|
31
|
+
}),
|
|
32
|
+
autocomplete.snippetCompletion('if ${} then ${}', {
|
|
33
|
+
label: 'if',
|
|
34
|
+
detail: 'block',
|
|
35
|
+
type: 'keyword'
|
|
36
|
+
}),
|
|
37
|
+
autocomplete.snippetCompletion('if ${} then ${} else ${}', {
|
|
38
|
+
label: 'if',
|
|
39
|
+
detail: '/ else block',
|
|
40
|
+
type: 'keyword'
|
|
41
|
+
})
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
// / A language provider based on the [Lezer FEEL
|
|
45
|
+
// / parser](https://github.com/nikku/lezer-feel), extended with
|
|
46
|
+
// / highlighting and indentation information.
|
|
47
|
+
const feelLanguage = language.LRLanguage.define({
|
|
48
|
+
parser: lezerFeel.parser.configure({
|
|
49
|
+
props: [
|
|
50
|
+
language.indentNodeProp.add({
|
|
51
|
+
'Context': language.delimitedIndent({
|
|
52
|
+
closing: '}'
|
|
53
|
+
}),
|
|
54
|
+
'List FilterExpression': language.delimitedIndent({
|
|
55
|
+
closing: ']'
|
|
56
|
+
}),
|
|
57
|
+
'ParenthesizedExpression FunctionInvocation': language.delimitedIndent({
|
|
58
|
+
closing: ')'
|
|
59
|
+
}),
|
|
60
|
+
'ForExpression QuantifiedExpression IfExpression': language.continuedIndent({
|
|
61
|
+
except: /^\s*(then|else|return|satisfies)\b/
|
|
62
|
+
}),
|
|
63
|
+
'FunctionDefinition': language.continuedIndent({
|
|
64
|
+
except: /^\s*(\(|\))/
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
language.foldNodeProp.add({
|
|
68
|
+
Context: language.foldInside,
|
|
69
|
+
List: language.foldInside,
|
|
70
|
+
FunctionDefinition(node) {
|
|
71
|
+
const last = node.getChild(')');
|
|
72
|
+
if (!last)
|
|
73
|
+
return null;
|
|
74
|
+
return {
|
|
75
|
+
from: last.to,
|
|
76
|
+
to: node.to
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
}),
|
|
82
|
+
languageData: {
|
|
83
|
+
indentOnInput: /^\s*(\)|\}|\]|then|else|return|satisfies)$/,
|
|
84
|
+
commentTokens: {
|
|
85
|
+
line: '//',
|
|
86
|
+
block: {
|
|
87
|
+
open: '/*',
|
|
88
|
+
close: '*/'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// / A language provider for TypeScript.
|
|
94
|
+
const unaryTestsLanguage = feelLanguage.configure({ top: 'UnaryTests' });
|
|
95
|
+
// / Language provider for JSX.
|
|
96
|
+
const expressionsLanguage = feelLanguage.configure({ top: 'Expressions' });
|
|
97
|
+
const keywords = 'for return every some satisfies if then in function'.split(' ').map(kw => ({ label: kw, type: 'keyword' }));
|
|
98
|
+
const dontComplete = [
|
|
99
|
+
'String', 'Name',
|
|
100
|
+
'LineComment', 'BlockComment'
|
|
101
|
+
];
|
|
102
|
+
// / FEEL support. Includes [snippet](#lang-feel.snippets)
|
|
103
|
+
// / completion.
|
|
104
|
+
function feel(config = {}) {
|
|
105
|
+
const lang = config.dialect === 'unaryTests' ? unaryTestsLanguage : expressionsLanguage;
|
|
106
|
+
const contextualLang = lang.configure({
|
|
107
|
+
contextTracker: lezerFeel.trackVariables(config.context)
|
|
108
|
+
});
|
|
109
|
+
return new language.LanguageSupport(contextualLang, [
|
|
110
|
+
feelLanguage.data.of({
|
|
111
|
+
autocomplete: autocomplete.ifNotIn(dontComplete, autocomplete.completeFromList(snippets.concat(keywords)))
|
|
112
|
+
})
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exports.expressionsLanguage = expressionsLanguage;
|
|
117
|
+
exports.feel = feel;
|
|
118
|
+
exports.feelLanguage = feelLanguage;
|
|
119
|
+
exports.snippets = snippets;
|
|
120
|
+
exports.unaryTestsLanguage = unaryTestsLanguage;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LRLanguage, LanguageSupport } from '@codemirror/language';
|
|
2
|
+
import { Completion } from '@codemirror/autocomplete';
|
|
3
|
+
|
|
4
|
+
declare const feelLanguage: LRLanguage;
|
|
5
|
+
declare const unaryTestsLanguage: LRLanguage;
|
|
6
|
+
declare const expressionsLanguage: LRLanguage;
|
|
7
|
+
declare function feel(config?: {
|
|
8
|
+
dialect?: 'expressions' | 'unaryTests';
|
|
9
|
+
context?: Record<string, any>;
|
|
10
|
+
}): LanguageSupport;
|
|
11
|
+
|
|
12
|
+
declare const snippets: readonly Completion[];
|
|
13
|
+
|
|
14
|
+
export { expressionsLanguage, feel, feelLanguage, snippets, unaryTestsLanguage };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { parser, trackVariables } from 'lezer-feel';
|
|
2
|
+
import { LRLanguage, indentNodeProp, delimitedIndent, continuedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
|
|
3
|
+
import { snippetCompletion, ifNotIn, completeFromList } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
// / A collection of FEEL-related
|
|
6
|
+
// / [snippets](#autocomplete.snippet).
|
|
7
|
+
const snippets = [
|
|
8
|
+
/*@__PURE__*/snippetCompletion('function(${params})\n\t${body}', {
|
|
9
|
+
label: 'function',
|
|
10
|
+
detail: 'definition',
|
|
11
|
+
type: 'keyword'
|
|
12
|
+
}),
|
|
13
|
+
/*@__PURE__*/snippetCompletion('for\n\t${a} in ${b}\nreturn\n\t${a}', {
|
|
14
|
+
label: 'for',
|
|
15
|
+
detail: 'expression',
|
|
16
|
+
type: 'keyword'
|
|
17
|
+
}),
|
|
18
|
+
/*@__PURE__*/snippetCompletion('every\n\t${a} in ${}\nsatisfies\n\t${a}', {
|
|
19
|
+
label: 'every',
|
|
20
|
+
detail: 'expression',
|
|
21
|
+
type: 'keyword'
|
|
22
|
+
}),
|
|
23
|
+
/*@__PURE__*/snippetCompletion('some\n\t${a} in ${}\nsatisfies\n\t${a}', {
|
|
24
|
+
label: 'some',
|
|
25
|
+
detail: 'expression',
|
|
26
|
+
type: 'keyword'
|
|
27
|
+
}),
|
|
28
|
+
/*@__PURE__*/snippetCompletion('if ${} then ${}', {
|
|
29
|
+
label: 'if',
|
|
30
|
+
detail: 'block',
|
|
31
|
+
type: 'keyword'
|
|
32
|
+
}),
|
|
33
|
+
/*@__PURE__*/snippetCompletion('if ${} then ${} else ${}', {
|
|
34
|
+
label: 'if',
|
|
35
|
+
detail: '/ else block',
|
|
36
|
+
type: 'keyword'
|
|
37
|
+
})
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// / A language provider based on the [Lezer FEEL
|
|
41
|
+
// / parser](https://github.com/nikku/lezer-feel), extended with
|
|
42
|
+
// / highlighting and indentation information.
|
|
43
|
+
const feelLanguage = /*@__PURE__*/LRLanguage.define({
|
|
44
|
+
parser: /*@__PURE__*/parser.configure({
|
|
45
|
+
props: [
|
|
46
|
+
/*@__PURE__*/indentNodeProp.add({
|
|
47
|
+
'Context': /*@__PURE__*/delimitedIndent({
|
|
48
|
+
closing: '}'
|
|
49
|
+
}),
|
|
50
|
+
'List FilterExpression': /*@__PURE__*/delimitedIndent({
|
|
51
|
+
closing: ']'
|
|
52
|
+
}),
|
|
53
|
+
'ParenthesizedExpression FunctionInvocation': /*@__PURE__*/delimitedIndent({
|
|
54
|
+
closing: ')'
|
|
55
|
+
}),
|
|
56
|
+
'ForExpression QuantifiedExpression IfExpression': /*@__PURE__*/continuedIndent({
|
|
57
|
+
except: /^\s*(then|else|return|satisfies)\b/
|
|
58
|
+
}),
|
|
59
|
+
'FunctionDefinition': /*@__PURE__*/continuedIndent({
|
|
60
|
+
except: /^\s*(\(|\))/
|
|
61
|
+
})
|
|
62
|
+
}),
|
|
63
|
+
/*@__PURE__*/foldNodeProp.add({
|
|
64
|
+
Context: foldInside,
|
|
65
|
+
List: foldInside,
|
|
66
|
+
FunctionDefinition(node) {
|
|
67
|
+
const last = node.getChild(')');
|
|
68
|
+
if (!last)
|
|
69
|
+
return null;
|
|
70
|
+
return {
|
|
71
|
+
from: last.to,
|
|
72
|
+
to: node.to
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
}),
|
|
78
|
+
languageData: {
|
|
79
|
+
indentOnInput: /^\s*(\)|\}|\]|then|else|return|satisfies)$/,
|
|
80
|
+
commentTokens: {
|
|
81
|
+
line: '//',
|
|
82
|
+
block: {
|
|
83
|
+
open: '/*',
|
|
84
|
+
close: '*/'
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
// / A language provider for TypeScript.
|
|
90
|
+
const unaryTestsLanguage = /*@__PURE__*/feelLanguage.configure({ top: 'UnaryTests' });
|
|
91
|
+
// / Language provider for JSX.
|
|
92
|
+
const expressionsLanguage = /*@__PURE__*/feelLanguage.configure({ top: 'Expressions' });
|
|
93
|
+
const keywords = /*@__PURE__*/'for return every some satisfies if then in function'.split(' ').map(kw => ({ label: kw, type: 'keyword' }));
|
|
94
|
+
const dontComplete = [
|
|
95
|
+
'String', 'Name',
|
|
96
|
+
'LineComment', 'BlockComment'
|
|
97
|
+
];
|
|
98
|
+
// / FEEL support. Includes [snippet](#lang-feel.snippets)
|
|
99
|
+
// / completion.
|
|
100
|
+
function feel(config = {}) {
|
|
101
|
+
const lang = config.dialect === 'unaryTests' ? unaryTestsLanguage : expressionsLanguage;
|
|
102
|
+
const contextualLang = lang.configure({
|
|
103
|
+
contextTracker: trackVariables(config.context)
|
|
104
|
+
});
|
|
105
|
+
return new LanguageSupport(contextualLang, [
|
|
106
|
+
feelLanguage.data.of({
|
|
107
|
+
autocomplete: ifNotIn(dontComplete, completeFromList(snippets.concat(keywords)))
|
|
108
|
+
})
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { expressionsLanguage, feel, feelLanguage, snippets, unaryTestsLanguage };
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lang-feel",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "FEEL language support for the CodeMirror code editor",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"all": "run-s lint build test",
|
|
7
|
+
"test": "cm-runtests",
|
|
8
|
+
"lint": "eslint . --ext ts",
|
|
9
|
+
"build": "cm-buildhelper src/index.ts",
|
|
10
|
+
"prepare": "npm run build",
|
|
11
|
+
"dev": "chokidar 'src/*.ts' 'test/*.ts' --initial -c 'npm run build && npm test'"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"editor",
|
|
15
|
+
"code"
|
|
16
|
+
],
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Nico Rehwaldt",
|
|
19
|
+
"url": "https://github.com/nikku"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "dist/index.cjs",
|
|
23
|
+
"exports": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"module": "dist/index.js",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@codemirror/autocomplete": "^6.0.0",
|
|
33
|
+
"@codemirror/language": "^6.0.0",
|
|
34
|
+
"@codemirror/state": "^6.0.0",
|
|
35
|
+
"@codemirror/view": "^6.0.0",
|
|
36
|
+
"@lezer/common": "^1.0.0",
|
|
37
|
+
"lezer-feel": "^0.14.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@codemirror/buildhelper": "^0.1.5",
|
|
41
|
+
"@lezer/lr": "^1.0.0",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.37.0",
|
|
43
|
+
"@typescript-eslint/parser": "^5.37.0",
|
|
44
|
+
"chokidar": "^3.5.3",
|
|
45
|
+
"chokidar-cli": "^3.0.0",
|
|
46
|
+
"eslint": "^8.23.1",
|
|
47
|
+
"eslint-plugin-bpmn-io": "^0.16.0",
|
|
48
|
+
"npm-run-all": "^4.1.5",
|
|
49
|
+
"typescript": "^4.8.3"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/nikku/lang-feel.git"
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist"
|
|
57
|
+
]
|
|
58
|
+
}
|