react-dsl-editor 0.3.0 → 0.3.4

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
@@ -1,3 +1,4 @@
1
+ import { CSSProperties } from 'react';
1
2
  import { JSX } from 'react/jsx-runtime';
2
3
  import { TextareaHTMLAttributes } from 'react';
3
4
 
@@ -11,36 +12,52 @@ export declare interface CSTNode<T extends string> {
11
12
  end: number;
12
13
  grammar: GrammarNode<T>;
13
14
  children?: CSTNode<T>[];
15
+ recoverableError: boolean;
14
16
  }
15
17
 
16
18
  export declare type CSTOf<T> = CSTNode<_NodeTypes<T>>;
17
19
 
20
+ export declare function defaultSyntaxColors(theme: keyof typeof themes): (node: CSTNode<string>) => CSSProperties | undefined;
21
+
18
22
  export declare interface DSL<T extends string> {
19
23
  cst: CSTNode<T>;
20
24
  terminals: CSTNode<T>[];
21
25
  result: ParserSuccess<T>;
26
+ strictResult: ParserSuccess<T> | undefined;
27
+ errors: DSLError[];
22
28
  }
23
29
 
24
- export declare function DslEditor<T extends string>({ code, onChange, onParsed, grammar, wrap, suggestions: clientSuggestions, className, ...textareaProps }: {
30
+ export declare function DslEditor<T extends string>({ code, onChange, onParsed, grammar, wrap, suggestions: clientSuggestions, className, syntaxColors, ...textareaProps }: {
25
31
  code: string;
26
32
  onChange: (text: string) => void;
27
- onParsed?: (ast: ParserSuccess<T>) => void;
33
+ onParsed?: (dsl: DSL<T>) => void;
28
34
  grammar: GrammarNode<T>;
29
35
  wrap?: boolean;
30
36
  className?: string;
31
37
  suggestions?: (node: CSTNode<T>) => string[] | undefined;
38
+ syntaxColors?: SyntaxColorsProvider;
32
39
  } & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'wrap' | 'onChange'>): JSX.Element;
33
40
 
41
+ export declare interface DSLError {
42
+ message: string;
43
+ start: number;
44
+ end: number;
45
+ }
46
+
34
47
  export declare class DSLParser<T extends string> {
35
48
  private readonly grammar;
36
49
  constructor(grammar: GrammarNode<T>);
37
- private _parse;
38
50
  parse(input: string): DSL<T>;
39
51
  }
40
52
 
41
53
  export declare const eof: GrammarNode;
42
54
 
43
- export declare function error<T extends string>(param: ParserError<T>): ParserError<T>;
55
+ export declare function error<T extends string>(param: Omit<ParserError<T>, 'offset'>): {
56
+ offset: number;
57
+ grammar: GrammarNode<T>;
58
+ got: string;
59
+ expected: string[];
60
+ };
44
61
 
45
62
  export declare interface GrammarNode<T extends string = never> {
46
63
  type: T;
@@ -71,6 +88,7 @@ export declare interface ParserError<T extends string = never> {
71
88
  grammar: GrammarNode<T>;
72
89
  got: string;
73
90
  expected: string[];
91
+ offset: number;
74
92
  }
75
93
 
76
94
  export declare type ParserResult<T extends string = never> = ParserSuccess<T> | ParserError<T>;
@@ -79,6 +97,7 @@ export declare interface ParserSuccess<T extends string = never> {
79
97
  text: string;
80
98
  grammar: GrammarNode<T>;
81
99
  children: ParserSuccess<T>[];
100
+ recoverableError?: boolean;
82
101
  }
83
102
 
84
103
  export declare class ParsingError extends Error {
@@ -97,9 +116,16 @@ export declare function sequence<T extends string>(...nodes: GrammarNode<T>[]):
97
116
 
98
117
  export declare function success<T extends string>(param: ParserSuccess<T>): ParserSuccess<T>;
99
118
 
119
+ export declare type SyntaxColorsProvider = (node: CSTNode<string>) => CSSProperties | undefined;
120
+
100
121
  export declare function term(str: string): GrammarNode<never>;
101
122
 
102
- export declare function visit<T extends string, V = string>(parserResult: ParserSuccess<T>, type: T, extractor?: (node: ParserSuccess<T>) => V): V[];
123
+ declare const themes: {
124
+ readonly light: string[];
125
+ readonly dark: string[];
126
+ };
127
+
128
+ export declare function visit<T extends string, V = string>(parserResult: ParserSuccess<T>, type: T[], extractor?: (node: ParserSuccess<T>) => V): V[];
103
129
 
104
130
  export declare const ws: GrammarNode<never>;
105
131