react-dsl-editor 0.2.3 → 0.3.2
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/dist/index.d.ts +80 -41
- package/dist/react-dsl-editor.js +1210 -398
- package/package.json +7 -3
package/dist/index.d.ts
CHANGED
|
@@ -2,85 +2,124 @@ import { CSSProperties } from 'react';
|
|
|
2
2
|
import { JSX } from 'react/jsx-runtime';
|
|
3
3
|
import { TextareaHTMLAttributes } from 'react';
|
|
4
4
|
|
|
5
|
-
export declare function alternative<T extends string>(
|
|
5
|
+
export declare function alternative<T extends string>(...seq: GrammarNode<T>[]): GrammarNode<T>;
|
|
6
6
|
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function asException<T extends string>(error: ParserError<T>): ParsingError;
|
|
8
8
|
|
|
9
|
-
export declare
|
|
10
|
-
|
|
11
|
-
export declare interface ASTNode<T extends string> {
|
|
12
|
-
type: T;
|
|
9
|
+
export declare interface CSTNode<T extends string> {
|
|
13
10
|
text: string;
|
|
14
|
-
children?: ASTNode<T>[];
|
|
15
|
-
errors: ParserError<T>[];
|
|
16
11
|
offset: number;
|
|
12
|
+
end: number;
|
|
13
|
+
grammar: GrammarNode<T>;
|
|
14
|
+
children?: CSTNode<T>[];
|
|
15
|
+
recoverableError: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare type CSTOf<T> = CSTNode<_NodeTypes<T>>;
|
|
19
|
+
|
|
20
|
+
export declare interface DSL<T extends string> {
|
|
21
|
+
cst: CSTNode<T>;
|
|
22
|
+
terminals: CSTNode<T>[];
|
|
23
|
+
result: ParserSuccess<T>;
|
|
24
|
+
strictResult: ParserSuccess<T> | undefined;
|
|
25
|
+
errors: DSLError[];
|
|
17
26
|
}
|
|
18
27
|
|
|
19
|
-
export declare function DslEditor<T extends string>({ code, onChange, onParsed, grammar, wrap, suggestions: clientSuggestions, className,
|
|
28
|
+
export declare function DslEditor<T extends string>({ code, onChange, onParsed, grammar, wrap, suggestions: clientSuggestions, className, syntaxColors, ...textareaProps }: {
|
|
20
29
|
code: string;
|
|
21
30
|
onChange: (text: string) => void;
|
|
22
|
-
onParsed?: (
|
|
23
|
-
grammar:
|
|
31
|
+
onParsed?: (dsl: DSL<T>) => void;
|
|
32
|
+
grammar: GrammarNode<T>;
|
|
24
33
|
wrap?: boolean;
|
|
25
34
|
className?: string;
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
suggestions?: (node: CSTNode<T>) => string[] | undefined;
|
|
36
|
+
syntaxColors?: SyntaxColorsProvider;
|
|
28
37
|
} & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'wrap' | 'onChange'>): JSX.Element;
|
|
29
38
|
|
|
30
|
-
export declare
|
|
39
|
+
export declare interface DSLError {
|
|
40
|
+
message: string;
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
}
|
|
31
44
|
|
|
32
|
-
export declare
|
|
45
|
+
export declare class DSLParser<T extends string> {
|
|
46
|
+
private readonly grammar;
|
|
47
|
+
constructor(grammar: GrammarNode<T>);
|
|
48
|
+
parse(input: string): DSL<T>;
|
|
49
|
+
}
|
|
33
50
|
|
|
34
|
-
export declare
|
|
51
|
+
export declare const eof: GrammarNode;
|
|
35
52
|
|
|
36
|
-
declare
|
|
53
|
+
export declare function error<T extends string>(param: Omit<ParserError<T>, 'offset'>): {
|
|
54
|
+
offset: number;
|
|
55
|
+
grammar: GrammarNode<T>;
|
|
56
|
+
got: string;
|
|
57
|
+
expected: string[];
|
|
58
|
+
};
|
|
37
59
|
|
|
38
|
-
export declare
|
|
60
|
+
export declare interface GrammarNode<T extends string = never> {
|
|
61
|
+
type: T;
|
|
62
|
+
suggestions(): string[];
|
|
63
|
+
parse(text: string, context: ParserContext): ParserResult<T>;
|
|
64
|
+
children: GrammarNode<T>[];
|
|
65
|
+
meta?: Record<string, unknown>;
|
|
66
|
+
}
|
|
39
67
|
|
|
40
|
-
export declare
|
|
68
|
+
export declare function isParserError<T extends string>(result: ParserResult<T>): result is ParserError<T>;
|
|
41
69
|
|
|
42
|
-
export declare
|
|
70
|
+
export declare function isParserSuccess<T extends string>(result: ParserResult<T>): result is ParserSuccess<T>;
|
|
43
71
|
|
|
44
|
-
export declare
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
export declare function named<T extends string, K extends string>(name: T, child: GrammarNode<K>): GrammarNode<T | K>;
|
|
73
|
+
|
|
74
|
+
export declare type NodeTypes<T> = _NodeTypes<T> | 'error';
|
|
75
|
+
|
|
76
|
+
declare type _NodeTypes<T> = T extends GrammarNode<infer U> ? U : never;
|
|
77
|
+
|
|
78
|
+
export declare function optional<T extends string>(child: GrammarNode<T>): GrammarNode<T>;
|
|
79
|
+
|
|
80
|
+
export declare interface ParserContext {
|
|
81
|
+
faultTolerant: boolean;
|
|
82
|
+
faultCorrection<T extends string>(parse: ParserResult<T>, grammar: GrammarNode<T>): ParserResult<T>;
|
|
48
83
|
}
|
|
49
84
|
|
|
50
|
-
export declare interface ParserError<T> {
|
|
51
|
-
|
|
52
|
-
expected: string | RegExp;
|
|
85
|
+
export declare interface ParserError<T extends string = never> {
|
|
86
|
+
grammar: GrammarNode<T>;
|
|
53
87
|
got: string;
|
|
54
|
-
|
|
88
|
+
expected: string[];
|
|
89
|
+
offset: number;
|
|
55
90
|
}
|
|
56
91
|
|
|
57
|
-
export declare
|
|
58
|
-
|
|
92
|
+
export declare type ParserResult<T extends string = never> = ParserSuccess<T> | ParserError<T>;
|
|
93
|
+
|
|
94
|
+
export declare interface ParserSuccess<T extends string = never> {
|
|
59
95
|
text: string;
|
|
60
|
-
|
|
61
|
-
|
|
96
|
+
grammar: GrammarNode<T>;
|
|
97
|
+
children: ParserSuccess<T>[];
|
|
98
|
+
recoverableError?: boolean;
|
|
62
99
|
}
|
|
63
100
|
|
|
64
101
|
export declare class ParsingError extends Error {
|
|
65
102
|
constructor(msg: string);
|
|
66
103
|
}
|
|
67
104
|
|
|
68
|
-
export declare function pattern(regex:
|
|
105
|
+
export declare function pattern(regex: RegExp): GrammarNode<never>;
|
|
106
|
+
|
|
107
|
+
export declare const rational: GrammarNode<never>;
|
|
69
108
|
|
|
70
|
-
export declare function
|
|
109
|
+
export declare function repeat<T extends string>(child: GrammarNode<T>, min?: number, max?: number): GrammarNode<T>;
|
|
71
110
|
|
|
72
|
-
export declare
|
|
111
|
+
export declare function seq<T extends string>(...nodes: GrammarNode<T>[]): GrammarNode<T>;
|
|
73
112
|
|
|
74
|
-
export declare function
|
|
113
|
+
export declare function sequence<T extends string>(...nodes: GrammarNode<T>[]): GrammarNode<T>;
|
|
75
114
|
|
|
76
|
-
export declare function
|
|
115
|
+
export declare function success<T extends string>(param: ParserSuccess<T>): ParserSuccess<T>;
|
|
77
116
|
|
|
78
|
-
|
|
117
|
+
declare type SyntaxColorsProvider = (node: CSTNode<string>) => CSSProperties | undefined;
|
|
79
118
|
|
|
80
|
-
export declare function term
|
|
119
|
+
export declare function term(str: string): GrammarNode<never>;
|
|
81
120
|
|
|
82
|
-
export declare function
|
|
121
|
+
export declare function visit<T extends string, V = string>(parserResult: ParserSuccess<T>, type: T[], extractor?: (node: ParserSuccess<T>) => V): V[];
|
|
83
122
|
|
|
84
|
-
export declare const ws:
|
|
123
|
+
export declare const ws: GrammarNode<never>;
|
|
85
124
|
|
|
86
125
|
export { }
|