1.1.4 • Published 4 years ago
antlr-editor v1.1.4
Antlr Editor
See example into deployed Storybook
Usage
Install
yarn add antlr-editor antlr4ts monaco-editor react-monaco-editorAntlrEditor
import React, { useState } from "react";
import { AntlrEditor } from "antlr-editor";
import * as tools from "my-antlr-lib";
import { getSuggestions } from "./custom-suggestions";
const Editor = ({}) => {
const [script, setScript] = useState("");
const [errors, setErros] = useState([]);
const customTools = { ...tools, getSuggestionsFromRange: getSuggestions };
return (
<>
<AntlrEditor
script={script}
setScript={setScript}
languageVersion="my-language"
setErrors={setErrors}
variables={{}}
variableURLs={[]}
tools={customTools}
/>
{errors.length > 0 && <div>{`Errors: ${errors.join(" - ")}`}</div>}
</>
);
};
export default Editor;AntlrEditor Props
| Name | Type | Default value |
|---|---|---|
| script | string | - |
| setScript | Function | - |
| languageVersion | string | - |
| setErrors | Function | - |
| tools | Tools * | - |
| theme | string | vs-dark |
| variables | Variables * | { } |
| variableURLs | VariableURLs * | |
| options | Options * | {} |
See details about * props below
Props
tools
tools has to be mainly antlr4 auto-generated Lexer & Parser.
| Name | Type | Default value |
|---|---|---|
| id | string | - |
| initialRule | string | - |
| grammar | string | - |
| Lexer | Antlr4 Lexer | - |
| Parser | Antlr4 Parser | - |
| getSuggestionsFromRange | Function | () => [] |
Have a look to VTL 2.0 Antlr Tools for example.
variables
variables enable to pass an object to provide auto-suggestion.
The shape of this object is:
const obj = {
"var1": {"type": "STRING", "role": "IDENTIFIER"},
"var2": {"type": "INTEGER", "role": "MEASURE"},
}variableURLs
variableURLs enable to pass an array of string to fetch to provide auto-suggestion:
["http://metadata/1", "http://metadata/2"]The shape of each fetched resources has to be:
[
{ "name": "var1", "type": "STRING", "role": "IDENTIFIER" },
{ "name": "var2", "type": "INTEGER", "role": "MEASURE" }
]Options
The shape of options props has to be:
{
"minimap": "Values: true | false - Default: true",
"theme": "Values: 'vs-dark' | 'vs-light - Default: 'vs-dark'",
"hideLines": "Values: true | false - Default: false",
"style": {
"cssProperty": "value",
...
// Style props are applied to editor container
}
}1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago
0.1.21
4 years ago
0.1.20
4 years ago
0.1.19
4 years ago
0.1.18
4 years ago
0.1.17
4 years ago
0.1.16
4 years ago
0.1.15
4 years ago
0.1.13
4 years ago
0.1.12
4 years ago
0.1.11
4 years ago
0.1.9
4 years ago
0.1.8
4 years ago
0.1.7
4 years ago
0.1.6
4 years ago
0.1.5
4 years ago
0.1.4
4 years ago
0.1.3
4 years ago
0.1.2
4 years ago
0.1.1
4 years ago