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.
Files changed (87) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +183 -37
  3. package/dist/YINI.d.ts +22 -7
  4. package/dist/YINI.js +101 -0
  5. package/dist/core/astBuilder.d.ts +94 -15
  6. package/dist/core/astBuilder.js +394 -362
  7. package/dist/core/errorDataHandler.d.ts +6 -1
  8. package/dist/core/errorDataHandler.js +30 -43
  9. package/dist/core/internalTypes.d.ts +10 -1
  10. package/dist/core/objectBuilder.js +21 -6
  11. package/dist/core/options/defaultParserOptions.d.ts +3 -2
  12. package/dist/core/options/defaultParserOptions.js +2 -1
  13. package/dist/core/options/optionsFunctions.js +5 -1
  14. package/dist/core/pipeline/pipeline.js +31 -10
  15. package/dist/core/runtime.js +28 -19
  16. package/dist/grammar/generated/YiniLexer.d.ts +28 -35
  17. package/dist/grammar/generated/YiniLexer.js +323 -310
  18. package/dist/grammar/generated/YiniParser.d.ts +158 -80
  19. package/dist/grammar/generated/YiniParser.js +1141 -620
  20. package/dist/grammar/generated/YiniParserVisitor.d.ts +77 -14
  21. package/dist/grammar/generated/YiniParserVisitor.js +1 -1
  22. package/dist/index.d.ts +2 -1
  23. package/dist/index.js +4 -3
  24. package/dist/parsers/extractHeaderParts.d.ts +12 -19
  25. package/dist/parsers/extractHeaderParts.js +57 -46
  26. package/dist/parsers/parseNumber.d.ts +24 -6
  27. package/dist/parsers/parseNumber.js +114 -49
  28. package/dist/parsers/parseSectionHeader.d.ts +11 -3
  29. package/dist/parsers/parseSectionHeader.js +55 -43
  30. package/dist/parsers/parseString.js +39 -20
  31. package/dist/parsers/validateShebangPlacement.d.ts +3 -0
  32. package/dist/parsers/validateShebangPlacement.js +52 -0
  33. package/dist/types/index.d.ts +19 -2
  34. package/dist/utils/print.d.ts +1 -0
  35. package/dist/utils/print.js +5 -1
  36. package/dist/utils/string.d.ts +1 -0
  37. package/dist/utils/string.js +17 -1
  38. package/dist/utils/system.d.ts +1 -0
  39. package/dist/utils/system.js +6 -1
  40. package/dist/utils/yiniHelpers.d.ts +44 -2
  41. package/dist/utils/yiniHelpers.js +134 -46
  42. package/examples/compare-formats.md +1 -1
  43. package/examples/nested.yini +1 -1
  44. package/package.json +11 -3
  45. package/dist/YINI.js.map +0 -1
  46. package/dist/config/env.js.map +0 -1
  47. package/dist/core/astBuilder.js.map +0 -1
  48. package/dist/core/errorDataHandler.js.map +0 -1
  49. package/dist/core/internalTypes.js.map +0 -1
  50. package/dist/core/objectBuilder.js.map +0 -1
  51. package/dist/core/options/defaultParserOptions.js.map +0 -1
  52. package/dist/core/options/failLevel.js.map +0 -1
  53. package/dist/core/options/optionsFunctions.js.map +0 -1
  54. package/dist/core/parsingRules/modeFromRulesMatcher.js.map +0 -1
  55. package/dist/core/parsingRules/rulesConstAndGuards.js.map +0 -1
  56. package/dist/core/pipeline/errorListeners.js.map +0 -1
  57. package/dist/core/pipeline/pipeline.js.map +0 -1
  58. package/dist/core/resultMetadataBuilder.js.map +0 -1
  59. package/dist/core/runtime.js.map +0 -1
  60. package/dist/dev/main.d.ts +0 -1
  61. package/dist/dev/main.js +0 -139
  62. package/dist/dev/main.js.map +0 -1
  63. package/dist/dev/quick-test-samples/defect-inputs.d.ts +0 -37
  64. package/dist/dev/quick-test-samples/defect-inputs.js +0 -106
  65. package/dist/dev/quick-test-samples/defect-inputs.js.map +0 -1
  66. package/dist/dev/quick-test-samples/valid-inputs.d.ts +0 -21
  67. package/dist/dev/quick-test-samples/valid-inputs.js +0 -422
  68. package/dist/dev/quick-test-samples/valid-inputs.js.map +0 -1
  69. package/dist/grammar/generated/YiniLexer.js.map +0 -1
  70. package/dist/grammar/generated/YiniParser.js.map +0 -1
  71. package/dist/grammar/generated/YiniParserVisitor.js.map +0 -1
  72. package/dist/index.js.map +0 -1
  73. package/dist/parsers/extractHeaderParts.js.map +0 -1
  74. package/dist/parsers/extractSignificantYiniLine.js.map +0 -1
  75. package/dist/parsers/parseBoolean.js.map +0 -1
  76. package/dist/parsers/parseNull.js.map +0 -1
  77. package/dist/parsers/parseNumber.js.map +0 -1
  78. package/dist/parsers/parseSectionHeader.js.map +0 -1
  79. package/dist/parsers/parseString.js.map +0 -1
  80. package/dist/types/index.js.map +0 -1
  81. package/dist/utils/number.js.map +0 -1
  82. package/dist/utils/object.js.map +0 -1
  83. package/dist/utils/pathAndFileName.js.map +0 -1
  84. package/dist/utils/print.js.map +0 -1
  85. package/dist/utils/string.js.map +0 -1
  86. package/dist/utils/system.js.map +0 -1
  87. 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, StmtContext, String_concatContext, String_literalContext, Terminal_stmtContext, ValueContext, YiniContext } from '../grammar/generated/YiniParser.js';
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<Result> extends YiniParserVisitor<Result> {
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 | assignment | colon_list_decl | marker_stmt | bad_member
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.string_literal`.
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 WS? COLON NL* value
166
- * @return the visitor result
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
- * @note Colon list not supported any more since YINI Spec Package v1.0.0.rc4
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
- * Visit a parse tree produced by `YiniParser.string_concat`.
174
- * @param ctx the parse tree
175
- * @return the visitor result
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
- visitString_concat: (ctx: String_concatContext) => any;
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