@making-sense/antlr-editor
Version:
ANTLR Typescript editor
136 lines (94 loc) • 5.64 kB
Markdown
[](https://github.com/Making-Sense-Info/ANTLR-Editor/actions/workflows/ci.yaml)
[](https://badge.fury.io/js/@making-sense%2Fantlr-editor)
[](https://making-sense-info.github.io/ANTLR-Editor)
ANTLR Typescript editor.
```bash
yarn add @making-sense/antlr-editor
```
```bash
yarn add @making-sense/antlr-editor @making-sense/vtl-2-1-antlr-tools-ts @making-sense/vtl-2-1-monaco-tools-ts
```
```typescript
import { AntlrEditor as VTLEditor } from "@making-sense/antlr-editor";
import * as VTLTools from "@making-sense/vtl-2-1-antlr-tools-ts";
import { getSuggestionsFromRange, monarchDefinition } from "@making-sense/vtl-2-1-monaco-tools-ts";
const customTools = { ...VTLTools, getSuggestionsFromRange, monarchDefinition };
const Editor = () => {
return <VTLEditor tools={customTools} />;
};
export default Editor;
```
```bash
yarn storybook
```
```bash
git clone https://github.com/Making-Sense-Info/ANTLR-Editor
cd ANTLR-Editor
yarn
yarn start-test-app
yarn link-in-app test-app
```
| Name | Type | Default value |
| ------------------ | :---------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: |
| script | string | - |
| setScript | Function | - |
| customFetcher | Function \* | - |
| tools | Tools \* | - |
| variables | Variables \* | { } |
| variablesInputURLs | VariableURLs \* | [ ] |
| onListErrors | Function | undefined |
| height | string | "50vh" |
| width | string | "100%" |
| theme | string | "vs-dark" |
| options | [IStandaloneEditorConstructionOptions](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html) | {} |
See details about \* props below
`tools` has to be Antlr4 auto-generated Lexer & Parser.
| Name | Type | Default value |
| ----------- | :-----------: | :-----------: |
| id | string | - |
| initialRule | string | - |
| grammar | string | - |
| Lexer | Antlr4 Lexer | - |
| Parser | Antlr4 Parser | - |
Have a look to [VTL 2.0 Antlr Tools](https://github.com/Making-Sense-Info/VTL-2.0-ANTLR-Tools-TS) for example.
Have a look to [VTL 2.0 Monaco Tools](https://github.com/Making-Sense-Info/VTL-2.0-Monaco-Tools-TS) for autosuggestion & highlighting example.
`customFetcher` enable to provide a custom fetch, adding Authorization header for instance:
```javascript
u => fetch(u, headers:{ Authorization: 'Bearer XXX'})
```
This function will be used to fetch `variableURLs` & `sdmxResultURL` props.
`variables` enable to pass an object to provide auto-suggestion.
The shape of this object is:
```json
const obj = {
"var1": {"type": "STRING", "role": "IDENTIFIER"},
"var2": {"type": "INTEGER", "role": "MEASURE"},
}
```
`variableURLs` enable to pass an array of string to fetch to provide auto-suggestion:
```json
["http://metadata/1", "http://metadata/2"]
```
The shape of each fetched resources has to be:
```json
[
{ "name": "var1", "type": "STRING", "role": "IDENTIFIER" },
{ "name": "var2", "type": "INTEGER", "role": "MEASURE" }
]
```