grammar-well 1.1.2 → 1.1.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.
Files changed (63) hide show
  1. package/build/compiler/compiler.d.ts +49 -49
  2. package/build/compiler/compiler.js +227 -227
  3. package/build/compiler/generator.d.ts +23 -23
  4. package/build/compiler/generator.js +213 -212
  5. package/build/compiler/generator.js.map +1 -1
  6. package/build/compiler/import-resolver.d.ts +15 -15
  7. package/build/compiler/import-resolver.js +36 -36
  8. package/build/compiler/outputs/javascript.d.ts +3 -3
  9. package/build/compiler/outputs/javascript.js +14 -14
  10. package/build/compiler/outputs/json.d.ts +2 -2
  11. package/build/compiler/outputs/json.js +7 -7
  12. package/build/compiler/outputs/typescript.d.ts +2 -2
  13. package/build/compiler/outputs/typescript.js +9 -8
  14. package/build/compiler/outputs/typescript.js.map +1 -1
  15. package/build/grammars/gwell.d.ts +1023 -997
  16. package/build/grammars/gwell.js +540 -536
  17. package/build/grammars/gwell.js.map +1 -1
  18. package/build/grammars/json.d.ts +151 -151
  19. package/build/grammars/json.js +111 -111
  20. package/build/grammars/number.d.ts +239 -239
  21. package/build/grammars/number.js +114 -114
  22. package/build/grammars/number.json +1 -1
  23. package/build/grammars/string.d.ts +116 -116
  24. package/build/grammars/string.js +49 -49
  25. package/build/grammars/string.json +1 -1
  26. package/build/grammars/whitespace.d.ts +51 -51
  27. package/build/grammars/whitespace.js +29 -29
  28. package/build/grammars/whitespace.json +1 -1
  29. package/build/index.d.ts +4 -4
  30. package/build/index.js +20 -20
  31. package/build/lexers/character-lexer.d.ts +27 -27
  32. package/build/lexers/character-lexer.js +70 -70
  33. package/build/lexers/stateful-lexer.d.ts +48 -48
  34. package/build/lexers/stateful-lexer.js +308 -308
  35. package/build/lexers/token-buffer.d.ts +32 -32
  36. package/build/lexers/token-buffer.js +91 -91
  37. package/build/parser/algorithms/cyk.d.ts +16 -16
  38. package/build/parser/algorithms/cyk.js +57 -57
  39. package/build/parser/algorithms/earley.d.ts +48 -48
  40. package/build/parser/algorithms/earley.js +157 -157
  41. package/build/parser/algorithms/lr.d.ts +10 -10
  42. package/build/parser/algorithms/lr.js +33 -33
  43. package/build/parser/parser.d.ts +26 -26
  44. package/build/parser/parser.js +73 -73
  45. package/build/typings.d.ts +199 -198
  46. package/build/typings.js +2 -2
  47. package/build/utility/general.d.ts +55 -55
  48. package/build/utility/general.js +175 -165
  49. package/build/utility/general.js.map +1 -1
  50. package/build/utility/lint.d.ts +2 -2
  51. package/build/utility/lint.js +27 -27
  52. package/build/utility/lr.d.ts +52 -52
  53. package/build/utility/lr.js +129 -129
  54. package/build/utility/text-format.d.ts +11 -11
  55. package/build/utility/text-format.js +83 -83
  56. package/package.json +1 -1
  57. package/src/compiler/generator.ts +1 -0
  58. package/src/compiler/outputs/typescript.ts +2 -1
  59. package/src/grammars/gwell.gwell +15 -13
  60. package/src/grammars/gwell.js +17 -13
  61. package/src/grammars/gwell.json +1 -1
  62. package/src/typings.ts +1 -0
  63. package/src/utility/general.ts +31 -19
@@ -1,198 +1,199 @@
1
- import { TokenBuffer } from "./lexers/token-buffer";
2
- import { ParserUtility } from "./parser/parser";
3
- export interface Dictionary<T> {
4
- [key: string]: T;
5
- }
6
- export interface CompileOptions {
7
- version?: string;
8
- noscript?: boolean;
9
- basedir?: string;
10
- resolver?: ImportResolverConstructor;
11
- resolverInstance?: ImportResolver;
12
- exportName?: string;
13
- template?: TemplateFormat;
14
- }
15
- export type TemplateFormat = '_default' | 'object' | 'json' | 'js' | 'javascript' | 'module' | 'esmodule' | 'esm' | 'ts' | 'typescript';
16
- export interface GrammarBuilderContext {
17
- alreadyCompiled: Set<string>;
18
- resolver: ImportResolver;
19
- uuids: Dictionary<number>;
20
- }
21
- export interface ImportResolver {
22
- path(path: string): string;
23
- body(path: string): Promise<string>;
24
- }
25
- export interface ImportResolverConstructor {
26
- new (basePath: string): ImportResolver;
27
- }
28
- export type PostProcessor = (payload: PostProcessorPayload) => any;
29
- interface PostProcessorPayload {
30
- data: any[];
31
- rule: GrammarRule;
32
- meta: any;
33
- }
34
- export type JavascriptDirective = {
35
- body: GrammarTypeJS;
36
- } | {
37
- head: GrammarTypeJS;
38
- };
39
- export interface ImportDirective {
40
- import: string;
41
- path?: boolean;
42
- }
43
- export interface ConfigDirective {
44
- config: Dictionary<any>;
45
- }
46
- export interface GrammarDirective {
47
- grammar: {
48
- config?: Dictionary<any>;
49
- rules: GrammarBuilderRule[];
50
- };
51
- }
52
- export interface LexerDirective {
53
- lexer: {
54
- start?: string;
55
- states: LexerStateDefinition[];
56
- };
57
- }
58
- export interface GrammarBuilderRule {
59
- name: string;
60
- expressions: GrammarBuilderExpression[];
61
- postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
62
- }
63
- export interface GrammarBuilderExpression {
64
- symbols: GrammarBuilderSymbol[];
65
- postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
66
- }
67
- export type GrammarBuilderSymbol = GrammarTypeRule | GrammarTypeRegex | GrammarTypeToken | GrammarTypeLiteral | GrammarBuilderSymbolRepeat | GrammarBuilderSymbolSubexpression;
68
- export interface GrammarBuilderSymbolSubexpression {
69
- subexpression: GrammarBuilderExpression[];
70
- }
71
- export interface GrammarBuilderSymbolRepeat {
72
- expression: GrammarBuilderSymbol;
73
- repeat: "+" | "*" | "?";
74
- }
75
- export interface GrammarTypeRule {
76
- rule: string;
77
- }
78
- export interface GrammarTypeRegex {
79
- regex: string;
80
- flags?: string;
81
- }
82
- export interface GrammarTypeToken {
83
- token: string;
84
- }
85
- export interface GrammarTypeLiteral {
86
- literal: string;
87
- insensitive?: boolean;
88
- }
89
- export type GrammarTypeBuiltIn = {
90
- builtin: string;
91
- };
92
- export type GrammarTypeTemplate = {
93
- template: string;
94
- };
95
- export type GrammarTypeJS = {
96
- js: string;
97
- };
98
- export type ParserAlgorithm = ((language: LanguageDefinition & {
99
- tokens: TokenBuffer;
100
- utility: ParserUtility;
101
- }, options?: any) => {
102
- results: any[];
103
- info?: any;
104
- });
105
- export type LanguageDirective = (JavascriptDirective | ImportDirective | ConfigDirective | GrammarDirective | LexerDirective);
106
- type GrammarRuleSymbolFunction = (data: LexerToken) => boolean;
107
- export interface GrammarRule {
108
- name: string;
109
- symbols: GrammarRuleSymbol[];
110
- postprocess?: PostProcessor;
111
- }
112
- export type GrammarRuleSymbol = string | RegExp | GrammarTypeLiteral | GrammarTypeToken | GrammarRuleSymbolFunction;
113
- export interface GeneratorGrammarRule {
114
- name: string;
115
- symbols: GeneratorGrammarSymbol[];
116
- postprocess?: GrammarTypeTemplate | GrammarTypeBuiltIn | GrammarTypeJS;
117
- }
118
- export type GeneratorGrammarSymbol = {
119
- alias?: string;
120
- } & (GrammarTypeRule | GrammarTypeRegex | GrammarTypeLiteral | GrammarTypeToken | GrammarTypeJS);
121
- export interface LanguageDefinition {
122
- lexer?: Lexer | LexerConfig;
123
- grammar: {
124
- start: string;
125
- rules: Dictionary<GrammarRule[]>;
126
- };
127
- }
128
- export interface TQRestorePoint {
129
- historyIndex: number;
130
- offset: number;
131
- }
132
- export interface Lexer {
133
- next(): LexerToken | undefined;
134
- feed(chunk?: string, state?: ReturnType<Lexer['state']>): void;
135
- state(): any;
136
- flush?(): void;
137
- }
138
- export interface LexerToken {
139
- type?: string | undefined;
140
- tag?: Set<string>;
141
- value: string;
142
- offset: number;
143
- line: number;
144
- column: number;
145
- }
146
- export interface LexerStatus {
147
- index: number;
148
- line: number;
149
- column: number;
150
- state: string;
151
- }
152
- export interface LexerStateDefinition {
153
- name: string;
154
- unmatched?: string;
155
- default?: string;
156
- rules: (LexerStateImportRule | LexerStateMatchRule)[];
157
- }
158
- export interface LexerStateImportRule {
159
- import: string[];
160
- }
161
- export interface LexerStateMatchRule {
162
- when: string | RegExp;
163
- type?: string;
164
- tag?: string[];
165
- pop?: number | 'all';
166
- inset?: number;
167
- goto?: string;
168
- set?: string;
169
- }
170
- export interface ResolvedStateDefinition {
171
- name: string;
172
- unmatched?: string;
173
- rules: LexerStateMatchRule[];
174
- }
175
- export interface CompiledStateDefinition {
176
- regexp: RegExp;
177
- unmatched?: LexerStateMatchRule;
178
- rules: LexerStateMatchRule[];
179
- }
180
- export interface LexerConfig {
181
- start?: string;
182
- states: Dictionary<LexerStateDefinition>;
183
- }
184
- export interface GeneratorState {
185
- version: string;
186
- config: Dictionary<string>;
187
- head: string[];
188
- body: string[];
189
- lexer?: LexerConfig;
190
- grammar: {
191
- start: string;
192
- rules: Dictionary<GeneratorGrammarRule[]>;
193
- uuids: {
194
- [key: string]: number;
195
- };
196
- };
197
- }
198
- export {};
1
+ import { TokenBuffer } from "./lexers/token-buffer";
2
+ import { ParserUtility } from "./parser/parser";
3
+ export interface Dictionary<T> {
4
+ [key: string]: T;
5
+ }
6
+ export interface CompileOptions {
7
+ version?: string;
8
+ noscript?: boolean;
9
+ basedir?: string;
10
+ resolver?: ImportResolverConstructor;
11
+ resolverInstance?: ImportResolver;
12
+ exportName?: string;
13
+ template?: TemplateFormat;
14
+ }
15
+ export type TemplateFormat = '_default' | 'object' | 'json' | 'js' | 'javascript' | 'module' | 'esmodule' | 'esm' | 'ts' | 'typescript';
16
+ export interface GrammarBuilderContext {
17
+ alreadyCompiled: Set<string>;
18
+ resolver: ImportResolver;
19
+ uuids: Dictionary<number>;
20
+ }
21
+ export interface ImportResolver {
22
+ path(path: string): string;
23
+ body(path: string): Promise<string>;
24
+ }
25
+ export interface ImportResolverConstructor {
26
+ new (basePath: string): ImportResolver;
27
+ }
28
+ export type PostProcessor = (payload: PostProcessorPayload) => any;
29
+ interface PostProcessorPayload {
30
+ data: any[];
31
+ rule: GrammarRule;
32
+ meta: any;
33
+ }
34
+ export type JavascriptDirective = {
35
+ body: GrammarTypeJS;
36
+ } | {
37
+ head: GrammarTypeJS;
38
+ };
39
+ export interface ImportDirective {
40
+ import: string;
41
+ path?: boolean;
42
+ }
43
+ export interface ConfigDirective {
44
+ config: Dictionary<any>;
45
+ }
46
+ export interface GrammarDirective {
47
+ grammar: {
48
+ config?: Dictionary<any>;
49
+ rules: GrammarBuilderRule[];
50
+ };
51
+ }
52
+ export interface LexerDirective {
53
+ lexer: {
54
+ start?: string;
55
+ states: LexerStateDefinition[];
56
+ };
57
+ }
58
+ export interface GrammarBuilderRule {
59
+ name: string;
60
+ expressions: GrammarBuilderExpression[];
61
+ postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
62
+ }
63
+ export interface GrammarBuilderExpression {
64
+ symbols: GrammarBuilderSymbol[];
65
+ postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
66
+ }
67
+ export type GrammarBuilderSymbol = GrammarTypeRule | GrammarTypeRegex | GrammarTypeToken | GrammarTypeLiteral | GrammarBuilderSymbolRepeat | GrammarBuilderSymbolSubexpression;
68
+ export interface GrammarBuilderSymbolSubexpression {
69
+ subexpression: GrammarBuilderExpression[];
70
+ }
71
+ export interface GrammarBuilderSymbolRepeat {
72
+ expression: GrammarBuilderSymbol;
73
+ repeat: "+" | "*" | "?";
74
+ }
75
+ export interface GrammarTypeRule {
76
+ rule: string;
77
+ }
78
+ export interface GrammarTypeRegex {
79
+ regex: string;
80
+ flags?: string;
81
+ }
82
+ export interface GrammarTypeToken {
83
+ token: string;
84
+ }
85
+ export interface GrammarTypeLiteral {
86
+ literal: string;
87
+ insensitive?: boolean;
88
+ }
89
+ export type GrammarTypeBuiltIn = {
90
+ builtin: string;
91
+ };
92
+ export type GrammarTypeTemplate = {
93
+ template: string;
94
+ };
95
+ export type GrammarTypeJS = {
96
+ js: string;
97
+ };
98
+ export type ParserAlgorithm = ((language: LanguageDefinition & {
99
+ tokens: TokenBuffer;
100
+ utility: ParserUtility;
101
+ }, options?: any) => {
102
+ results: any[];
103
+ info?: any;
104
+ });
105
+ export type LanguageDirective = (JavascriptDirective | ImportDirective | ConfigDirective | GrammarDirective | LexerDirective);
106
+ type GrammarRuleSymbolFunction = (data: LexerToken) => boolean;
107
+ export interface GrammarRule {
108
+ name: string;
109
+ symbols: GrammarRuleSymbol[];
110
+ postprocess?: PostProcessor;
111
+ }
112
+ export type GrammarRuleSymbol = string | RegExp | GrammarTypeLiteral | GrammarTypeToken | GrammarRuleSymbolFunction;
113
+ export interface GeneratorGrammarRule {
114
+ name: string;
115
+ symbols: GeneratorGrammarSymbol[];
116
+ postprocess?: GrammarTypeTemplate | GrammarTypeBuiltIn | GrammarTypeJS;
117
+ }
118
+ export type GeneratorGrammarSymbol = {
119
+ alias?: string;
120
+ } & (GrammarTypeRule | GrammarTypeRegex | GrammarTypeLiteral | GrammarTypeToken | GrammarTypeJS);
121
+ export interface LanguageDefinition {
122
+ lexer?: Lexer | LexerConfig;
123
+ grammar: {
124
+ start: string;
125
+ rules: Dictionary<GrammarRule[]>;
126
+ };
127
+ }
128
+ export interface TQRestorePoint {
129
+ historyIndex: number;
130
+ offset: number;
131
+ }
132
+ export interface Lexer {
133
+ next(): LexerToken | undefined;
134
+ feed(chunk?: string, state?: ReturnType<Lexer['state']>): void;
135
+ state(): any;
136
+ flush?(): void;
137
+ }
138
+ export interface LexerToken {
139
+ type?: string | undefined;
140
+ tag?: Set<string>;
141
+ value: string;
142
+ offset: number;
143
+ line: number;
144
+ column: number;
145
+ }
146
+ export interface LexerStatus {
147
+ index: number;
148
+ line: number;
149
+ column: number;
150
+ state: string;
151
+ }
152
+ export interface LexerStateDefinition {
153
+ name: string;
154
+ unmatched?: string;
155
+ default?: string;
156
+ rules: (LexerStateImportRule | LexerStateMatchRule)[];
157
+ }
158
+ export interface LexerStateImportRule {
159
+ import: string[];
160
+ }
161
+ export interface LexerStateMatchRule {
162
+ when: string | RegExp;
163
+ type?: string;
164
+ tag?: string[];
165
+ pop?: number | 'all';
166
+ highlight?: string;
167
+ inset?: number;
168
+ goto?: string;
169
+ set?: string;
170
+ }
171
+ export interface ResolvedStateDefinition {
172
+ name: string;
173
+ unmatched?: string;
174
+ rules: LexerStateMatchRule[];
175
+ }
176
+ export interface CompiledStateDefinition {
177
+ regexp: RegExp;
178
+ unmatched?: LexerStateMatchRule;
179
+ rules: LexerStateMatchRule[];
180
+ }
181
+ export interface LexerConfig {
182
+ start?: string;
183
+ states: Dictionary<LexerStateDefinition>;
184
+ }
185
+ export interface GeneratorState {
186
+ version: string;
187
+ config: Dictionary<string>;
188
+ head: string[];
189
+ body: string[];
190
+ lexer?: LexerConfig;
191
+ grammar: {
192
+ start: string;
193
+ rules: Dictionary<GeneratorGrammarRule[]>;
194
+ uuids: {
195
+ [key: string]: number;
196
+ };
197
+ };
198
+ }
199
+ export {};
package/build/typings.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=typings.js.map
@@ -1,55 +1,55 @@
1
- import { Dictionary, GrammarRuleSymbol } from "../typings";
2
- export declare class Collection<T> {
3
- categorized: Dictionary<Dictionary<number>>;
4
- private uncategorized;
5
- items: T[];
6
- constructor(ref?: T[]);
7
- encode(ref: T): number;
8
- decode(id: number | string): T;
9
- has(ref: T): boolean;
10
- redirect(source: T, target: T): void;
11
- resolve(_: T): {
12
- category: keyof Collection<T>['categorized'];
13
- key: string;
14
- } | void;
15
- private addCategorized;
16
- private addUncategorized;
17
- }
18
- export declare class SymbolCollection extends Collection<GrammarRuleSymbol> {
19
- categorized: {
20
- nonTerminal: {};
21
- literalI: {};
22
- literalS: {};
23
- token: {};
24
- regex: {};
25
- function: {};
26
- };
27
- resolve(symbol: GrammarRuleSymbol): {
28
- category: string;
29
- key: string;
30
- };
31
- }
32
- export declare class Matrix<T> {
33
- private initial?;
34
- private $x;
35
- private $y;
36
- get x(): number;
37
- set x(x: number);
38
- get y(): number;
39
- set y(y: number);
40
- matrix: GetCallbackOrValue<T>[][];
41
- constructor(x: number, y: number, initial?: T | ((...args: any) => T));
42
- get(x: number, y: number): T;
43
- set(x: number, y: number, value: any): any;
44
- resize(x: number, y: number): void;
45
- static Array<T>(length: any, initial?: T | ((...args: any) => T)): GetCallbackOrValue<T>[];
46
- }
47
- export declare function Flatten(obj: any[] | {
48
- [key: string]: any;
49
- }): FlatObject;
50
- export declare function Unflatten(items: FlatObject): any;
51
- type FlatObject = (boolean | number | string | (number[]) | {
52
- [key: string]: number;
53
- })[];
54
- type GetCallbackOrValue<T> = T extends (...args: any) => any ? ReturnType<T> : T;
55
- export {};
1
+ import { Dictionary, GrammarRuleSymbol } from "../typings";
2
+ export declare class Collection<T> {
3
+ categorized: Dictionary<Dictionary<number>>;
4
+ uncategorized: Map<T, number>;
5
+ items: T[];
6
+ constructor(ref?: T[]);
7
+ encode(ref: T): number;
8
+ decode(id: number | string): T;
9
+ has(ref: T): boolean;
10
+ redirect(source: T, target: T): void;
11
+ resolve(_: T): {
12
+ category: keyof Collection<T>['categorized'];
13
+ key: string;
14
+ } | void;
15
+ private addCategorized;
16
+ private addUncategorized;
17
+ }
18
+ export declare class SymbolCollection extends Collection<GrammarRuleSymbol> {
19
+ categorized: {
20
+ nonTerminal: {};
21
+ literalI: {};
22
+ literalS: {};
23
+ token: {};
24
+ regex: {};
25
+ function: {};
26
+ };
27
+ resolve(symbol: GrammarRuleSymbol): {
28
+ category: string;
29
+ key: string;
30
+ };
31
+ }
32
+ export declare class Matrix<T> {
33
+ private initial?;
34
+ private $x;
35
+ private $y;
36
+ get x(): number;
37
+ set x(x: number);
38
+ get y(): number;
39
+ set y(y: number);
40
+ matrix: GetCallbackOrValue<T>[][];
41
+ constructor(x: number, y: number, initial?: T | ((...args: any) => T));
42
+ get(x: number, y: number): T;
43
+ set(x: number, y: number, value: any): any;
44
+ resize(x: number, y: number): void;
45
+ static Array<T>(length: any, initial?: T | ((...args: any) => T)): GetCallbackOrValue<T>[];
46
+ }
47
+ export declare function Flatten(obj: any[] | {
48
+ [key: string]: any;
49
+ }): FlatObject;
50
+ export declare function Unflatten(items: FlatObject): any;
51
+ type FlatObject = (boolean | number | string | (number[]) | {
52
+ [key: string]: number;
53
+ })[];
54
+ type GetCallbackOrValue<T> = T extends (...args: any) => any ? ReturnType<T> : T;
55
+ export {};