yini-parser 1.4.3 → 1.6.0
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/CHANGELOG.md +52 -0
- package/README.md +187 -35
- package/dist/YINI.d.ts +29 -18
- package/dist/YINI.js +104 -3
- package/dist/core/astBuilder.d.ts +94 -18
- package/dist/core/astBuilder.js +439 -376
- package/dist/core/errorDataHandler.d.ts +6 -1
- package/dist/core/errorDataHandler.js +30 -43
- package/dist/core/internalTypes.d.ts +10 -1
- package/dist/core/objectBuilder.d.ts +8 -4
- package/dist/core/objectBuilder.js +47 -62
- package/dist/core/options/defaultParserOptions.d.ts +3 -2
- package/dist/core/options/defaultParserOptions.js +11 -2
- package/dist/core/options/optionsFunctions.js +6 -4
- package/dist/core/parsingRules/modeFromRulesMatcher.d.ts +1 -1
- package/dist/core/parsingRules/modeFromRulesMatcher.js +22 -13
- package/dist/core/pipeline/pipeline.js +35 -10
- package/dist/core/runtime.js +28 -19
- package/dist/grammar/generated/YiniLexer.d.ts +40 -53
- package/dist/grammar/generated/YiniLexer.js +357 -356
- package/dist/grammar/generated/YiniParser.d.ts +174 -118
- package/dist/grammar/generated/YiniParser.js +1185 -929
- package/dist/grammar/generated/YiniParserVisitor.d.ts +82 -19
- package/dist/grammar/generated/YiniParserVisitor.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -3
- package/dist/parsers/extractHeaderParts.d.ts +12 -19
- package/dist/parsers/extractHeaderParts.js +57 -46
- package/dist/parsers/parseNumber.d.ts +24 -6
- package/dist/parsers/parseNumber.js +114 -49
- package/dist/parsers/parseSectionHeader.d.ts +11 -3
- package/dist/parsers/parseSectionHeader.js +55 -43
- package/dist/parsers/parseString.js +39 -20
- package/dist/parsers/validateShebangPlacement.d.ts +3 -0
- package/dist/parsers/validateShebangPlacement.js +52 -0
- package/dist/types/index.d.ts +20 -3
- package/dist/utils/print.d.ts +1 -0
- package/dist/utils/print.js +5 -1
- package/dist/utils/string.d.ts +1 -0
- package/dist/utils/string.js +17 -1
- package/dist/utils/system.d.ts +1 -0
- package/dist/utils/system.js +6 -1
- package/dist/utils/yiniHelpers.d.ts +44 -2
- package/dist/utils/yiniHelpers.js +134 -46
- package/examples/compare-formats.md +1 -1
- package/examples/nested.yini +1 -1
- package/package.json +11 -3
- package/dist/YINI.js.map +0 -1
- package/dist/config/env.js.map +0 -1
- package/dist/core/astBuilder.js.map +0 -1
- package/dist/core/errorDataHandler.js.map +0 -1
- package/dist/core/internalTypes.js.map +0 -1
- package/dist/core/objectBuilder.js.map +0 -1
- package/dist/core/options/defaultParserOptions.js.map +0 -1
- package/dist/core/options/failLevel.js.map +0 -1
- package/dist/core/options/optionsFunctions.js.map +0 -1
- package/dist/core/parsingRules/modeFromRulesMatcher.js.map +0 -1
- package/dist/core/parsingRules/rulesConstAndGuards.js.map +0 -1
- package/dist/core/pipeline/errorListeners.js.map +0 -1
- package/dist/core/pipeline/pipeline.js.map +0 -1
- package/dist/core/resultMetadataBuilder.js.map +0 -1
- package/dist/core/runtime.js.map +0 -1
- package/dist/dev/main.d.ts +0 -1
- package/dist/dev/main.js +0 -168
- package/dist/dev/main.js.map +0 -1
- package/dist/dev/quick-test-samples/defect-inputs.d.ts +0 -37
- package/dist/dev/quick-test-samples/defect-inputs.js +0 -106
- package/dist/dev/quick-test-samples/defect-inputs.js.map +0 -1
- package/dist/dev/quick-test-samples/valid-inputs.d.ts +0 -21
- package/dist/dev/quick-test-samples/valid-inputs.js +0 -422
- package/dist/dev/quick-test-samples/valid-inputs.js.map +0 -1
- package/dist/grammar/generated/YiniLexer.js.map +0 -1
- package/dist/grammar/generated/YiniParser.js.map +0 -1
- package/dist/grammar/generated/YiniParserVisitor.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/parsers/extractHeaderParts.js.map +0 -1
- package/dist/parsers/extractSignificantYiniLine.js.map +0 -1
- package/dist/parsers/parseBoolean.js.map +0 -1
- package/dist/parsers/parseNull.js.map +0 -1
- package/dist/parsers/parseNumber.js.map +0 -1
- package/dist/parsers/parseSectionHeader.js.map +0 -1
- package/dist/parsers/parseString.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/utils/number.js.map +0 -1
- package/dist/utils/object.js.map +0 -1
- package/dist/utils/pathAndFileName.js.map +0 -1
- package/dist/utils/print.js.map +0 -1
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/system.js.map +0 -1
- package/dist/utils/yiniHelpers.js.map +0 -1
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { AnnotationContext, AssignmentContext, Bad_memberContext, Bad_meta_textContext, Boolean_literalContext,
|
|
1
|
+
import { AnnotationContext, AssignmentContext, Bad_memberContext, Bad_meta_textContext, Boolean_literalContext, Concat_expressionContext, Concat_operandContext, Concat_tailContext, DirectiveContext, Disabled_line_stmtContext, ElementsContext, EolContext, Full_line_comment_stmtContext, Invalid_section_stmtContext, List_literalContext, MemberContext, Meta_stmtContext, Null_literalContext, Number_literalContext, Object_literalContext, Object_member_separatorContext, Object_memberContext, Object_membersContext, PrologContext, Scalar_valueContext, StmtContext, String_literalContext, Terminal_stmtContext, Terminal_triviaContext, ValueContext, Yini_directiveContext, Yini_mode_declarationContext, YiniContext } from '../grammar/generated/YiniParser.js';
|
|
2
2
|
import YiniParserVisitor from '../grammar/generated/YiniParserVisitor';
|
|
3
3
|
import { ErrorDataHandler } from './errorDataHandler';
|
|
4
4
|
import { IParseCoreOptions, IYiniAST, TSourceType } from './internalTypes';
|
|
5
|
-
/** Parse SECTION_HEAD token text → {level, name}.
|
|
6
|
-
* Supports repeated markers (^^^^) and shorthand (^7) (Spec 5.2–5.3.1). :contentReference[oaicite:5]{index=5}:contentReference[oaicite:6]{index=6}
|
|
7
|
-
*/
|
|
8
5
|
/**
|
|
9
6
|
* This interface defines a complete generic visitor for a parse tree produced
|
|
10
7
|
* by `YiniParser`.
|
|
@@ -12,13 +9,14 @@ import { IParseCoreOptions, IYiniAST, TSourceType } from './internalTypes';
|
|
|
12
9
|
* @param <Result> The return type of the visit operation. Use `void` for
|
|
13
10
|
* operations with no return type.
|
|
14
11
|
*/
|
|
15
|
-
export default class ASTBuilder
|
|
12
|
+
export default class ASTBuilder extends YiniParserVisitor<any> {
|
|
16
13
|
private errorHandler;
|
|
17
14
|
private readonly options;
|
|
18
15
|
private readonly isStrict;
|
|
19
16
|
private readonly onDuplicateKey;
|
|
20
17
|
private ast;
|
|
21
18
|
private sectionStack;
|
|
19
|
+
private ignoredSectionLevel;
|
|
22
20
|
private meta_hasYiniMarker;
|
|
23
21
|
private _numOfMembers;
|
|
24
22
|
private meta_maxLevel;
|
|
@@ -28,14 +26,19 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
28
26
|
* @param metaLineCount Provide the line-count here so the meta information can be updated accordingly.
|
|
29
27
|
*/
|
|
30
28
|
constructor(errorHandler: ErrorDataHandler, options: IParseCoreOptions, sourceType: TSourceType, metaFileName: string | null);
|
|
29
|
+
private validateStrictTopLevelStructure;
|
|
31
30
|
private hasDefinedSectionTitle;
|
|
32
31
|
private setDefineSectionTitle;
|
|
33
|
-
private extractStringParts;
|
|
34
32
|
private extractStringKindAndValue;
|
|
35
33
|
/** Attach a section to the stack respecting up/down moves (Spec 5.3). :contentReference[oaicite:7]{index=7} */
|
|
36
34
|
private attachSection;
|
|
35
|
+
private isIgnoringDuplicateSection;
|
|
36
|
+
private shouldSkipSectionAtLevel;
|
|
37
37
|
/** Insert a key/value into current section (duplicate handling per options). */
|
|
38
38
|
private putMember;
|
|
39
|
+
private stringifyConcatOperand;
|
|
40
|
+
private parseStringToken;
|
|
41
|
+
private hasTrailingComma;
|
|
39
42
|
buildAST(ctx: YiniContext): IYiniAST;
|
|
40
43
|
/**
|
|
41
44
|
* Visit a parse tree produced by `YiniParser.yini`.
|
|
@@ -55,13 +58,37 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
55
58
|
* @return the visitor result
|
|
56
59
|
*/
|
|
57
60
|
visitTerminal_stmt: (ctx: Terminal_stmtContext) => any;
|
|
61
|
+
/**
|
|
62
|
+
* Visit a parse tree produced by `YiniParser.terminal_trivia`.
|
|
63
|
+
* @param ctx the parse tree
|
|
64
|
+
* @return the visitor result
|
|
65
|
+
*/
|
|
66
|
+
visitTerminal_trivia: (ctx: Terminal_triviaContext) => any;
|
|
67
|
+
/**
|
|
68
|
+
* Visit a parse tree produced by `YiniParser.stmt`.
|
|
69
|
+
* @param ctx the parse tree
|
|
70
|
+
* @return the visitor result
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Visit a parse tree produced by `YiniParser.full_line_comment_stmt`.
|
|
74
|
+
* @param ctx the parse tree
|
|
75
|
+
* @return the visitor result
|
|
76
|
+
*/
|
|
77
|
+
visitFull_line_comment_stmt: (_ctx: Full_line_comment_stmtContext) => any;
|
|
78
|
+
/**
|
|
79
|
+
* Visit a parse tree produced by `YiniParser.disabled_line_stmt`.
|
|
80
|
+
* @param ctx the parse tree
|
|
81
|
+
* @return the visitor result
|
|
82
|
+
*/
|
|
83
|
+
visitDisabled_line_stmt: (_ctx: Disabled_line_stmtContext) => any;
|
|
58
84
|
/**
|
|
59
85
|
* Visit a parse tree produced by `YiniParser.stmt`.
|
|
60
86
|
* @param ctx the parse tree
|
|
61
|
-
* @grammarRule eol | SECTION_HEAD |
|
|
87
|
+
* @grammarRule eol | full_line_comment_stmt | disabled_line_stmt | SECTION_HEAD | invalid_section_stmt | assignment | meta_stmt | bad_member
|
|
62
88
|
* @return the visitor result
|
|
63
89
|
*/
|
|
64
90
|
visitStmt: (ctx: StmtContext) => any;
|
|
91
|
+
visitInvalid_section_stmt: (ctx: Invalid_section_stmtContext) => any;
|
|
65
92
|
/**
|
|
66
93
|
* Visit a parse tree produced by `YiniParser.meta_stmt`.
|
|
67
94
|
* @param ctx the parse tree
|
|
@@ -107,10 +134,47 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
107
134
|
*/
|
|
108
135
|
visitValue: (ctx: ValueContext) => any;
|
|
109
136
|
/**
|
|
110
|
-
* Visit a parse tree produced by `YiniParser.
|
|
137
|
+
* Visit a parse tree produced by `YiniParser.scalar_value`.
|
|
138
|
+
* @param ctx the parse tree
|
|
139
|
+
* @return the visitor result
|
|
140
|
+
*/
|
|
141
|
+
visitScalar_value: (ctx: Scalar_valueContext) => any;
|
|
142
|
+
/**
|
|
143
|
+
* Visit a parse tree produced by `YiniParser.concat_expression`.
|
|
144
|
+
*
|
|
145
|
+
* Grammar:
|
|
146
|
+
* concat_expression : STRING concat_tail+ ;
|
|
147
|
+
*
|
|
148
|
+
* Spec:
|
|
149
|
+
* - Concatenation must begin with a string literal.
|
|
150
|
+
* - In strict mode, every operand must be a string literal.
|
|
151
|
+
* - In lenient mode, later operands may be string, number, boolean, or null.
|
|
152
|
+
* - YINI does not define numeric addition.
|
|
153
|
+
*
|
|
154
|
+
* Examples:
|
|
155
|
+
* "Port: " + 8080 // lenient valid
|
|
156
|
+
* "1" + 2 + 3 // lenient valid
|
|
157
|
+
* 8080 + " is the port" // invalid: must begin with string literal
|
|
158
|
+
* 1 + 2 + "3" // invalid: must begin with string literal
|
|
159
|
+
* 1 + 2 + 3 // invalid: YINI does not define numeric addition
|
|
160
|
+
*/
|
|
161
|
+
visitConcat_expression: (ctx: Concat_expressionContext) => any;
|
|
162
|
+
/**
|
|
163
|
+
* Visit a parse tree produced by `YiniParser.concat_tail`.
|
|
111
164
|
* @param ctx the parse tree
|
|
112
165
|
* @return the visitor result
|
|
113
166
|
*/
|
|
167
|
+
visitConcat_tail: (ctx: Concat_tailContext) => any;
|
|
168
|
+
/**
|
|
169
|
+
* Visit a parse tree produced by `YiniParser.concat_operand`.
|
|
170
|
+
*
|
|
171
|
+
* @note Must use token accessors, not literal visitors.
|
|
172
|
+
* Use STRING() instead of string_literal(), etc.
|
|
173
|
+
*
|
|
174
|
+
* @param ctx the parse tree
|
|
175
|
+
* @return the visitor result
|
|
176
|
+
*/
|
|
177
|
+
visitConcat_operand: (ctx: Concat_operandContext) => any;
|
|
114
178
|
visitString_literal: (ctx: String_literalContext) => any;
|
|
115
179
|
/**
|
|
116
180
|
* Visit a parse tree produced by `YiniParser.number_literal`.
|
|
@@ -156,28 +220,40 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
156
220
|
* @param ctx the parse tree
|
|
157
221
|
* @grammarRule object_member (COMMA NL* object_member)* COMMA?
|
|
158
222
|
* @return the visitor result
|
|
223
|
+
*
|
|
224
|
+
* @note
|
|
225
|
+
* SPEC says:
|
|
226
|
+
* - Lenient: first wins + warning
|
|
227
|
+
* - Strict: error
|
|
228
|
+
*
|
|
229
|
+
* NEVER silently overwrite.
|
|
159
230
|
*/
|
|
160
231
|
visitObject_members: (ctx: Object_membersContext) => any;
|
|
161
232
|
/**
|
|
162
233
|
* Visit a parse tree produced by `YiniParser.object_member`.
|
|
163
234
|
* @param ctx the parse tree
|
|
164
|
-
* @grammarRule KEY
|
|
165
|
-
* @return the
|
|
235
|
+
* @grammarRule KEY object_member_separator NL* value
|
|
236
|
+
* @return the object member key and value
|
|
166
237
|
*/
|
|
167
238
|
visitObject_member: (ctx: Object_memberContext) => any;
|
|
168
239
|
/**
|
|
169
|
-
* Visit a parse tree produced by `YiniParser.
|
|
240
|
+
* Visit a parse tree produced by `YiniParser.object_member_separator`.
|
|
170
241
|
* @param ctx the parse tree
|
|
171
|
-
* @grammarRule
|
|
172
|
-
* @return
|
|
242
|
+
* @grammarRule COLON | EQ
|
|
243
|
+
* @return ':' or '='
|
|
173
244
|
*/
|
|
174
|
-
|
|
245
|
+
visitObject_member_separator: (ctx: Object_member_separatorContext) => any;
|
|
175
246
|
/**
|
|
176
|
-
*
|
|
177
|
-
* @
|
|
178
|
-
* @
|
|
247
|
+
*
|
|
248
|
+
* @note
|
|
249
|
+
* @yini strict + active lenient => error
|
|
250
|
+
* @yini lenient + active strict => warning
|
|
251
|
+
* @yini strict + active strict => ok
|
|
252
|
+
* @yini lenient + active lenient => ok
|
|
253
|
+
* @yini + any mode => ok
|
|
179
254
|
*/
|
|
180
|
-
|
|
255
|
+
visitYini_directive: (ctx: Yini_directiveContext) => any;
|
|
256
|
+
visitYini_mode_declaration: (ctx: Yini_mode_declarationContext | undefined) => any;
|
|
181
257
|
/**
|
|
182
258
|
* Visit a parse tree produced by `YiniParser.bad_member`.
|
|
183
259
|
* @param ctx the parse tree
|