1.1.4 • Published 3 years ago

antlr-editor v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Antlr Editor

ci npm version License: MIT

See example into deployed Storybook

Usage

Install

yarn add antlr-editor antlr4ts monaco-editor react-monaco-editor

AntlrEditor

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

NameTypeDefault value
scriptstring-
setScriptFunction-
languageVersionstring-
setErrorsFunction-
toolsTools *-
themestringvs-dark
variablesVariables *{ }
variableURLsVariableURLs *
optionsOptions *{}

See details about * props below

Props

tools

tools has to be mainly antlr4 auto-generated Lexer & Parser.

NameTypeDefault value
idstring-
initialRulestring-
grammarstring-
LexerAntlr4 Lexer-
ParserAntlr4 Parser-
getSuggestionsFromRangeFunction() => []

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

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.21

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago