yini-parser 1.0.2-beta → 1.1.0-beta

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 (43) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +83 -98
  3. package/dist/YINI.d.ts +34 -11
  4. package/dist/YINI.js +206 -93
  5. package/dist/core/ASTBuilder.d.ts +191 -0
  6. package/dist/core/ASTBuilder.js +827 -0
  7. package/dist/core/ErrorDataHandler.d.ts +19 -19
  8. package/dist/core/ErrorDataHandler.js +258 -150
  9. package/dist/core/objectBuilder.d.ts +9 -3
  10. package/dist/core/objectBuilder.js +126 -163
  11. package/dist/core/types.d.ts +234 -44
  12. package/dist/core/types.js +7 -33
  13. package/dist/grammar/YiniLexer.d.ts +54 -48
  14. package/dist/grammar/YiniLexer.js +324 -289
  15. package/dist/grammar/YiniParser.d.ts +167 -150
  16. package/dist/grammar/YiniParser.js +1241 -1202
  17. package/dist/grammar/YiniParserVisitor.d.ts +59 -45
  18. package/dist/grammar/YiniParserVisitor.js +1 -1
  19. package/dist/index.d.ts +4 -2
  20. package/dist/index.js +286 -26
  21. package/dist/parseEntry.d.ts +3 -2
  22. package/dist/parseEntry.js +352 -81
  23. package/dist/parsers/extractHeaderParts.d.ts +3 -2
  24. package/dist/parsers/extractHeaderParts.js +1 -0
  25. package/dist/parsers/parseBoolean.d.ts +1 -1
  26. package/dist/parsers/parseBoolean.js +2 -1
  27. package/dist/parsers/parseNumber.d.ts +8 -3
  28. package/dist/parsers/parseNumber.js +21 -7
  29. package/dist/parsers/parseSectionHeader.d.ts +3 -2
  30. package/dist/parsers/parseSectionHeader.js +1 -0
  31. package/dist/utils/number.d.ts +3 -0
  32. package/dist/utils/number.js +18 -0
  33. package/dist/utils/object.d.ts +55 -0
  34. package/dist/utils/object.js +85 -0
  35. package/dist/utils/string.d.ts +21 -1
  36. package/dist/utils/string.js +39 -4
  37. package/dist/utils/system.d.ts +15 -0
  38. package/dist/utils/system.js +21 -0
  39. package/dist/yiniHelpers.d.ts +3 -0
  40. package/dist/yiniHelpers.js +43 -7
  41. package/package.json +1 -1
  42. package/dist/core/YINIVisitor.d.ts +0 -158
  43. package/dist/core/YINIVisitor.js +0 -1008
@@ -0,0 +1,191 @@
1
+ import { AnnotationContext, AssignmentContext, Bad_memberContext, Bad_meta_textContext, Boolean_literalContext, Colon_list_declContext, 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/YiniParser.js';
2
+ import YiniParserVisitor from '../grammar/YiniParserVisitor';
3
+ import { ErrorDataHandler } from './ErrorDataHandler';
4
+ import { IParseCoreOptions, IYiniAST, TSourceType } from './types';
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
+ /**
9
+ * This interface defines a complete generic visitor for a parse tree produced
10
+ * by `YiniParser`.
11
+ *
12
+ * @param <Result> The return type of the visit operation. Use `void` for
13
+ * operations with no return type.
14
+ */
15
+ export default class ASTBuilder<Result> extends YiniParserVisitor<Result> {
16
+ private errorHandler;
17
+ private readonly options;
18
+ private readonly isStrict;
19
+ private readonly onDuplicateKey;
20
+ private ast;
21
+ private sectionStack;
22
+ private meta_hasYiniMarker;
23
+ private _numOfMembers;
24
+ private meta_maxLevel;
25
+ mapSectionNamePaths: Map<string, number>;
26
+ /**
27
+ * @param metaFileName If parsing from a file, provide the file name here so the meta information can be updated accordingly.
28
+ * @param metaLineCount Provide the line-count here so the meta information can be updated accordingly.
29
+ */
30
+ constructor(errorHandler: ErrorDataHandler, options: IParseCoreOptions, sourceType: TSourceType, metaFileName: string | null);
31
+ private hasDefinedSectionTitle;
32
+ private setDefineSectionTitle;
33
+ /** Attach a section to the stack respecting up/down moves (Spec 5.3). :contentReference[oaicite:7]{index=7} */
34
+ private attachSection;
35
+ /** Insert a key/value into current section (duplicate handling per options). */
36
+ private putMember;
37
+ buildAST(ctx: YiniContext): IYiniAST;
38
+ /**
39
+ * Visit a parse tree produced by `YiniParser.yini`.
40
+ * @param ctx the parse tree
41
+ * @return the visitor result
42
+ */
43
+ visitYini: (ctx: YiniContext) => any;
44
+ /**
45
+ * Visit a parse tree produced by `YiniParser.prolog`.
46
+ * @param ctx the parse tree
47
+ * @return the visitor result
48
+ */
49
+ visitProlog: (ctx: PrologContext) => any;
50
+ /**
51
+ * Visit a parse tree produced by `YiniParser.terminal`.
52
+ * @param ctx the parse tree
53
+ * @return the visitor result
54
+ */
55
+ visitTerminal_stmt: (ctx: Terminal_stmtContext) => any;
56
+ /**
57
+ * Visit a parse tree produced by `YiniParser.stmt`.
58
+ * @param ctx the parse tree
59
+ * @grammarRule eol | SECTION_HEAD | assignment | colon_list_decl | marker_stmt | bad_member
60
+ * @return the visitor result
61
+ */
62
+ visitStmt: (ctx: StmtContext) => any;
63
+ /**
64
+ * Visit a parse tree produced by `YiniParser.meta_stmt`.
65
+ * @param ctx the parse tree
66
+ */
67
+ visitMeta_stmt: (ctx: Meta_stmtContext) => any;
68
+ /**
69
+ * Visit a parse tree produced by `YiniParser.directive`.
70
+ * @param ctx the parse tree
71
+ * @note Directive statements in YINI are special top-level commands that
72
+ * appear only at the beginning of a document, before any sections
73
+ * or members. Each directive may occur at most once per file.
74
+ */
75
+ visitDirective: (ctx: DirectiveContext) => any;
76
+ /**
77
+ * Visit a parse tree produced by `YiniParser.annotation`.
78
+ * @param ctx the parse tree
79
+ * @return the visitor result
80
+ */
81
+ visitAnnotation: (ctx: AnnotationContext) => any;
82
+ /**
83
+ * Visit a parse tree produced by `YiniParser.eol`.
84
+ * @param ctx the parse tree
85
+ * @return the visitor result
86
+ */
87
+ visitEol: (ctx: EolContext) => any;
88
+ /**
89
+ * Visit a parse tree produced by `YiniParser.assignment`.
90
+ * @param ctx the parse tree
91
+ * @return the visitor result
92
+ */
93
+ visitAssignment: (ctx: AssignmentContext) => any;
94
+ /**
95
+ * Visit a parse tree produced by `YiniParser.member`.
96
+ * @param ctx the parse tree
97
+ * @grammarRule KEY WS? EQ WS? value?
98
+ * @return the visitor result
99
+ */
100
+ visitMember: (ctx: MemberContext) => any;
101
+ /**
102
+ * Visit a parse tree produced by `YiniParser.value`.
103
+ * @param ctx the parse tree
104
+ * @return the visitor result
105
+ */
106
+ visitValue: (ctx: ValueContext) => any;
107
+ /**
108
+ * Visit a parse tree produced by `YiniParser.string_literal`.
109
+ * @param ctx the parse tree
110
+ * @return the visitor result
111
+ */
112
+ visitString_literal: (ctx: String_literalContext) => any;
113
+ /**
114
+ * Visit a parse tree produced by `YiniParser.number_literal`.
115
+ * @param ctx the parse tree
116
+ * @return the visitor result
117
+ */
118
+ visitNumber_literal: (ctx: Number_literalContext) => any;
119
+ /**
120
+ * Visit a parse tree produced by `YiniParser.boolean_literal`.
121
+ * @param ctx the parse tree
122
+ * @return the visitor result
123
+ */
124
+ visitBoolean_literal: (ctx: Boolean_literalContext) => any;
125
+ /**
126
+ * Visit a parse tree produced by `YiniParser.null_literal`.
127
+ * @param ctx the parse tree
128
+ * @return the visitor result
129
+ */
130
+ visitNull_literal: (ctx: Null_literalContext) => any;
131
+ /**
132
+ * Visit a parse tree produced by `YiniParser.list_literal`.
133
+ * @param ctx the parse tree
134
+ * @grammarRule OB NL* elements? NL* CB NL* | EMPTY_LIST NL*
135
+ * @return the visitor result
136
+ */
137
+ visitList_literal: (ctx: List_literalContext) => any;
138
+ /**
139
+ * Visit a parse tree produced by `YiniParser.elements`.
140
+ * @param ctx the parse tree
141
+ * @grammarRule value (NL* COMMA NL* value)* COMMA?
142
+ * @return the visitor result
143
+ */
144
+ visitElements: (ctx: ElementsContext) => any;
145
+ /**
146
+ * Visit a parse tree produced by `YiniParser.object_literal`.
147
+ * @param ctx the parse tree
148
+ * @grammarRule OC NL* object_members? NL* CC NL* | EMPTY_OBJECT NL*
149
+ * @return the visitor result
150
+ */
151
+ visitObject_literal: (ctx: Object_literalContext) => any;
152
+ /**
153
+ * Visit a parse tree produced by `YiniParser.object_members`.
154
+ * @param ctx the parse tree
155
+ * @grammarRule object_member (COMMA NL* object_member)* COMMA?
156
+ * @return the visitor result
157
+ */
158
+ visitObject_members: (ctx: Object_membersContext) => any;
159
+ /**
160
+ * Visit a parse tree produced by `YiniParser.object_member`.
161
+ * @param ctx the parse tree
162
+ * @grammarRule KEY WS? COLON NL* value
163
+ * @return the visitor result
164
+ */
165
+ visitObject_member: (ctx: Object_memberContext) => any;
166
+ /**
167
+ * Visit a parse tree produced by `YiniParser.colon_list_decl`.
168
+ * @param ctx the parse tree
169
+ * @grammarRule KEY WS? COLON (eol | WS+)* elements (eol | WS+)* eol
170
+ * @return the visitor result
171
+ */
172
+ visitColon_list_decl: (ctx: Colon_list_declContext) => any;
173
+ /**
174
+ * Visit a parse tree produced by `YiniParser.string_concat`.
175
+ * @param ctx the parse tree
176
+ * @return the visitor result
177
+ */
178
+ visitString_concat: (ctx: String_concatContext) => any;
179
+ /**
180
+ * Visit a parse tree produced by `YiniParser.bad_member`.
181
+ * @param ctx the parse tree
182
+ * @return the visitor result
183
+ */
184
+ visitBad_member: (ctx: Bad_memberContext) => any;
185
+ /**
186
+ * Visit a parse tree produced by `YiniParser.bad_meta_text`.
187
+ * @param ctx the parse tree
188
+ * @return the visitor result
189
+ */
190
+ visitBad_meta_text: (ctx: Bad_meta_textContext) => any;
191
+ }