yini-parser 1.5.0 → 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 +33 -0
- package/README.md +183 -37
- package/dist/YINI.d.ts +22 -7
- package/dist/YINI.js +101 -0
- package/dist/core/astBuilder.d.ts +94 -15
- package/dist/core/astBuilder.js +394 -362
- 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.js +21 -6
- package/dist/core/options/defaultParserOptions.d.ts +3 -2
- package/dist/core/options/defaultParserOptions.js +2 -1
- package/dist/core/options/optionsFunctions.js +5 -1
- package/dist/core/pipeline/pipeline.js +31 -10
- package/dist/core/runtime.js +28 -19
- package/dist/grammar/generated/YiniLexer.d.ts +28 -35
- package/dist/grammar/generated/YiniLexer.js +323 -310
- package/dist/grammar/generated/YiniParser.d.ts +158 -80
- package/dist/grammar/generated/YiniParser.js +1141 -620
- package/dist/grammar/generated/YiniParserVisitor.d.ts +77 -14
- 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 +19 -2
- 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 -139
- 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, DirectiveContext, ElementsContext, EolContext, List_literalContext, MemberContext, Meta_stmtContext, Null_literalContext, Number_literalContext, Object_literalContext, Object_memberContext, Object_membersContext, PrologContext,
|
|
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;
|
|
@@ -31,12 +29,16 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
31
29
|
private validateStrictTopLevelStructure;
|
|
32
30
|
private hasDefinedSectionTitle;
|
|
33
31
|
private setDefineSectionTitle;
|
|
34
|
-
private extractStringParts;
|
|
35
32
|
private extractStringKindAndValue;
|
|
36
33
|
/** Attach a section to the stack respecting up/down moves (Spec 5.3). :contentReference[oaicite:7]{index=7} */
|
|
37
34
|
private attachSection;
|
|
35
|
+
private isIgnoringDuplicateSection;
|
|
36
|
+
private shouldSkipSectionAtLevel;
|
|
38
37
|
/** Insert a key/value into current section (duplicate handling per options). */
|
|
39
38
|
private putMember;
|
|
39
|
+
private stringifyConcatOperand;
|
|
40
|
+
private parseStringToken;
|
|
41
|
+
private hasTrailingComma;
|
|
40
42
|
buildAST(ctx: YiniContext): IYiniAST;
|
|
41
43
|
/**
|
|
42
44
|
* Visit a parse tree produced by `YiniParser.yini`.
|
|
@@ -56,13 +58,37 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
56
58
|
* @return the visitor result
|
|
57
59
|
*/
|
|
58
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;
|
|
59
84
|
/**
|
|
60
85
|
* Visit a parse tree produced by `YiniParser.stmt`.
|
|
61
86
|
* @param ctx the parse tree
|
|
62
|
-
* @grammarRule eol | SECTION_HEAD |
|
|
87
|
+
* @grammarRule eol | full_line_comment_stmt | disabled_line_stmt | SECTION_HEAD | invalid_section_stmt | assignment | meta_stmt | bad_member
|
|
63
88
|
* @return the visitor result
|
|
64
89
|
*/
|
|
65
90
|
visitStmt: (ctx: StmtContext) => any;
|
|
91
|
+
visitInvalid_section_stmt: (ctx: Invalid_section_stmtContext) => any;
|
|
66
92
|
/**
|
|
67
93
|
* Visit a parse tree produced by `YiniParser.meta_stmt`.
|
|
68
94
|
* @param ctx the parse tree
|
|
@@ -108,10 +134,47 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
108
134
|
*/
|
|
109
135
|
visitValue: (ctx: ValueContext) => any;
|
|
110
136
|
/**
|
|
111
|
-
* 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`.
|
|
112
164
|
* @param ctx the parse tree
|
|
113
165
|
* @return the visitor result
|
|
114
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;
|
|
115
178
|
visitString_literal: (ctx: String_literalContext) => any;
|
|
116
179
|
/**
|
|
117
180
|
* Visit a parse tree produced by `YiniParser.number_literal`.
|
|
@@ -157,24 +220,40 @@ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
|
|
|
157
220
|
* @param ctx the parse tree
|
|
158
221
|
* @grammarRule object_member (COMMA NL* object_member)* COMMA?
|
|
159
222
|
* @return the visitor result
|
|
223
|
+
*
|
|
224
|
+
* @note
|
|
225
|
+
* SPEC says:
|
|
226
|
+
* - Lenient: first wins + warning
|
|
227
|
+
* - Strict: error
|
|
228
|
+
*
|
|
229
|
+
* NEVER silently overwrite.
|
|
160
230
|
*/
|
|
161
231
|
visitObject_members: (ctx: Object_membersContext) => any;
|
|
162
232
|
/**
|
|
163
233
|
* Visit a parse tree produced by `YiniParser.object_member`.
|
|
164
234
|
* @param ctx the parse tree
|
|
165
|
-
* @grammarRule KEY
|
|
166
|
-
* @return the
|
|
235
|
+
* @grammarRule KEY object_member_separator NL* value
|
|
236
|
+
* @return the object member key and value
|
|
167
237
|
*/
|
|
168
238
|
visitObject_member: (ctx: Object_memberContext) => any;
|
|
169
239
|
/**
|
|
170
|
-
*
|
|
240
|
+
* Visit a parse tree produced by `YiniParser.object_member_separator`.
|
|
241
|
+
* @param ctx the parse tree
|
|
242
|
+
* @grammarRule COLON | EQ
|
|
243
|
+
* @return ':' or '='
|
|
171
244
|
*/
|
|
245
|
+
visitObject_member_separator: (ctx: Object_member_separatorContext) => any;
|
|
172
246
|
/**
|
|
173
|
-
*
|
|
174
|
-
* @
|
|
175
|
-
* @
|
|
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
|
|
176
254
|
*/
|
|
177
|
-
|
|
255
|
+
visitYini_directive: (ctx: Yini_directiveContext) => any;
|
|
256
|
+
visitYini_mode_declaration: (ctx: Yini_mode_declarationContext | undefined) => any;
|
|
178
257
|
/**
|
|
179
258
|
* Visit a parse tree produced by `YiniParser.bad_member`.
|
|
180
259
|
* @param ctx the parse tree
|