⚠️ This is unstable: Expect breaking changes until v1 is out.
bin/console importmap:require @valtzu/codemirror-lang-el
npm install @valtzu/codemirror-lang-el
yarn add @valtzu/codemirror-lang-el
<div id="editor"></div>
<script type="module">
import { EditorView, basicSetup } from "codemirror";
import { acceptCompletion } from "@codemirror/autocomplete";
import { keymap } from "@codemirror/view";
import { expressionlanguage } from "@valtzu/codemirror-lang-el";
import { defaultKeymap } from "@codemirror/commands";
let editor = new EditorView({
extensions: [
basicSetup,
keymap.of([...defaultKeymap, {key: "Tab", run: acceptCompletion}]),
expressionlanguage({
types: {
"User": {
identifiers: [
{ name: "self", type: ["User"], info: 'Self-reference for property-access demonstration purposes' },
{ name: "name", type: ["string"] },
{ name: "age", type: ["int"], info: "Years since birthday", detail: "years" },
],
functions: [
{ name: "isActive", returnType: ["bool"] },
{ name: "getGroup", args: [], returnType: ["Group"], info: 'Get the user group' },
],
},
"Group": {
identifiers: [{ name: "name", type: ["string"] }]
}
},
identifiers: [
{ name: "user", type: ["User"], info: 'This is the user' },
],
functions: [
{ name: "is_granted", args: [{name: "attributes", type: ["string"]}, {name: "object", type: ["object"], optional: true}], info: 'Check if subject has permission to the object', returnType: ['bool'] },
],
})
],
parent: document.getElementById('editor'),
doc: 'is_granted(user, user.self.getGroup())',
});
</script>
Contributions are accepted.