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 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>(type?: T, ...seq: Parse<T>[]): Parse<T>;
5
+ export declare function alternative<T extends string>(...seq: GrammarNode<T>[]): GrammarNode<T>;
6
6
 
7
- export declare function appendOffset<T>(error: ParserError<T>, offset: number): ParserError<T>;
7
+ export declare function asException<T extends string>(error: ParserError<T>): ParsingError;
8
8
 
9
- export declare function appendOffsets<T>(errors: ParserError<T>[], offsets: number): ParserError<T>[];
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, styles, ...textareaProps }: {
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?: (ast: ParserResult<T>) => void;
23
- grammar: Parse<T>;
31
+ onParsed?: (dsl: DSL<T>) => void;
32
+ grammar: GrammarNode<T>;
24
33
  wrap?: boolean;
25
34
  className?: string;
26
- styles?: Partial<Record<T | 'error', CSSProperties>>;
27
- suggestions?: (type: T | 'error') => string[] | undefined;
35
+ suggestions?: (node: CSTNode<T>) => string[] | undefined;
36
+ syntaxColors?: SyntaxColorsProvider;
28
37
  } & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'wrap' | 'onChange'>): JSX.Element;
29
38
 
30
- export declare function isParserError<T extends string>(result: ParserResult<T>): boolean;
39
+ export declare interface DSLError {
40
+ message: string;
41
+ start: number;
42
+ end: number;
43
+ }
31
44
 
32
- export declare function isParserSuccess<T extends string>(result: ParserResult<T>): boolean;
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 type NodeTypes<T> = _NodeTypes<T> | 'error';
51
+ export declare const eof: GrammarNode;
35
52
 
36
- declare type _NodeTypes<T> = T extends Parse<infer U> ? U : never;
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 function optional<T extends string>(subparser: Parse<T>): Parse<T>;
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 const optionalWhitespace: Parse<"optionalWhitespace">;
68
+ export declare function isParserError<T extends string>(result: ParserResult<T>): result is ParserError<T>;
41
69
 
42
- export declare type Parse<T extends string> = (text: string) => ParserResult<T>;
70
+ export declare function isParserSuccess<T extends string>(result: ParserResult<T>): result is ParserSuccess<T>;
43
71
 
44
- export declare class Parser<T extends string> {
45
- private readonly parser;
46
- constructor(parser: Parse<T>);
47
- parse(input: string): ASTNode<T>;
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
- offset: number;
52
- expected: string | RegExp;
85
+ export declare interface ParserError<T extends string = never> {
86
+ grammar: GrammarNode<T>;
53
87
  got: string;
54
- type: T;
88
+ expected: string[];
89
+ offset: number;
55
90
  }
56
91
 
57
- export declare interface ParserResult<T extends string> {
58
- type: T;
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
- children?: ParserResult<T>[];
61
- errors: ParserError<T>[];
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: string): Parse<'pattern'>;
105
+ export declare function pattern(regex: RegExp): GrammarNode<never>;
106
+
107
+ export declare const rational: GrammarNode<never>;
69
108
 
70
- export declare function pattern<T extends string>(regex: string, type: T): Parse<T>;
109
+ export declare function repeat<T extends string>(child: GrammarNode<T>, min?: number, max?: number): GrammarNode<T>;
71
110
 
72
- export declare const rational: Parse<"rational">;
111
+ export declare function seq<T extends string>(...nodes: GrammarNode<T>[]): GrammarNode<T>;
73
112
 
74
- export declare function repeat<T extends string>(type: T | undefined, parser: Parse<T>, min?: number, max?: number): Parse<T>;
113
+ export declare function sequence<T extends string>(...nodes: GrammarNode<T>[]): GrammarNode<T>;
75
114
 
76
- export declare function seq<T extends string>(type?: T, ...p: Parse<T>[]): Parse<T | 'optionalWhitespace'>;
115
+ export declare function success<T extends string>(param: ParserSuccess<T>): ParserSuccess<T>;
77
116
 
78
- export declare function sequence<T extends string>(type?: T, ...seq: Parse<T>[]): Parse<T>;
117
+ declare type SyntaxColorsProvider = (node: CSTNode<string>) => CSSProperties | undefined;
79
118
 
80
- export declare function term<T extends string>(str: T): Parse<T>;
119
+ export declare function term(str: string): GrammarNode<never>;
81
120
 
82
- export declare function term<T extends string>(str: string, type: T): Parse<T>;
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: Parse<"space" | "ws">;
123
+ export declare const ws: GrammarNode<never>;
85
124
 
86
125
  export { }