yini-parser 1.0.1-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.
- package/CHANGELOG.md +33 -0
- package/README.md +131 -328
- package/dist/YINI.d.ts +34 -11
- package/dist/YINI.js +206 -121
- package/dist/core/ASTBuilder.d.ts +191 -0
- package/dist/core/ASTBuilder.js +827 -0
- package/dist/core/ErrorDataHandler.d.ts +19 -19
- package/dist/core/ErrorDataHandler.js +258 -150
- package/dist/core/objectBuilder.d.ts +9 -3
- package/dist/core/objectBuilder.js +126 -163
- package/dist/core/types.d.ts +234 -44
- package/dist/core/types.js +7 -33
- package/dist/grammar/YiniLexer.d.ts +54 -48
- package/dist/grammar/YiniLexer.js +330 -293
- package/dist/grammar/YiniParser.d.ts +167 -150
- package/dist/grammar/YiniParser.js +1241 -1202
- package/dist/grammar/YiniParserVisitor.d.ts +59 -45
- package/dist/grammar/YiniParserVisitor.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +298 -120
- package/dist/parseEntry.d.ts +3 -2
- package/dist/parseEntry.js +352 -81
- package/dist/parsers/extractHeaderParts.d.ts +3 -2
- package/dist/parsers/extractHeaderParts.js +1 -0
- package/dist/parsers/parseBoolean.d.ts +1 -1
- package/dist/parsers/parseBoolean.js +2 -1
- package/dist/parsers/parseNumber.d.ts +8 -3
- package/dist/parsers/parseNumber.js +50 -16
- package/dist/parsers/parseSectionHeader.d.ts +3 -2
- package/dist/parsers/parseSectionHeader.js +1 -0
- package/dist/utils/number.d.ts +3 -0
- package/dist/utils/number.js +18 -0
- package/dist/utils/object.d.ts +55 -0
- package/dist/utils/object.js +85 -0
- package/dist/utils/string.d.ts +21 -1
- package/dist/utils/string.js +39 -4
- package/dist/utils/system.d.ts +15 -0
- package/dist/utils/system.js +21 -0
- package/dist/yiniHelpers.d.ts +3 -0
- package/dist/yiniHelpers.js +43 -7
- package/package.json +3 -3
- package/dist/core/YINIVisitor.d.ts +0 -158
- package/dist/core/YINIVisitor.js +0 -1010
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { ParseTreeVisitor } from 'antlr4';
|
|
2
2
|
import { YiniContext } from "./YiniParser.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { PrologContext } from "./YiniParser.js";
|
|
4
|
+
import { Terminal_stmtContext } from "./YiniParser.js";
|
|
5
|
+
import { StmtContext } from "./YiniParser.js";
|
|
6
|
+
import { Meta_stmtContext } from "./YiniParser.js";
|
|
7
|
+
import { DirectiveContext } from "./YiniParser.js";
|
|
8
|
+
import { AnnotationContext } from "./YiniParser.js";
|
|
9
|
+
import { EolContext } from "./YiniParser.js";
|
|
10
|
+
import { AssignmentContext } from "./YiniParser.js";
|
|
6
11
|
import { MemberContext } from "./YiniParser.js";
|
|
7
|
-
import {
|
|
12
|
+
import { Colon_list_declContext } from "./YiniParser.js";
|
|
8
13
|
import { ValueContext } from "./YiniParser.js";
|
|
9
14
|
import { Object_literalContext } from "./YiniParser.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { List_in_bracketsContext } from "./YiniParser.js";
|
|
15
|
+
import { Object_membersContext } from "./YiniParser.js";
|
|
16
|
+
import { Object_memberContext } from "./YiniParser.js";
|
|
17
|
+
import { List_literalContext } from "./YiniParser.js";
|
|
14
18
|
import { ElementsContext } from "./YiniParser.js";
|
|
15
|
-
import { ElementContext } from "./YiniParser.js";
|
|
16
19
|
import { Number_literalContext } from "./YiniParser.js";
|
|
17
20
|
import { Null_literalContext } from "./YiniParser.js";
|
|
18
21
|
import { String_literalContext } from "./YiniParser.js";
|
|
19
22
|
import { String_concatContext } from "./YiniParser.js";
|
|
20
23
|
import { Boolean_literalContext } from "./YiniParser.js";
|
|
21
|
-
import {
|
|
22
|
-
import { Empty_listContext } from "./YiniParser.js";
|
|
24
|
+
import { Bad_meta_textContext } from "./YiniParser.js";
|
|
23
25
|
import { Bad_memberContext } from "./YiniParser.js";
|
|
24
26
|
/**
|
|
25
27
|
* This interface defines a complete generic visitor for a parse tree produced
|
|
@@ -36,83 +38,101 @@ export default class YiniParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|
|
36
38
|
*/
|
|
37
39
|
visitYini?: (ctx: YiniContext) => Result;
|
|
38
40
|
/**
|
|
39
|
-
* Visit a parse tree produced by `YiniParser.
|
|
41
|
+
* Visit a parse tree produced by `YiniParser.prolog`.
|
|
40
42
|
* @param ctx the parse tree
|
|
41
43
|
* @return the visitor result
|
|
42
44
|
*/
|
|
43
|
-
|
|
45
|
+
visitProlog?: (ctx: PrologContext) => Result;
|
|
44
46
|
/**
|
|
45
|
-
* Visit a parse tree produced by `YiniParser.
|
|
47
|
+
* Visit a parse tree produced by `YiniParser.terminal_stmt`.
|
|
46
48
|
* @param ctx the parse tree
|
|
47
49
|
* @return the visitor result
|
|
48
50
|
*/
|
|
49
|
-
|
|
51
|
+
visitTerminal_stmt?: (ctx: Terminal_stmtContext) => Result;
|
|
50
52
|
/**
|
|
51
|
-
* Visit a parse tree produced by `YiniParser.
|
|
53
|
+
* Visit a parse tree produced by `YiniParser.stmt`.
|
|
52
54
|
* @param ctx the parse tree
|
|
53
55
|
* @return the visitor result
|
|
54
56
|
*/
|
|
55
|
-
|
|
57
|
+
visitStmt?: (ctx: StmtContext) => Result;
|
|
56
58
|
/**
|
|
57
|
-
* Visit a parse tree produced by `YiniParser.
|
|
59
|
+
* Visit a parse tree produced by `YiniParser.meta_stmt`.
|
|
58
60
|
* @param ctx the parse tree
|
|
59
61
|
* @return the visitor result
|
|
60
62
|
*/
|
|
61
|
-
|
|
63
|
+
visitMeta_stmt?: (ctx: Meta_stmtContext) => Result;
|
|
62
64
|
/**
|
|
63
|
-
* Visit a parse tree produced by `YiniParser.
|
|
65
|
+
* Visit a parse tree produced by `YiniParser.directive`.
|
|
64
66
|
* @param ctx the parse tree
|
|
65
67
|
* @return the visitor result
|
|
66
68
|
*/
|
|
67
|
-
|
|
69
|
+
visitDirective?: (ctx: DirectiveContext) => Result;
|
|
68
70
|
/**
|
|
69
|
-
* Visit a parse tree produced by `YiniParser.
|
|
71
|
+
* Visit a parse tree produced by `YiniParser.annotation`.
|
|
70
72
|
* @param ctx the parse tree
|
|
71
73
|
* @return the visitor result
|
|
72
74
|
*/
|
|
73
|
-
|
|
75
|
+
visitAnnotation?: (ctx: AnnotationContext) => Result;
|
|
74
76
|
/**
|
|
75
|
-
* Visit a parse tree produced by `YiniParser.
|
|
77
|
+
* Visit a parse tree produced by `YiniParser.eol`.
|
|
76
78
|
* @param ctx the parse tree
|
|
77
79
|
* @return the visitor result
|
|
78
80
|
*/
|
|
79
|
-
|
|
81
|
+
visitEol?: (ctx: EolContext) => Result;
|
|
80
82
|
/**
|
|
81
|
-
* Visit a parse tree produced by `YiniParser.
|
|
83
|
+
* Visit a parse tree produced by `YiniParser.assignment`.
|
|
82
84
|
* @param ctx the parse tree
|
|
83
85
|
* @return the visitor result
|
|
84
86
|
*/
|
|
85
|
-
|
|
87
|
+
visitAssignment?: (ctx: AssignmentContext) => Result;
|
|
86
88
|
/**
|
|
87
|
-
* Visit a parse tree produced by `YiniParser.
|
|
89
|
+
* Visit a parse tree produced by `YiniParser.member`.
|
|
88
90
|
* @param ctx the parse tree
|
|
89
91
|
* @return the visitor result
|
|
90
92
|
*/
|
|
91
|
-
|
|
93
|
+
visitMember?: (ctx: MemberContext) => Result;
|
|
92
94
|
/**
|
|
93
|
-
* Visit a parse tree produced by `YiniParser.
|
|
95
|
+
* Visit a parse tree produced by `YiniParser.colon_list_decl`.
|
|
94
96
|
* @param ctx the parse tree
|
|
95
97
|
* @return the visitor result
|
|
96
98
|
*/
|
|
97
|
-
|
|
99
|
+
visitColon_list_decl?: (ctx: Colon_list_declContext) => Result;
|
|
98
100
|
/**
|
|
99
|
-
* Visit a parse tree produced by `YiniParser.
|
|
101
|
+
* Visit a parse tree produced by `YiniParser.value`.
|
|
100
102
|
* @param ctx the parse tree
|
|
101
103
|
* @return the visitor result
|
|
102
104
|
*/
|
|
103
|
-
|
|
105
|
+
visitValue?: (ctx: ValueContext) => Result;
|
|
104
106
|
/**
|
|
105
|
-
* Visit a parse tree produced by `YiniParser.
|
|
107
|
+
* Visit a parse tree produced by `YiniParser.object_literal`.
|
|
106
108
|
* @param ctx the parse tree
|
|
107
109
|
* @return the visitor result
|
|
108
110
|
*/
|
|
109
|
-
|
|
111
|
+
visitObject_literal?: (ctx: Object_literalContext) => Result;
|
|
112
|
+
/**
|
|
113
|
+
* Visit a parse tree produced by `YiniParser.object_members`.
|
|
114
|
+
* @param ctx the parse tree
|
|
115
|
+
* @return the visitor result
|
|
116
|
+
*/
|
|
117
|
+
visitObject_members?: (ctx: Object_membersContext) => Result;
|
|
118
|
+
/**
|
|
119
|
+
* Visit a parse tree produced by `YiniParser.object_member`.
|
|
120
|
+
* @param ctx the parse tree
|
|
121
|
+
* @return the visitor result
|
|
122
|
+
*/
|
|
123
|
+
visitObject_member?: (ctx: Object_memberContext) => Result;
|
|
124
|
+
/**
|
|
125
|
+
* Visit a parse tree produced by `YiniParser.list_literal`.
|
|
126
|
+
* @param ctx the parse tree
|
|
127
|
+
* @return the visitor result
|
|
128
|
+
*/
|
|
129
|
+
visitList_literal?: (ctx: List_literalContext) => Result;
|
|
110
130
|
/**
|
|
111
|
-
* Visit a parse tree produced by `YiniParser.
|
|
131
|
+
* Visit a parse tree produced by `YiniParser.elements`.
|
|
112
132
|
* @param ctx the parse tree
|
|
113
133
|
* @return the visitor result
|
|
114
134
|
*/
|
|
115
|
-
|
|
135
|
+
visitElements?: (ctx: ElementsContext) => Result;
|
|
116
136
|
/**
|
|
117
137
|
* Visit a parse tree produced by `YiniParser.number_literal`.
|
|
118
138
|
* @param ctx the parse tree
|
|
@@ -144,17 +164,11 @@ export default class YiniParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|
|
144
164
|
*/
|
|
145
165
|
visitBoolean_literal?: (ctx: Boolean_literalContext) => Result;
|
|
146
166
|
/**
|
|
147
|
-
* Visit a parse tree produced by `YiniParser.
|
|
148
|
-
* @param ctx the parse tree
|
|
149
|
-
* @return the visitor result
|
|
150
|
-
*/
|
|
151
|
-
visitEmpty_object?: (ctx: Empty_objectContext) => Result;
|
|
152
|
-
/**
|
|
153
|
-
* Visit a parse tree produced by `YiniParser.empty_list`.
|
|
167
|
+
* Visit a parse tree produced by `YiniParser.bad_meta_text`.
|
|
154
168
|
* @param ctx the parse tree
|
|
155
169
|
* @return the visitor result
|
|
156
170
|
*/
|
|
157
|
-
|
|
171
|
+
visitBad_meta_text?: (ctx: Bad_meta_textContext) => Result;
|
|
158
172
|
/**
|
|
159
173
|
* Visit a parse tree produced by `YiniParser.bad_member`.
|
|
160
174
|
* @param ctx the parse tree
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import YINI from './YINI';
|
|
2
|
-
export declare const parse:
|
|
3
|
-
export declare const parseFile:
|
|
2
|
+
export declare const parse: typeof YINI.parse;
|
|
3
|
+
export declare const parseFile: typeof YINI.parseFile;
|
|
4
|
+
export declare const getTabSize: typeof YINI.getTabSize;
|
|
5
|
+
export declare const setTabSize: typeof YINI.setTabSize;
|
|
4
6
|
export default YINI;
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// import { isDebug&&console.log } from './utils/general'
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
var _a, _b, _c;
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.parseFile = exports.parse = void 0;
|
|
9
2
|
/*
|
|
10
|
-
https://
|
|
3
|
+
https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Project-Setup.md
|
|
11
4
|
|
|
12
5
|
Run the code with the following command:
|
|
13
|
-
npx ts-node index
|
|
14
|
-
or
|
|
15
6
|
npm start
|
|
7
|
+
or
|
|
8
|
+
npm run start:dev
|
|
9
|
+
or
|
|
10
|
+
npm run start:dev:debug
|
|
16
11
|
|
|
17
12
|
/END
|
|
18
13
|
*/
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.setTabSize = exports.getTabSize = exports.parseFile = exports.parse = void 0;
|
|
19
20
|
const env_1 = require("./config/env");
|
|
20
21
|
const print_1 = require("./utils/print");
|
|
21
22
|
const YINI_1 = __importDefault(require("./YINI"));
|
|
22
|
-
// export { default } from './YINI'
|
|
23
23
|
exports.parse = YINI_1.default.parse;
|
|
24
24
|
exports.parseFile = YINI_1.default.parseFile;
|
|
25
|
+
exports.getTabSize = YINI_1.default.getTabSize;
|
|
26
|
+
exports.setTabSize = YINI_1.default.setTabSize;
|
|
25
27
|
exports.default = YINI_1.default;
|
|
26
28
|
(0, print_1.debugPrint)();
|
|
27
29
|
(0, print_1.debugPrint)('-> Entered index.ts');
|
|
@@ -52,99 +54,7 @@ if ((0, env_1.isProdEnv)()) {
|
|
|
52
54
|
// Do nothing, and exit.
|
|
53
55
|
}
|
|
54
56
|
else {
|
|
55
|
-
const invalidInput1 = `
|
|
56
|
-
^ Settings
|
|
57
|
-
fruit = "Pear"
|
|
58
|
-
number = 5
|
|
59
|
-
value q= "something"
|
|
60
|
-
`;
|
|
61
|
-
const invalidInput2 = `
|
|
62
|
-
^ Config
|
|
63
|
-
varAge = 30
|
|
64
|
-
varName = abcd
|
|
65
|
-
varNull = NULL
|
|
66
|
-
`;
|
|
67
|
-
const input1 = `
|
|
68
|
-
^ SectionName
|
|
69
|
-
varBool = true
|
|
70
|
-
varBool2 = off
|
|
71
|
-
varInt = 30
|
|
72
|
-
varFloat = 12.34
|
|
73
|
-
varStr = "Alice"
|
|
74
|
-
listItems = ["a", "b", "c"]
|
|
75
|
-
varE1 = 1e4
|
|
76
|
-
varE2 = 1.23e4
|
|
77
|
-
varE3 = 6.5E23
|
|
78
|
-
/END
|
|
79
|
-
`;
|
|
80
|
-
const input2 = `
|
|
81
|
-
^ Config
|
|
82
|
-
varAge = 30
|
|
83
|
-
varName = "Alice"
|
|
84
|
-
varNull = NULL
|
|
85
|
-
listItems = ["a", "b", "c"]
|
|
86
|
-
^^Extra
|
|
87
|
-
isExtra = true
|
|
88
|
-
/END
|
|
89
|
-
`;
|
|
90
|
-
// const input = `
|
|
91
|
-
// # Config`;
|
|
92
|
-
// debugPrint('input2:')
|
|
93
|
-
// if (isDebug()) {
|
|
94
|
-
// console.debug(input2)
|
|
95
|
-
// }
|
|
96
|
-
// parseUntilError(input2)
|
|
97
|
-
// debugPrint('invalidInput1:')
|
|
98
|
-
// if (isDebug()) {
|
|
99
|
-
// console.debug(invalidInput1)
|
|
100
|
-
// }
|
|
101
|
-
// parseUntilError(invalidInput1)
|
|
102
57
|
if (env_1.localAppEnv === 'local' && env_1.localNodeEnv !== 'test') {
|
|
103
|
-
/*
|
|
104
|
-
parseUntilError(`
|
|
105
|
-
--^ Section0
|
|
106
|
-
--value = 0
|
|
107
|
-
^ Section1
|
|
108
|
-
value = 1
|
|
109
|
-
|
|
110
|
-
^^ Section11
|
|
111
|
-
value = 11
|
|
112
|
-
|
|
113
|
-
^^^ Section111
|
|
114
|
-
value = 111
|
|
115
|
-
//^^^^ Section2104
|
|
116
|
-
value = 24
|
|
117
|
-
|
|
118
|
-
^ Section2
|
|
119
|
-
value = 2
|
|
120
|
-
`)
|
|
121
|
-
}
|
|
122
|
-
*/
|
|
123
|
-
// parseUntilError(`number = 42`)
|
|
124
|
-
/*
|
|
125
|
-
Expected JS output:
|
|
126
|
-
{
|
|
127
|
-
Section1: { value: 1, Section2: { value: 11 }},
|
|
128
|
-
Section2: { value: 2 }
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
*/
|
|
132
|
-
/*
|
|
133
|
-
parseUntilError(
|
|
134
|
-
`
|
|
135
|
-
// Using numeric shorthand section markers.
|
|
136
|
-
|
|
137
|
-
@yini
|
|
138
|
-
|
|
139
|
-
// This whole line is a comment.
|
|
140
|
-
^SectionName# This part is a comment.
|
|
141
|
-
// This whole line is a comment.
|
|
142
|
-
--x=1
|
|
143
|
-
`,
|
|
144
|
-
false,
|
|
145
|
-
2,
|
|
146
|
-
)
|
|
147
|
-
*/
|
|
148
58
|
// parseUntilError(`^1 SectionName`, false, 2)
|
|
149
59
|
// const validYini = `
|
|
150
60
|
// < user
|
|
@@ -175,24 +85,292 @@ Expected JS output:
|
|
|
175
85
|
// id = 32403 # The correct app id.
|
|
176
86
|
// title = "My Program"
|
|
177
87
|
// `
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
88
|
+
/*
|
|
89
|
+
const yini = `
|
|
90
|
+
@yini
|
|
91
|
+
|
|
92
|
+
^ NumberFormats
|
|
93
|
+
|
|
94
|
+
^^ HexFormat // Hexadecimal (base-16)
|
|
95
|
+
hex = #FF0066 // Default notation
|
|
96
|
+
altHex = 0xFF0066 // Alternative notation
|
|
97
|
+
^^ BinFormat // Binary (base-2)
|
|
98
|
+
bin = %10101111 // Default notation
|
|
99
|
+
altBin = 0b10101111 // Alternative notation
|
|
100
|
+
^^ OctFormat // Octal (base-8)
|
|
101
|
+
oct = 0o755 // ( = decimal 493)
|
|
102
|
+
^^ DozFormat // Duodecimal (base-12)
|
|
103
|
+
doz = 0z10XE // Default notation: X=10, E=11
|
|
104
|
+
altDoz = 0z10AB // Alternative notation: A=10, B=11
|
|
105
|
+
` // End.
|
|
106
|
+
*/
|
|
107
|
+
/*
|
|
108
|
+
const yini = `
|
|
109
|
+
@yini
|
|
110
|
+
@YINI ///dfsf
|
|
111
|
+
|
|
112
|
+
< User
|
|
113
|
+
nullKey =
|
|
114
|
+
nullKey2 = NULL
|
|
115
|
+
username = 'tester two'
|
|
116
|
+
userId = 234
|
|
117
|
+
userColor = #ffaa99
|
|
118
|
+
userPerm = 0O733
|
|
119
|
+
userFearues = %01101
|
|
120
|
+
isSysOp = YES
|
|
121
|
+
|
|
122
|
+
map = {
|
|
123
|
+
a: 3,
|
|
124
|
+
b: 4,
|
|
125
|
+
cc: 5,
|
|
126
|
+
\`d d\`: 3453
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
listValueB: 3, 4, 5
|
|
130
|
+
listValue2 = ["a", "b"]
|
|
131
|
+
listValue3 = [434]
|
|
132
|
+
listValue4 = []
|
|
133
|
+
listValue5 = [1, ["a", "b", "c", [null, TRUE]], 3]
|
|
134
|
+
|
|
135
|
+
--listObject = { a: 1, b: 2}
|
|
136
|
+
|
|
137
|
+
colonList:
|
|
138
|
+
1,
|
|
139
|
+
2,
|
|
140
|
+
3,
|
|
141
|
+
|
|
142
|
+
<< Prefs
|
|
143
|
+
theme = "light"
|
|
144
|
+
notifications = OFF
|
|
145
|
+
nullValue = NULL
|
|
146
|
+
|
|
147
|
+
^1 User2
|
|
148
|
+
^2 PrefsOfUser2
|
|
149
|
+
^3 DeepSection
|
|
150
|
+
^4 DeeperSection
|
|
151
|
+
key = "Level 4 section"
|
|
152
|
+
^5 YetDeeperSection
|
|
153
|
+
key = "Level 5 section"
|
|
154
|
+
item = 77
|
|
155
|
+
|
|
156
|
+
<1 User3
|
|
157
|
+
username = 'tester three'
|
|
158
|
+
isSysOp = NO
|
|
159
|
+
|
|
160
|
+
<2 Prefs2
|
|
161
|
+
theme = "special-dark"
|
|
162
|
+
notifications = ON
|
|
163
|
+
|
|
164
|
+
<2 Special
|
|
165
|
+
value = 123
|
|
166
|
+
`
|
|
167
|
+
*/
|
|
168
|
+
// npm run start:dev
|
|
169
|
+
// "timing": {
|
|
170
|
+
// "totalMs": 158.421,
|
|
171
|
+
// "phase1Ms": 151.36,
|
|
172
|
+
// "phase2Ms": 6.92,
|
|
173
|
+
// "phase3Ms": 0.14
|
|
174
|
+
// }
|
|
175
|
+
//console.log(toPrettyJSON(YINI.parse(yini, false, 'auto', true)))
|
|
176
|
+
// const yini = `
|
|
177
|
+
// < SubTitle
|
|
178
|
+
// theme = "special-dark"
|
|
179
|
+
// notifications = ON
|
|
180
|
+
// < SubTitle // NOT OK, SubTitle already exists
|
|
181
|
+
// theme2 = "special-dark"
|
|
181
182
|
// `
|
|
183
|
+
// Arrange.
|
|
184
|
+
/*
|
|
182
185
|
const yini = `
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
//
|
|
186
|
+
@yini
|
|
187
|
+
// Example: Strict-friendly YINI document (no trailing commas, explicit /END)
|
|
188
|
+
|
|
189
|
+
^ App
|
|
190
|
+
name = 'YINI Demo Service'
|
|
191
|
+
version = '1.4.0'
|
|
192
|
+
description = 'Demo service for showcasing the YINI format'
|
|
193
|
+
owners = ['dev-team', 'ops-team']
|
|
194
|
+
|
|
195
|
+
// String concatenation (the '+' joins adjacent STRING tokens)
|
|
196
|
+
-- longNote = 'This text is split across ' +
|
|
197
|
+
-- 'two strings and then concatenated.'
|
|
198
|
+
|
|
199
|
+
// Case-insensitive booleans
|
|
200
|
+
enabled = YES
|
|
201
|
+
experimentalMode = off
|
|
202
|
+
|
|
203
|
+
// Numbers (ints, floats, scientific)
|
|
204
|
+
retries = 3
|
|
205
|
+
requestTimeoutMs = 2500
|
|
206
|
+
backoffFactor = 1.25
|
|
207
|
+
maxPayloadMB = 1.0e2
|
|
208
|
+
|
|
209
|
+
^ Server
|
|
210
|
+
host = '127.0.0.1'
|
|
211
|
+
port = 8080
|
|
212
|
+
useTLS = false
|
|
213
|
+
|
|
214
|
+
^^ CORS
|
|
215
|
+
allowedOrigins: 'https://example.com', 'https://admin.example.com'
|
|
216
|
+
allowCredentials = true
|
|
217
|
+
|
|
218
|
+
^^ Headers
|
|
219
|
+
// Object literal with key:value pairs
|
|
220
|
+
defaults = {
|
|
221
|
+
\`X-Frame-Options\`: 'DENY',
|
|
222
|
+
\`X-Content-Type-Options\`: 'nosniff'
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
^ Database
|
|
226
|
+
engine = 'postgres'
|
|
227
|
+
host = 'db.internal'
|
|
228
|
+
port = 5432
|
|
229
|
+
username = 'app_user'
|
|
230
|
+
password = 'change_me'
|
|
231
|
+
pool = {
|
|
232
|
+
min: 2,
|
|
233
|
+
max: 16
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
^^ Replicas
|
|
237
|
+
// Colon-form list (values only)
|
|
238
|
+
endpoints: 'db-replica-1.internal', 'db-replica-2.internal'
|
|
239
|
+
readPreference = 'nearest'
|
|
240
|
+
|
|
241
|
+
^ Features
|
|
242
|
+
// Mixed data types
|
|
243
|
+
betaFlags = ['new-ui', 'fast-path']
|
|
244
|
+
darkLaunch = NO
|
|
245
|
+
uploadLimitMB = 128
|
|
246
|
+
|
|
247
|
+
^ Integrations
|
|
248
|
+
// List of objects
|
|
249
|
+
webhooks = [
|
|
250
|
+
{ name: 'audit', url: 'https://hooks.example.com/audit', active: true },
|
|
251
|
+
{ name: 'metrics', url: 'https://hooks.example.com/metric', active: true }
|
|
252
|
+
]
|
|
253
|
+
|
|
254
|
+
^ Users
|
|
255
|
+
// Simple table-ish list using colon form
|
|
256
|
+
admins: 'alice', 'bob', 'carol'
|
|
257
|
+
reviewers: 'dave', 'erin'
|
|
258
|
+
|
|
259
|
+
^^ Profiles
|
|
260
|
+
// Object-of-objects
|
|
261
|
+
alice = {
|
|
262
|
+
email: 'alice@example.com',
|
|
263
|
+
roles: ['admin', 'dev'],
|
|
264
|
+
mfa: true
|
|
265
|
+
}
|
|
266
|
+
bob = {
|
|
267
|
+
email: 'bob@example.com',
|
|
268
|
+
roles: ['admin'],
|
|
269
|
+
mfa: false
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
^ Paths
|
|
273
|
+
logs = '/var/log/yini-demo/'
|
|
274
|
+
data = '/srv/yini-demo/data'
|
|
275
|
+
|
|
276
|
+
^^ \`Backups\`
|
|
277
|
+
// Empty value -> null in lenient mode; in strict mode, supply explicit null:
|
|
278
|
+
lastFull = null
|
|
279
|
+
targets: '/mnt/backup1', '/mnt/backup2'
|
|
280
|
+
^^^ Backups2
|
|
281
|
+
value = 23
|
|
282
|
+
|
|
283
|
+
^ Security
|
|
284
|
+
allowedIPs: '10.0.0.0/24', '10.1.0.0/24'
|
|
285
|
+
|
|
286
|
+
^ Logging
|
|
287
|
+
level = 'info'
|
|
288
|
+
format = 'json'
|
|
289
|
+
sinks = ['stdout']
|
|
290
|
+
|
|
291
|
+
/END
|
|
292
|
+
`*/
|
|
293
|
+
// const yini = `
|
|
294
|
+
// /*sdfsdf*/
|
|
295
|
+
// @yini
|
|
296
|
+
// @include 'sdf'
|
|
297
|
+
// --@invalid
|
|
298
|
+
// @deprecated
|
|
299
|
+
// ^ window
|
|
300
|
+
// --^^ window2
|
|
301
|
+
// title = 'Sample Window' // Strings can be enclosed in either ' or ".
|
|
302
|
+
// @deprecated
|
|
303
|
+
// id = 'window_main'
|
|
304
|
+
// // @bla
|
|
305
|
+
// --@include 'wrongplace'
|
|
306
|
+
// --@yini // This is an error should be catched in the parser.
|
|
307
|
+
// /end
|
|
308
|
+
// `
|
|
309
|
+
// YINI.setTabSize(2)
|
|
310
|
+
// debugPrint('tab size = ' + YINI.getTabSize())
|
|
311
|
+
const yini = ` @yini
|
|
312
|
+
--@yini
|
|
313
|
+
^^ Header // INVALID: Must start with atleast one 1-level section.
|
|
314
|
+
key = 33254
|
|
315
|
+
/END
|
|
316
|
+
--/END
|
|
317
|
+
`;
|
|
318
|
+
console.log((0, print_1.toPrettyJSON)(YINI_1.default.parse(yini, {
|
|
319
|
+
strictMode: false,
|
|
320
|
+
failLevel: 1,
|
|
321
|
+
includeMetaData: false,
|
|
322
|
+
requireDocTerminator: false,
|
|
323
|
+
})));
|
|
324
|
+
// const yini = `
|
|
325
|
+
// ^ Booleans
|
|
326
|
+
// bool1 = true
|
|
327
|
+
// bool2 = false
|
|
328
|
+
// bool3 = on
|
|
329
|
+
// bool4 = off
|
|
330
|
+
// bool5 = yes
|
|
331
|
+
// bool6 = no
|
|
332
|
+
// `
|
|
333
|
+
// console.log(
|
|
334
|
+
// toPrettyJSON(
|
|
335
|
+
// YINI.parse(yini, {
|
|
336
|
+
// strictMode: true,
|
|
337
|
+
// failLevel: 'auto',
|
|
338
|
+
// includeMetaData: false,
|
|
339
|
+
// requireDocTerminator: false,
|
|
340
|
+
// }),
|
|
341
|
+
// ),
|
|
342
|
+
// )
|
|
343
|
+
// console.log(
|
|
344
|
+
// toPrettyJSON(
|
|
345
|
+
// YINI.parseFile(
|
|
346
|
+
// 'comprehensive-example.yini',
|
|
347
|
+
// false,
|
|
348
|
+
// 'auto',
|
|
349
|
+
// true,
|
|
350
|
+
// ),
|
|
351
|
+
// ),
|
|
352
|
+
// )
|
|
353
|
+
// console.log(
|
|
354
|
+
// toPrettyJSON(
|
|
355
|
+
// YINI.parseFile('comprehensive-example.yini', {
|
|
356
|
+
// strictMode: false,
|
|
357
|
+
// failLevel: 'auto',
|
|
358
|
+
// includeMetaData: true,
|
|
359
|
+
// }),
|
|
360
|
+
// ),
|
|
361
|
+
// )
|
|
362
|
+
// const fileName = './tests/fixtures/valid/common/common-config-2.yini'
|
|
363
|
+
// YINI.parseFile(fileName, {
|
|
364
|
+
// strictMode: false,
|
|
365
|
+
// failLevel: 'auto',
|
|
366
|
+
// includeMetaData: true,
|
|
367
|
+
// })
|
|
368
|
+
// const fileName =
|
|
369
|
+
// './tests/fixtures/invalid/bad-user-profile-config-2.yini'
|
|
370
|
+
// YINI.parseFile(fileName, {
|
|
371
|
+
// strictMode: true,
|
|
372
|
+
// failLevel: 'auto',
|
|
373
|
+
// includeMetaData: true,
|
|
374
|
+
// })
|
|
197
375
|
}
|
|
198
376
|
}
|
package/dist/parseEntry.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { IParseCoreOptions, IRuntimeInfo } from './core/types';
|
|
2
|
+
/** Single source of truth. */
|
|
3
|
+
export declare const _parseMain: (yiniContent: string, options: IParseCoreOptions | undefined, runtimeInfo: IRuntimeInfo) => any;
|