projen 0.80.6 → 0.80.7
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/.jsii +41 -41
- package/lib/awscdk/auto-discover.js +5 -5
- package/lib/awscdk/awscdk-app-java.js +1 -1
- package/lib/awscdk/awscdk-app-py.js +1 -1
- package/lib/awscdk/awscdk-app-ts.js +1 -1
- package/lib/awscdk/awscdk-construct.js +2 -2
- package/lib/awscdk/awscdk-deps-java.js +1 -1
- package/lib/awscdk/awscdk-deps-js.js +1 -1
- package/lib/awscdk/awscdk-deps-py.js +1 -1
- package/lib/awscdk/awscdk-deps.js +1 -1
- package/lib/awscdk/cdk-config.js +1 -1
- package/lib/awscdk/cdk-tasks.js +1 -1
- package/lib/awscdk/integration-test.js +1 -1
- package/lib/awscdk/lambda-extension.js +1 -1
- package/lib/awscdk/lambda-function.js +2 -2
- package/lib/build/build-workflow.js +1 -1
- package/lib/cdk/auto-discover-base.js +2 -2
- package/lib/cdk/construct-lib.js +1 -1
- package/lib/cdk/integration-test-base.js +1 -1
- package/lib/cdk/jsii-docgen.js +1 -1
- package/lib/cdk/jsii-project.js +1 -1
- package/lib/cdk8s/auto-discover.js +2 -2
- package/lib/cdk8s/cdk8s-app-py.js +1 -1
- package/lib/cdk8s/cdk8s-app-ts.js +1 -1
- package/lib/cdk8s/cdk8s-construct.js +1 -1
- package/lib/cdk8s/cdk8s-deps-py.js +1 -1
- package/lib/cdk8s/cdk8s-deps.js +1 -1
- package/lib/cdk8s/integration-test.js +1 -1
- package/lib/cdktf/cdktf-construct.js +1 -1
- package/lib/circleci/circleci.js +1 -1
- package/lib/component.js +1 -1
- package/lib/dependencies.js +1 -1
- package/lib/dev-env.js +1 -1
- package/lib/docker-compose/docker-compose-service.js +1 -1
- package/lib/docker-compose/docker-compose.js +1 -1
- package/lib/file.js +1 -1
- package/lib/gitattributes.js +1 -1
- package/lib/github/actions-provider.js +1 -1
- package/lib/github/auto-approve.js +1 -1
- package/lib/github/auto-merge.js +1 -1
- package/lib/github/dependabot.js +1 -1
- package/lib/github/github-credentials.js +1 -1
- package/lib/github/github-project.js +1 -1
- package/lib/github/github.js +1 -1
- package/lib/github/mergify.js +1 -1
- package/lib/github/pr-template.js +1 -1
- package/lib/github/pull-request-lint.js +1 -1
- package/lib/github/stale.js +1 -1
- package/lib/github/task-workflow-job.js +1 -1
- package/lib/github/task-workflow.js +1 -1
- package/lib/github/workflow-actions.js +1 -1
- package/lib/github/workflow-jobs.js +1 -1
- package/lib/github/workflow-steps.js +1 -1
- package/lib/github/workflows.js +1 -1
- package/lib/gitlab/configuration.js +1 -1
- package/lib/gitlab/gitlab-configuration.js +1 -1
- package/lib/gitlab/nested-configuration.js +1 -1
- package/lib/gitpod.js +1 -1
- package/lib/ignore-file.js +1 -1
- package/lib/ini.js +1 -1
- package/lib/java/java-project.js +1 -1
- package/lib/java/junit.js +1 -1
- package/lib/java/maven-compile.js +1 -1
- package/lib/java/maven-packaging.js +1 -1
- package/lib/java/maven-sample.js +1 -1
- package/lib/java/pom.js +1 -1
- package/lib/java/projenrc.js +1 -1
- package/lib/javascript/bundler.js +1 -1
- package/lib/javascript/eslint.js +1 -1
- package/lib/javascript/jest.js +4 -4
- package/lib/javascript/license-checker.js +1 -1
- package/lib/javascript/node-package.js +1 -1
- package/lib/javascript/node-project.js +1 -1
- package/lib/javascript/npm-config.js +1 -1
- package/lib/javascript/prettier.js +1 -1
- package/lib/javascript/projenrc.js +1 -1
- package/lib/javascript/typescript-config.js +2 -2
- package/lib/javascript/upgrade-dependencies.js +2 -2
- package/lib/javascript/yarnrc.js +1 -1
- package/lib/json-patch.js +1 -1
- package/lib/json.js +1 -1
- package/lib/license.js +1 -1
- package/lib/logger.js +1 -1
- package/lib/makefile.js +1 -1
- package/lib/object-file.js +1 -1
- package/lib/project-build.js +1 -1
- package/lib/project-tree.js +1 -1
- package/lib/project.js +1 -1
- package/lib/projects.js +1 -1
- package/lib/projenrc-json.js +2 -2
- package/lib/projenrc.js +1 -1
- package/lib/python/pip.js +1 -1
- package/lib/python/poetry.d.ts +7 -3
- package/lib/python/poetry.js +43 -21
- package/lib/python/projenrc.js +1 -1
- package/lib/python/pytest-sample.js +1 -1
- package/lib/python/pytest.js +1 -1
- package/lib/python/python-project.js +1 -1
- package/lib/python/python-sample.js +1 -1
- package/lib/python/requirements-file.js +1 -1
- package/lib/python/setuppy.js +1 -1
- package/lib/python/setuptools.js +1 -1
- package/lib/python/venv.js +1 -1
- package/lib/readme.js +1 -1
- package/lib/release/publisher.js +1 -1
- package/lib/release/release-trigger.js +1 -1
- package/lib/release/release.js +1 -1
- package/lib/renovatebot.js +1 -1
- package/lib/sample-file.js +2 -2
- package/lib/semver.js +1 -1
- package/lib/source-code.js +1 -1
- package/lib/task-runtime.js +1 -1
- package/lib/task.js +1 -1
- package/lib/tasks.js +1 -1
- package/lib/testing.js +1 -1
- package/lib/textfile.js +1 -1
- package/lib/toml.js +10 -8
- package/lib/typescript/projenrc-ts.js +1 -1
- package/lib/typescript/projenrc.js +1 -1
- package/lib/typescript/typescript-typedoc.js +1 -1
- package/lib/typescript/typescript.js +6 -6
- package/lib/version.js +2 -2
- package/lib/vscode/devcontainer.js +1 -1
- package/lib/vscode/extensions.js +1 -1
- package/lib/vscode/launch-config.js +1 -1
- package/lib/vscode/settings.js +1 -1
- package/lib/vscode/vscode.js +1 -1
- package/lib/web/next.js +3 -3
- package/lib/web/postcss.js +1 -1
- package/lib/web/react.js +4 -4
- package/lib/web/tailwind.js +1 -1
- package/lib/xmlfile.js +1 -1
- package/lib/yaml.js +1 -1
- package/node_modules/json2toml/CHANGELOG.md +128 -0
- package/node_modules/json2toml/LICENSE.txt +18 -0
- package/node_modules/json2toml/README.md +52 -0
- package/node_modules/json2toml/index.d.ts +13 -0
- package/node_modules/json2toml/index.js +160 -0
- package/node_modules/json2toml/package.json +62 -0
- package/node_modules/lodash.isdate/LICENSE +47 -0
- package/node_modules/lodash.isdate/README.md +18 -0
- package/node_modules/lodash.isdate/index.js +119 -0
- package/node_modules/lodash.isdate/package.json +17 -0
- package/node_modules/lodash.isempty/LICENSE +47 -0
- package/node_modules/lodash.isempty/README.md +18 -0
- package/node_modules/lodash.isempty/index.js +582 -0
- package/node_modules/lodash.isempty/package.json +17 -0
- package/node_modules/lodash.isplainobject/LICENSE +47 -0
- package/node_modules/lodash.isplainobject/README.md +18 -0
- package/node_modules/lodash.isplainobject/index.js +139 -0
- package/node_modules/lodash.isplainobject/package.json +17 -0
- package/node_modules/strftime/Changelog.md +286 -0
- package/node_modules/strftime/Makefile +15 -0
- package/node_modules/strftime/Readme.md +208 -0
- package/node_modules/strftime/bower.json +13 -0
- package/node_modules/strftime/component.json +16 -0
- package/node_modules/strftime/package.json +53 -0
- package/node_modules/strftime/strftime-min.js +21 -0
- package/node_modules/strftime/strftime.js +854 -0
- package/node_modules/strftime/test.js +271 -0
- package/package.json +4 -3
- package/node_modules/@iarna/toml/LICENSE +0 -14
- package/node_modules/@iarna/toml/README.md +0 -301
- package/node_modules/@iarna/toml/index.d.ts +0 -57
- package/node_modules/@iarna/toml/lib/create-date.js +0 -23
- package/node_modules/@iarna/toml/lib/create-datetime-float.js +0 -24
- package/node_modules/@iarna/toml/lib/create-datetime.js +0 -10
- package/node_modules/@iarna/toml/lib/create-time.js +0 -22
- package/node_modules/@iarna/toml/lib/format-num.js +0 -6
- package/node_modules/@iarna/toml/lib/parser-debug.js +0 -60
- package/node_modules/@iarna/toml/lib/parser.js +0 -127
- package/node_modules/@iarna/toml/lib/toml-parser.js +0 -1379
- package/node_modules/@iarna/toml/package.json +0 -82
- package/node_modules/@iarna/toml/parse-async.js +0 -30
- package/node_modules/@iarna/toml/parse-pretty-error.js +0 -33
- package/node_modules/@iarna/toml/parse-stream.js +0 -80
- package/node_modules/@iarna/toml/parse-string.js +0 -18
- package/node_modules/@iarna/toml/parse.js +0 -5
- package/node_modules/@iarna/toml/stringify.js +0 -296
- package/node_modules/@iarna/toml/toml.js +0 -3
|
@@ -1,1379 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
/* eslint-disable no-new-wrappers, no-eval, camelcase, operator-linebreak */
|
|
3
|
-
module.exports = makeParserClass(require('./parser.js'))
|
|
4
|
-
module.exports.makeParserClass = makeParserClass
|
|
5
|
-
|
|
6
|
-
class TomlError extends Error {
|
|
7
|
-
constructor (msg) {
|
|
8
|
-
super(msg)
|
|
9
|
-
this.name = 'TomlError'
|
|
10
|
-
/* istanbul ignore next */
|
|
11
|
-
if (Error.captureStackTrace) Error.captureStackTrace(this, TomlError)
|
|
12
|
-
this.fromTOML = true
|
|
13
|
-
this.wrapped = null
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
TomlError.wrap = err => {
|
|
17
|
-
const terr = new TomlError(err.message)
|
|
18
|
-
terr.code = err.code
|
|
19
|
-
terr.wrapped = err
|
|
20
|
-
return terr
|
|
21
|
-
}
|
|
22
|
-
module.exports.TomlError = TomlError
|
|
23
|
-
|
|
24
|
-
const createDateTime = require('./create-datetime.js')
|
|
25
|
-
const createDateTimeFloat = require('./create-datetime-float.js')
|
|
26
|
-
const createDate = require('./create-date.js')
|
|
27
|
-
const createTime = require('./create-time.js')
|
|
28
|
-
|
|
29
|
-
const CTRL_I = 0x09
|
|
30
|
-
const CTRL_J = 0x0A
|
|
31
|
-
const CTRL_M = 0x0D
|
|
32
|
-
const CTRL_CHAR_BOUNDARY = 0x1F // the last non-character in the latin1 region of unicode, except DEL
|
|
33
|
-
const CHAR_SP = 0x20
|
|
34
|
-
const CHAR_QUOT = 0x22
|
|
35
|
-
const CHAR_NUM = 0x23
|
|
36
|
-
const CHAR_APOS = 0x27
|
|
37
|
-
const CHAR_PLUS = 0x2B
|
|
38
|
-
const CHAR_COMMA = 0x2C
|
|
39
|
-
const CHAR_HYPHEN = 0x2D
|
|
40
|
-
const CHAR_PERIOD = 0x2E
|
|
41
|
-
const CHAR_0 = 0x30
|
|
42
|
-
const CHAR_1 = 0x31
|
|
43
|
-
const CHAR_7 = 0x37
|
|
44
|
-
const CHAR_9 = 0x39
|
|
45
|
-
const CHAR_COLON = 0x3A
|
|
46
|
-
const CHAR_EQUALS = 0x3D
|
|
47
|
-
const CHAR_A = 0x41
|
|
48
|
-
const CHAR_E = 0x45
|
|
49
|
-
const CHAR_F = 0x46
|
|
50
|
-
const CHAR_T = 0x54
|
|
51
|
-
const CHAR_U = 0x55
|
|
52
|
-
const CHAR_Z = 0x5A
|
|
53
|
-
const CHAR_LOWBAR = 0x5F
|
|
54
|
-
const CHAR_a = 0x61
|
|
55
|
-
const CHAR_b = 0x62
|
|
56
|
-
const CHAR_e = 0x65
|
|
57
|
-
const CHAR_f = 0x66
|
|
58
|
-
const CHAR_i = 0x69
|
|
59
|
-
const CHAR_l = 0x6C
|
|
60
|
-
const CHAR_n = 0x6E
|
|
61
|
-
const CHAR_o = 0x6F
|
|
62
|
-
const CHAR_r = 0x72
|
|
63
|
-
const CHAR_s = 0x73
|
|
64
|
-
const CHAR_t = 0x74
|
|
65
|
-
const CHAR_u = 0x75
|
|
66
|
-
const CHAR_x = 0x78
|
|
67
|
-
const CHAR_z = 0x7A
|
|
68
|
-
const CHAR_LCUB = 0x7B
|
|
69
|
-
const CHAR_RCUB = 0x7D
|
|
70
|
-
const CHAR_LSQB = 0x5B
|
|
71
|
-
const CHAR_BSOL = 0x5C
|
|
72
|
-
const CHAR_RSQB = 0x5D
|
|
73
|
-
const CHAR_DEL = 0x7F
|
|
74
|
-
const SURROGATE_FIRST = 0xD800
|
|
75
|
-
const SURROGATE_LAST = 0xDFFF
|
|
76
|
-
|
|
77
|
-
const escapes = {
|
|
78
|
-
[CHAR_b]: '\u0008',
|
|
79
|
-
[CHAR_t]: '\u0009',
|
|
80
|
-
[CHAR_n]: '\u000A',
|
|
81
|
-
[CHAR_f]: '\u000C',
|
|
82
|
-
[CHAR_r]: '\u000D',
|
|
83
|
-
[CHAR_QUOT]: '\u0022',
|
|
84
|
-
[CHAR_BSOL]: '\u005C'
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function isDigit (cp) {
|
|
88
|
-
return cp >= CHAR_0 && cp <= CHAR_9
|
|
89
|
-
}
|
|
90
|
-
function isHexit (cp) {
|
|
91
|
-
return (cp >= CHAR_A && cp <= CHAR_F) || (cp >= CHAR_a && cp <= CHAR_f) || (cp >= CHAR_0 && cp <= CHAR_9)
|
|
92
|
-
}
|
|
93
|
-
function isBit (cp) {
|
|
94
|
-
return cp === CHAR_1 || cp === CHAR_0
|
|
95
|
-
}
|
|
96
|
-
function isOctit (cp) {
|
|
97
|
-
return (cp >= CHAR_0 && cp <= CHAR_7)
|
|
98
|
-
}
|
|
99
|
-
function isAlphaNumQuoteHyphen (cp) {
|
|
100
|
-
return (cp >= CHAR_A && cp <= CHAR_Z)
|
|
101
|
-
|| (cp >= CHAR_a && cp <= CHAR_z)
|
|
102
|
-
|| (cp >= CHAR_0 && cp <= CHAR_9)
|
|
103
|
-
|| cp === CHAR_APOS
|
|
104
|
-
|| cp === CHAR_QUOT
|
|
105
|
-
|| cp === CHAR_LOWBAR
|
|
106
|
-
|| cp === CHAR_HYPHEN
|
|
107
|
-
}
|
|
108
|
-
function isAlphaNumHyphen (cp) {
|
|
109
|
-
return (cp >= CHAR_A && cp <= CHAR_Z)
|
|
110
|
-
|| (cp >= CHAR_a && cp <= CHAR_z)
|
|
111
|
-
|| (cp >= CHAR_0 && cp <= CHAR_9)
|
|
112
|
-
|| cp === CHAR_LOWBAR
|
|
113
|
-
|| cp === CHAR_HYPHEN
|
|
114
|
-
}
|
|
115
|
-
const _type = Symbol('type')
|
|
116
|
-
const _declared = Symbol('declared')
|
|
117
|
-
|
|
118
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty
|
|
119
|
-
const defineProperty = Object.defineProperty
|
|
120
|
-
const descriptor = {configurable: true, enumerable: true, writable: true, value: undefined}
|
|
121
|
-
|
|
122
|
-
function hasKey (obj, key) {
|
|
123
|
-
if (hasOwnProperty.call(obj, key)) return true
|
|
124
|
-
if (key === '__proto__') defineProperty(obj, '__proto__', descriptor)
|
|
125
|
-
return false
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const INLINE_TABLE = Symbol('inline-table')
|
|
129
|
-
function InlineTable () {
|
|
130
|
-
return Object.defineProperties({}, {
|
|
131
|
-
[_type]: {value: INLINE_TABLE}
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
function isInlineTable (obj) {
|
|
135
|
-
if (obj === null || typeof (obj) !== 'object') return false
|
|
136
|
-
return obj[_type] === INLINE_TABLE
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const TABLE = Symbol('table')
|
|
140
|
-
function Table () {
|
|
141
|
-
return Object.defineProperties({}, {
|
|
142
|
-
[_type]: {value: TABLE},
|
|
143
|
-
[_declared]: {value: false, writable: true}
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
function isTable (obj) {
|
|
147
|
-
if (obj === null || typeof (obj) !== 'object') return false
|
|
148
|
-
return obj[_type] === TABLE
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const _contentType = Symbol('content-type')
|
|
152
|
-
const INLINE_LIST = Symbol('inline-list')
|
|
153
|
-
function InlineList (type) {
|
|
154
|
-
return Object.defineProperties([], {
|
|
155
|
-
[_type]: {value: INLINE_LIST},
|
|
156
|
-
[_contentType]: {value: type}
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
function isInlineList (obj) {
|
|
160
|
-
if (obj === null || typeof (obj) !== 'object') return false
|
|
161
|
-
return obj[_type] === INLINE_LIST
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const LIST = Symbol('list')
|
|
165
|
-
function List () {
|
|
166
|
-
return Object.defineProperties([], {
|
|
167
|
-
[_type]: {value: LIST}
|
|
168
|
-
})
|
|
169
|
-
}
|
|
170
|
-
function isList (obj) {
|
|
171
|
-
if (obj === null || typeof (obj) !== 'object') return false
|
|
172
|
-
return obj[_type] === LIST
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// in an eval, to let bundlers not slurp in a util proxy
|
|
176
|
-
let _custom
|
|
177
|
-
try {
|
|
178
|
-
const utilInspect = eval("require('util').inspect")
|
|
179
|
-
_custom = utilInspect.custom
|
|
180
|
-
} catch (_) {
|
|
181
|
-
/* eval require not available in transpiled bundle */
|
|
182
|
-
}
|
|
183
|
-
/* istanbul ignore next */
|
|
184
|
-
const _inspect = _custom || 'inspect'
|
|
185
|
-
|
|
186
|
-
class BoxedBigInt {
|
|
187
|
-
constructor (value) {
|
|
188
|
-
try {
|
|
189
|
-
this.value = global.BigInt.asIntN(64, value)
|
|
190
|
-
} catch (_) {
|
|
191
|
-
/* istanbul ignore next */
|
|
192
|
-
this.value = null
|
|
193
|
-
}
|
|
194
|
-
Object.defineProperty(this, _type, {value: INTEGER})
|
|
195
|
-
}
|
|
196
|
-
isNaN () {
|
|
197
|
-
return this.value === null
|
|
198
|
-
}
|
|
199
|
-
/* istanbul ignore next */
|
|
200
|
-
toString () {
|
|
201
|
-
return String(this.value)
|
|
202
|
-
}
|
|
203
|
-
/* istanbul ignore next */
|
|
204
|
-
[_inspect] () {
|
|
205
|
-
return `[BigInt: ${this.toString()}]}`
|
|
206
|
-
}
|
|
207
|
-
valueOf () {
|
|
208
|
-
return this.value
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const INTEGER = Symbol('integer')
|
|
213
|
-
function Integer (value) {
|
|
214
|
-
let num = Number(value)
|
|
215
|
-
// -0 is a float thing, not an int thing
|
|
216
|
-
if (Object.is(num, -0)) num = 0
|
|
217
|
-
/* istanbul ignore else */
|
|
218
|
-
if (global.BigInt && !Number.isSafeInteger(num)) {
|
|
219
|
-
return new BoxedBigInt(value)
|
|
220
|
-
} else {
|
|
221
|
-
/* istanbul ignore next */
|
|
222
|
-
return Object.defineProperties(new Number(num), {
|
|
223
|
-
isNaN: {value: function () { return isNaN(this) }},
|
|
224
|
-
[_type]: {value: INTEGER},
|
|
225
|
-
[_inspect]: {value: () => `[Integer: ${value}]`}
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function isInteger (obj) {
|
|
230
|
-
if (obj === null || typeof (obj) !== 'object') return false
|
|
231
|
-
return obj[_type] === INTEGER
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const FLOAT = Symbol('float')
|
|
235
|
-
function Float (value) {
|
|
236
|
-
/* istanbul ignore next */
|
|
237
|
-
return Object.defineProperties(new Number(value), {
|
|
238
|
-
[_type]: {value: FLOAT},
|
|
239
|
-
[_inspect]: {value: () => `[Float: ${value}]`}
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
function isFloat (obj) {
|
|
243
|
-
if (obj === null || typeof (obj) !== 'object') return false
|
|
244
|
-
return obj[_type] === FLOAT
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function tomlType (value) {
|
|
248
|
-
const type = typeof value
|
|
249
|
-
if (type === 'object') {
|
|
250
|
-
/* istanbul ignore if */
|
|
251
|
-
if (value === null) return 'null'
|
|
252
|
-
if (value instanceof Date) return 'datetime'
|
|
253
|
-
/* istanbul ignore else */
|
|
254
|
-
if (_type in value) {
|
|
255
|
-
switch (value[_type]) {
|
|
256
|
-
case INLINE_TABLE: return 'inline-table'
|
|
257
|
-
case INLINE_LIST: return 'inline-list'
|
|
258
|
-
/* istanbul ignore next */
|
|
259
|
-
case TABLE: return 'table'
|
|
260
|
-
/* istanbul ignore next */
|
|
261
|
-
case LIST: return 'list'
|
|
262
|
-
case FLOAT: return 'float'
|
|
263
|
-
case INTEGER: return 'integer'
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return type
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function makeParserClass (Parser) {
|
|
271
|
-
class TOMLParser extends Parser {
|
|
272
|
-
constructor () {
|
|
273
|
-
super()
|
|
274
|
-
this.ctx = this.obj = Table()
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/* MATCH HELPER */
|
|
278
|
-
atEndOfWord () {
|
|
279
|
-
return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine()
|
|
280
|
-
}
|
|
281
|
-
atEndOfLine () {
|
|
282
|
-
return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
parseStart () {
|
|
286
|
-
if (this.char === Parser.END) {
|
|
287
|
-
return null
|
|
288
|
-
} else if (this.char === CHAR_LSQB) {
|
|
289
|
-
return this.call(this.parseTableOrList)
|
|
290
|
-
} else if (this.char === CHAR_NUM) {
|
|
291
|
-
return this.call(this.parseComment)
|
|
292
|
-
} else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
|
|
293
|
-
return null
|
|
294
|
-
} else if (isAlphaNumQuoteHyphen(this.char)) {
|
|
295
|
-
return this.callNow(this.parseAssignStatement)
|
|
296
|
-
} else {
|
|
297
|
-
throw this.error(new TomlError(`Unknown character "${this.char}"`))
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// HELPER, this strips any whitespace and comments to the end of the line
|
|
302
|
-
// then RETURNS. Last state in a production.
|
|
303
|
-
parseWhitespaceToEOL () {
|
|
304
|
-
if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
|
|
305
|
-
return null
|
|
306
|
-
} else if (this.char === CHAR_NUM) {
|
|
307
|
-
return this.goto(this.parseComment)
|
|
308
|
-
} else if (this.char === Parser.END || this.char === CTRL_J) {
|
|
309
|
-
return this.return()
|
|
310
|
-
} else {
|
|
311
|
-
throw this.error(new TomlError('Unexpected character, expected only whitespace or comments till end of line'))
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/* ASSIGNMENT: key = value */
|
|
316
|
-
parseAssignStatement () {
|
|
317
|
-
return this.callNow(this.parseAssign, this.recordAssignStatement)
|
|
318
|
-
}
|
|
319
|
-
recordAssignStatement (kv) {
|
|
320
|
-
let target = this.ctx
|
|
321
|
-
let finalKey = kv.key.pop()
|
|
322
|
-
for (let kw of kv.key) {
|
|
323
|
-
if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
|
|
324
|
-
throw this.error(new TomlError("Can't redefine existing key"))
|
|
325
|
-
}
|
|
326
|
-
target = target[kw] = target[kw] || Table()
|
|
327
|
-
}
|
|
328
|
-
if (hasKey(target, finalKey)) {
|
|
329
|
-
throw this.error(new TomlError("Can't redefine existing key"))
|
|
330
|
-
}
|
|
331
|
-
// unbox our numbers
|
|
332
|
-
if (isInteger(kv.value) || isFloat(kv.value)) {
|
|
333
|
-
target[finalKey] = kv.value.valueOf()
|
|
334
|
-
} else {
|
|
335
|
-
target[finalKey] = kv.value
|
|
336
|
-
}
|
|
337
|
-
return this.goto(this.parseWhitespaceToEOL)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/* ASSSIGNMENT expression, key = value possibly inside an inline table */
|
|
341
|
-
parseAssign () {
|
|
342
|
-
return this.callNow(this.parseKeyword, this.recordAssignKeyword)
|
|
343
|
-
}
|
|
344
|
-
recordAssignKeyword (key) {
|
|
345
|
-
if (this.state.resultTable) {
|
|
346
|
-
this.state.resultTable.push(key)
|
|
347
|
-
} else {
|
|
348
|
-
this.state.resultTable = [key]
|
|
349
|
-
}
|
|
350
|
-
return this.goto(this.parseAssignKeywordPreDot)
|
|
351
|
-
}
|
|
352
|
-
parseAssignKeywordPreDot () {
|
|
353
|
-
if (this.char === CHAR_PERIOD) {
|
|
354
|
-
return this.next(this.parseAssignKeywordPostDot)
|
|
355
|
-
} else if (this.char !== CHAR_SP && this.char !== CTRL_I) {
|
|
356
|
-
return this.goto(this.parseAssignEqual)
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
parseAssignKeywordPostDot () {
|
|
360
|
-
if (this.char !== CHAR_SP && this.char !== CTRL_I) {
|
|
361
|
-
return this.callNow(this.parseKeyword, this.recordAssignKeyword)
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
parseAssignEqual () {
|
|
366
|
-
if (this.char === CHAR_EQUALS) {
|
|
367
|
-
return this.next(this.parseAssignPreValue)
|
|
368
|
-
} else {
|
|
369
|
-
throw this.error(new TomlError('Invalid character, expected "="'))
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
parseAssignPreValue () {
|
|
373
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
374
|
-
return null
|
|
375
|
-
} else {
|
|
376
|
-
return this.callNow(this.parseValue, this.recordAssignValue)
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
recordAssignValue (value) {
|
|
380
|
-
return this.returnNow({key: this.state.resultTable, value: value})
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/* COMMENTS: #...eol */
|
|
384
|
-
parseComment () {
|
|
385
|
-
do {
|
|
386
|
-
if (this.char === Parser.END || this.char === CTRL_J) {
|
|
387
|
-
return this.return()
|
|
388
|
-
}
|
|
389
|
-
} while (this.nextChar())
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/* TABLES AND LISTS, [foo] and [[foo]] */
|
|
393
|
-
parseTableOrList () {
|
|
394
|
-
if (this.char === CHAR_LSQB) {
|
|
395
|
-
this.next(this.parseList)
|
|
396
|
-
} else {
|
|
397
|
-
return this.goto(this.parseTable)
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/* TABLE [foo.bar.baz] */
|
|
402
|
-
parseTable () {
|
|
403
|
-
this.ctx = this.obj
|
|
404
|
-
return this.goto(this.parseTableNext)
|
|
405
|
-
}
|
|
406
|
-
parseTableNext () {
|
|
407
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
408
|
-
return null
|
|
409
|
-
} else {
|
|
410
|
-
return this.callNow(this.parseKeyword, this.parseTableMore)
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
parseTableMore (keyword) {
|
|
414
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
415
|
-
return null
|
|
416
|
-
} else if (this.char === CHAR_RSQB) {
|
|
417
|
-
if (hasKey(this.ctx, keyword) && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) {
|
|
418
|
-
throw this.error(new TomlError("Can't redefine existing key"))
|
|
419
|
-
} else {
|
|
420
|
-
this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table()
|
|
421
|
-
this.ctx[_declared] = true
|
|
422
|
-
}
|
|
423
|
-
return this.next(this.parseWhitespaceToEOL)
|
|
424
|
-
} else if (this.char === CHAR_PERIOD) {
|
|
425
|
-
if (!hasKey(this.ctx, keyword)) {
|
|
426
|
-
this.ctx = this.ctx[keyword] = Table()
|
|
427
|
-
} else if (isTable(this.ctx[keyword])) {
|
|
428
|
-
this.ctx = this.ctx[keyword]
|
|
429
|
-
} else if (isList(this.ctx[keyword])) {
|
|
430
|
-
this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1]
|
|
431
|
-
} else {
|
|
432
|
-
throw this.error(new TomlError("Can't redefine existing key"))
|
|
433
|
-
}
|
|
434
|
-
return this.next(this.parseTableNext)
|
|
435
|
-
} else {
|
|
436
|
-
throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'))
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/* LIST [[a.b.c]] */
|
|
441
|
-
parseList () {
|
|
442
|
-
this.ctx = this.obj
|
|
443
|
-
return this.goto(this.parseListNext)
|
|
444
|
-
}
|
|
445
|
-
parseListNext () {
|
|
446
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
447
|
-
return null
|
|
448
|
-
} else {
|
|
449
|
-
return this.callNow(this.parseKeyword, this.parseListMore)
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
parseListMore (keyword) {
|
|
453
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
454
|
-
return null
|
|
455
|
-
} else if (this.char === CHAR_RSQB) {
|
|
456
|
-
if (!hasKey(this.ctx, keyword)) {
|
|
457
|
-
this.ctx[keyword] = List()
|
|
458
|
-
}
|
|
459
|
-
if (isInlineList(this.ctx[keyword])) {
|
|
460
|
-
throw this.error(new TomlError("Can't extend an inline array"))
|
|
461
|
-
} else if (isList(this.ctx[keyword])) {
|
|
462
|
-
const next = Table()
|
|
463
|
-
this.ctx[keyword].push(next)
|
|
464
|
-
this.ctx = next
|
|
465
|
-
} else {
|
|
466
|
-
throw this.error(new TomlError("Can't redefine an existing key"))
|
|
467
|
-
}
|
|
468
|
-
return this.next(this.parseListEnd)
|
|
469
|
-
} else if (this.char === CHAR_PERIOD) {
|
|
470
|
-
if (!hasKey(this.ctx, keyword)) {
|
|
471
|
-
this.ctx = this.ctx[keyword] = Table()
|
|
472
|
-
} else if (isInlineList(this.ctx[keyword])) {
|
|
473
|
-
throw this.error(new TomlError("Can't extend an inline array"))
|
|
474
|
-
} else if (isInlineTable(this.ctx[keyword])) {
|
|
475
|
-
throw this.error(new TomlError("Can't extend an inline table"))
|
|
476
|
-
} else if (isList(this.ctx[keyword])) {
|
|
477
|
-
this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1]
|
|
478
|
-
} else if (isTable(this.ctx[keyword])) {
|
|
479
|
-
this.ctx = this.ctx[keyword]
|
|
480
|
-
} else {
|
|
481
|
-
throw this.error(new TomlError("Can't redefine an existing key"))
|
|
482
|
-
}
|
|
483
|
-
return this.next(this.parseListNext)
|
|
484
|
-
} else {
|
|
485
|
-
throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'))
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
parseListEnd (keyword) {
|
|
489
|
-
if (this.char === CHAR_RSQB) {
|
|
490
|
-
return this.next(this.parseWhitespaceToEOL)
|
|
491
|
-
} else {
|
|
492
|
-
throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'))
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/* VALUE string, number, boolean, inline list, inline object */
|
|
497
|
-
parseValue () {
|
|
498
|
-
if (this.char === Parser.END) {
|
|
499
|
-
throw this.error(new TomlError('Key without value'))
|
|
500
|
-
} else if (this.char === CHAR_QUOT) {
|
|
501
|
-
return this.next(this.parseDoubleString)
|
|
502
|
-
} if (this.char === CHAR_APOS) {
|
|
503
|
-
return this.next(this.parseSingleString)
|
|
504
|
-
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
|
|
505
|
-
return this.goto(this.parseNumberSign)
|
|
506
|
-
} else if (this.char === CHAR_i) {
|
|
507
|
-
return this.next(this.parseInf)
|
|
508
|
-
} else if (this.char === CHAR_n) {
|
|
509
|
-
return this.next(this.parseNan)
|
|
510
|
-
} else if (isDigit(this.char)) {
|
|
511
|
-
return this.goto(this.parseNumberOrDateTime)
|
|
512
|
-
} else if (this.char === CHAR_t || this.char === CHAR_f) {
|
|
513
|
-
return this.goto(this.parseBoolean)
|
|
514
|
-
} else if (this.char === CHAR_LSQB) {
|
|
515
|
-
return this.call(this.parseInlineList, this.recordValue)
|
|
516
|
-
} else if (this.char === CHAR_LCUB) {
|
|
517
|
-
return this.call(this.parseInlineTable, this.recordValue)
|
|
518
|
-
} else {
|
|
519
|
-
throw this.error(new TomlError('Unexpected character, expecting string, number, datetime, boolean, inline array or inline table'))
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
recordValue (value) {
|
|
523
|
-
return this.returnNow(value)
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
parseInf () {
|
|
527
|
-
if (this.char === CHAR_n) {
|
|
528
|
-
return this.next(this.parseInf2)
|
|
529
|
-
} else {
|
|
530
|
-
throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'))
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
parseInf2 () {
|
|
534
|
-
if (this.char === CHAR_f) {
|
|
535
|
-
if (this.state.buf === '-') {
|
|
536
|
-
return this.return(-Infinity)
|
|
537
|
-
} else {
|
|
538
|
-
return this.return(Infinity)
|
|
539
|
-
}
|
|
540
|
-
} else {
|
|
541
|
-
throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'))
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
parseNan () {
|
|
546
|
-
if (this.char === CHAR_a) {
|
|
547
|
-
return this.next(this.parseNan2)
|
|
548
|
-
} else {
|
|
549
|
-
throw this.error(new TomlError('Unexpected character, expected "nan"'))
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
parseNan2 () {
|
|
553
|
-
if (this.char === CHAR_n) {
|
|
554
|
-
return this.return(NaN)
|
|
555
|
-
} else {
|
|
556
|
-
throw this.error(new TomlError('Unexpected character, expected "nan"'))
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
/* KEYS, barewords or basic, literal, or dotted */
|
|
561
|
-
parseKeyword () {
|
|
562
|
-
if (this.char === CHAR_QUOT) {
|
|
563
|
-
return this.next(this.parseBasicString)
|
|
564
|
-
} else if (this.char === CHAR_APOS) {
|
|
565
|
-
return this.next(this.parseLiteralString)
|
|
566
|
-
} else {
|
|
567
|
-
return this.goto(this.parseBareKey)
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/* KEYS: barewords */
|
|
572
|
-
parseBareKey () {
|
|
573
|
-
do {
|
|
574
|
-
if (this.char === Parser.END) {
|
|
575
|
-
throw this.error(new TomlError('Key ended without value'))
|
|
576
|
-
} else if (isAlphaNumHyphen(this.char)) {
|
|
577
|
-
this.consume()
|
|
578
|
-
} else if (this.state.buf.length === 0) {
|
|
579
|
-
throw this.error(new TomlError('Empty bare keys are not allowed'))
|
|
580
|
-
} else {
|
|
581
|
-
return this.returnNow()
|
|
582
|
-
}
|
|
583
|
-
} while (this.nextChar())
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
/* STRINGS, single quoted (literal) */
|
|
587
|
-
parseSingleString () {
|
|
588
|
-
if (this.char === CHAR_APOS) {
|
|
589
|
-
return this.next(this.parseLiteralMultiStringMaybe)
|
|
590
|
-
} else {
|
|
591
|
-
return this.goto(this.parseLiteralString)
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
parseLiteralString () {
|
|
595
|
-
do {
|
|
596
|
-
if (this.char === CHAR_APOS) {
|
|
597
|
-
return this.return()
|
|
598
|
-
} else if (this.atEndOfLine()) {
|
|
599
|
-
throw this.error(new TomlError('Unterminated string'))
|
|
600
|
-
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
|
|
601
|
-
throw this.errorControlCharInString()
|
|
602
|
-
} else {
|
|
603
|
-
this.consume()
|
|
604
|
-
}
|
|
605
|
-
} while (this.nextChar())
|
|
606
|
-
}
|
|
607
|
-
parseLiteralMultiStringMaybe () {
|
|
608
|
-
if (this.char === CHAR_APOS) {
|
|
609
|
-
return this.next(this.parseLiteralMultiString)
|
|
610
|
-
} else {
|
|
611
|
-
return this.returnNow()
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
parseLiteralMultiString () {
|
|
615
|
-
if (this.char === CTRL_M) {
|
|
616
|
-
return null
|
|
617
|
-
} else if (this.char === CTRL_J) {
|
|
618
|
-
return this.next(this.parseLiteralMultiStringContent)
|
|
619
|
-
} else {
|
|
620
|
-
return this.goto(this.parseLiteralMultiStringContent)
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
parseLiteralMultiStringContent () {
|
|
624
|
-
do {
|
|
625
|
-
if (this.char === CHAR_APOS) {
|
|
626
|
-
return this.next(this.parseLiteralMultiEnd)
|
|
627
|
-
} else if (this.char === Parser.END) {
|
|
628
|
-
throw this.error(new TomlError('Unterminated multi-line string'))
|
|
629
|
-
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M)) {
|
|
630
|
-
throw this.errorControlCharInString()
|
|
631
|
-
} else {
|
|
632
|
-
this.consume()
|
|
633
|
-
}
|
|
634
|
-
} while (this.nextChar())
|
|
635
|
-
}
|
|
636
|
-
parseLiteralMultiEnd () {
|
|
637
|
-
if (this.char === CHAR_APOS) {
|
|
638
|
-
return this.next(this.parseLiteralMultiEnd2)
|
|
639
|
-
} else {
|
|
640
|
-
this.state.buf += "'"
|
|
641
|
-
return this.goto(this.parseLiteralMultiStringContent)
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
parseLiteralMultiEnd2 () {
|
|
645
|
-
if (this.char === CHAR_APOS) {
|
|
646
|
-
return this.return()
|
|
647
|
-
} else {
|
|
648
|
-
this.state.buf += "''"
|
|
649
|
-
return this.goto(this.parseLiteralMultiStringContent)
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/* STRINGS double quoted */
|
|
654
|
-
parseDoubleString () {
|
|
655
|
-
if (this.char === CHAR_QUOT) {
|
|
656
|
-
return this.next(this.parseMultiStringMaybe)
|
|
657
|
-
} else {
|
|
658
|
-
return this.goto(this.parseBasicString)
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
parseBasicString () {
|
|
662
|
-
do {
|
|
663
|
-
if (this.char === CHAR_BSOL) {
|
|
664
|
-
return this.call(this.parseEscape, this.recordEscapeReplacement)
|
|
665
|
-
} else if (this.char === CHAR_QUOT) {
|
|
666
|
-
return this.return()
|
|
667
|
-
} else if (this.atEndOfLine()) {
|
|
668
|
-
throw this.error(new TomlError('Unterminated string'))
|
|
669
|
-
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
|
|
670
|
-
throw this.errorControlCharInString()
|
|
671
|
-
} else {
|
|
672
|
-
this.consume()
|
|
673
|
-
}
|
|
674
|
-
} while (this.nextChar())
|
|
675
|
-
}
|
|
676
|
-
recordEscapeReplacement (replacement) {
|
|
677
|
-
this.state.buf += replacement
|
|
678
|
-
return this.goto(this.parseBasicString)
|
|
679
|
-
}
|
|
680
|
-
parseMultiStringMaybe () {
|
|
681
|
-
if (this.char === CHAR_QUOT) {
|
|
682
|
-
return this.next(this.parseMultiString)
|
|
683
|
-
} else {
|
|
684
|
-
return this.returnNow()
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
parseMultiString () {
|
|
688
|
-
if (this.char === CTRL_M) {
|
|
689
|
-
return null
|
|
690
|
-
} else if (this.char === CTRL_J) {
|
|
691
|
-
return this.next(this.parseMultiStringContent)
|
|
692
|
-
} else {
|
|
693
|
-
return this.goto(this.parseMultiStringContent)
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
parseMultiStringContent () {
|
|
697
|
-
do {
|
|
698
|
-
if (this.char === CHAR_BSOL) {
|
|
699
|
-
return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement)
|
|
700
|
-
} else if (this.char === CHAR_QUOT) {
|
|
701
|
-
return this.next(this.parseMultiEnd)
|
|
702
|
-
} else if (this.char === Parser.END) {
|
|
703
|
-
throw this.error(new TomlError('Unterminated multi-line string'))
|
|
704
|
-
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M)) {
|
|
705
|
-
throw this.errorControlCharInString()
|
|
706
|
-
} else {
|
|
707
|
-
this.consume()
|
|
708
|
-
}
|
|
709
|
-
} while (this.nextChar())
|
|
710
|
-
}
|
|
711
|
-
errorControlCharInString () {
|
|
712
|
-
let displayCode = '\\u00'
|
|
713
|
-
if (this.char < 16) {
|
|
714
|
-
displayCode += '0'
|
|
715
|
-
}
|
|
716
|
-
displayCode += this.char.toString(16)
|
|
717
|
-
|
|
718
|
-
return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`))
|
|
719
|
-
}
|
|
720
|
-
recordMultiEscapeReplacement (replacement) {
|
|
721
|
-
this.state.buf += replacement
|
|
722
|
-
return this.goto(this.parseMultiStringContent)
|
|
723
|
-
}
|
|
724
|
-
parseMultiEnd () {
|
|
725
|
-
if (this.char === CHAR_QUOT) {
|
|
726
|
-
return this.next(this.parseMultiEnd2)
|
|
727
|
-
} else {
|
|
728
|
-
this.state.buf += '"'
|
|
729
|
-
return this.goto(this.parseMultiStringContent)
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
parseMultiEnd2 () {
|
|
733
|
-
if (this.char === CHAR_QUOT) {
|
|
734
|
-
return this.return()
|
|
735
|
-
} else {
|
|
736
|
-
this.state.buf += '""'
|
|
737
|
-
return this.goto(this.parseMultiStringContent)
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
parseMultiEscape () {
|
|
741
|
-
if (this.char === CTRL_M || this.char === CTRL_J) {
|
|
742
|
-
return this.next(this.parseMultiTrim)
|
|
743
|
-
} else if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
744
|
-
return this.next(this.parsePreMultiTrim)
|
|
745
|
-
} else {
|
|
746
|
-
return this.goto(this.parseEscape)
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
parsePreMultiTrim () {
|
|
750
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
751
|
-
return null
|
|
752
|
-
} else if (this.char === CTRL_M || this.char === CTRL_J) {
|
|
753
|
-
return this.next(this.parseMultiTrim)
|
|
754
|
-
} else {
|
|
755
|
-
throw this.error(new TomlError("Can't escape whitespace"))
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
parseMultiTrim () {
|
|
759
|
-
// explicitly whitespace here, END should follow the same path as chars
|
|
760
|
-
if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
|
|
761
|
-
return null
|
|
762
|
-
} else {
|
|
763
|
-
return this.returnNow()
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
parseEscape () {
|
|
767
|
-
if (this.char in escapes) {
|
|
768
|
-
return this.return(escapes[this.char])
|
|
769
|
-
} else if (this.char === CHAR_u) {
|
|
770
|
-
return this.call(this.parseSmallUnicode, this.parseUnicodeReturn)
|
|
771
|
-
} else if (this.char === CHAR_U) {
|
|
772
|
-
return this.call(this.parseLargeUnicode, this.parseUnicodeReturn)
|
|
773
|
-
} else {
|
|
774
|
-
throw this.error(new TomlError('Unknown escape character: ' + this.char))
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
parseUnicodeReturn (char) {
|
|
778
|
-
try {
|
|
779
|
-
const codePoint = parseInt(char, 16)
|
|
780
|
-
if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) {
|
|
781
|
-
throw this.error(new TomlError('Invalid unicode, character in range 0xD800 - 0xDFFF is reserved'))
|
|
782
|
-
}
|
|
783
|
-
return this.returnNow(String.fromCodePoint(codePoint))
|
|
784
|
-
} catch (err) {
|
|
785
|
-
throw this.error(TomlError.wrap(err))
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
parseSmallUnicode () {
|
|
789
|
-
if (!isHexit(this.char)) {
|
|
790
|
-
throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'))
|
|
791
|
-
} else {
|
|
792
|
-
this.consume()
|
|
793
|
-
if (this.state.buf.length >= 4) return this.return()
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
parseLargeUnicode () {
|
|
797
|
-
if (!isHexit(this.char)) {
|
|
798
|
-
throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'))
|
|
799
|
-
} else {
|
|
800
|
-
this.consume()
|
|
801
|
-
if (this.state.buf.length >= 8) return this.return()
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
/* NUMBERS */
|
|
806
|
-
parseNumberSign () {
|
|
807
|
-
this.consume()
|
|
808
|
-
return this.next(this.parseMaybeSignedInfOrNan)
|
|
809
|
-
}
|
|
810
|
-
parseMaybeSignedInfOrNan () {
|
|
811
|
-
if (this.char === CHAR_i) {
|
|
812
|
-
return this.next(this.parseInf)
|
|
813
|
-
} else if (this.char === CHAR_n) {
|
|
814
|
-
return this.next(this.parseNan)
|
|
815
|
-
} else {
|
|
816
|
-
return this.callNow(this.parseNoUnder, this.parseNumberIntegerStart)
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
parseNumberIntegerStart () {
|
|
820
|
-
if (this.char === CHAR_0) {
|
|
821
|
-
this.consume()
|
|
822
|
-
return this.next(this.parseNumberIntegerExponentOrDecimal)
|
|
823
|
-
} else {
|
|
824
|
-
return this.goto(this.parseNumberInteger)
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
parseNumberIntegerExponentOrDecimal () {
|
|
828
|
-
if (this.char === CHAR_PERIOD) {
|
|
829
|
-
this.consume()
|
|
830
|
-
return this.call(this.parseNoUnder, this.parseNumberFloat)
|
|
831
|
-
} else if (this.char === CHAR_E || this.char === CHAR_e) {
|
|
832
|
-
this.consume()
|
|
833
|
-
return this.next(this.parseNumberExponentSign)
|
|
834
|
-
} else {
|
|
835
|
-
return this.returnNow(Integer(this.state.buf))
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
parseNumberInteger () {
|
|
839
|
-
if (isDigit(this.char)) {
|
|
840
|
-
this.consume()
|
|
841
|
-
} else if (this.char === CHAR_LOWBAR) {
|
|
842
|
-
return this.call(this.parseNoUnder)
|
|
843
|
-
} else if (this.char === CHAR_E || this.char === CHAR_e) {
|
|
844
|
-
this.consume()
|
|
845
|
-
return this.next(this.parseNumberExponentSign)
|
|
846
|
-
} else if (this.char === CHAR_PERIOD) {
|
|
847
|
-
this.consume()
|
|
848
|
-
return this.call(this.parseNoUnder, this.parseNumberFloat)
|
|
849
|
-
} else {
|
|
850
|
-
const result = Integer(this.state.buf)
|
|
851
|
-
/* istanbul ignore if */
|
|
852
|
-
if (result.isNaN()) {
|
|
853
|
-
throw this.error(new TomlError('Invalid number'))
|
|
854
|
-
} else {
|
|
855
|
-
return this.returnNow(result)
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
parseNoUnder () {
|
|
860
|
-
if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD || this.char === CHAR_E || this.char === CHAR_e) {
|
|
861
|
-
throw this.error(new TomlError('Unexpected character, expected digit'))
|
|
862
|
-
} else if (this.atEndOfWord()) {
|
|
863
|
-
throw this.error(new TomlError('Incomplete number'))
|
|
864
|
-
}
|
|
865
|
-
return this.returnNow()
|
|
866
|
-
}
|
|
867
|
-
parseNoUnderHexOctBinLiteral () {
|
|
868
|
-
if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD) {
|
|
869
|
-
throw this.error(new TomlError('Unexpected character, expected digit'))
|
|
870
|
-
} else if (this.atEndOfWord()) {
|
|
871
|
-
throw this.error(new TomlError('Incomplete number'))
|
|
872
|
-
}
|
|
873
|
-
return this.returnNow()
|
|
874
|
-
}
|
|
875
|
-
parseNumberFloat () {
|
|
876
|
-
if (this.char === CHAR_LOWBAR) {
|
|
877
|
-
return this.call(this.parseNoUnder, this.parseNumberFloat)
|
|
878
|
-
} else if (isDigit(this.char)) {
|
|
879
|
-
this.consume()
|
|
880
|
-
} else if (this.char === CHAR_E || this.char === CHAR_e) {
|
|
881
|
-
this.consume()
|
|
882
|
-
return this.next(this.parseNumberExponentSign)
|
|
883
|
-
} else {
|
|
884
|
-
return this.returnNow(Float(this.state.buf))
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
parseNumberExponentSign () {
|
|
888
|
-
if (isDigit(this.char)) {
|
|
889
|
-
return this.goto(this.parseNumberExponent)
|
|
890
|
-
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
|
|
891
|
-
this.consume()
|
|
892
|
-
this.call(this.parseNoUnder, this.parseNumberExponent)
|
|
893
|
-
} else {
|
|
894
|
-
throw this.error(new TomlError('Unexpected character, expected -, + or digit'))
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
parseNumberExponent () {
|
|
898
|
-
if (isDigit(this.char)) {
|
|
899
|
-
this.consume()
|
|
900
|
-
} else if (this.char === CHAR_LOWBAR) {
|
|
901
|
-
return this.call(this.parseNoUnder)
|
|
902
|
-
} else {
|
|
903
|
-
return this.returnNow(Float(this.state.buf))
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
/* NUMBERS or DATETIMES */
|
|
908
|
-
parseNumberOrDateTime () {
|
|
909
|
-
if (this.char === CHAR_0) {
|
|
910
|
-
this.consume()
|
|
911
|
-
return this.next(this.parseNumberBaseOrDateTime)
|
|
912
|
-
} else {
|
|
913
|
-
return this.goto(this.parseNumberOrDateTimeOnly)
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
parseNumberOrDateTimeOnly () {
|
|
917
|
-
// note, if two zeros are in a row then it MUST be a date
|
|
918
|
-
if (this.char === CHAR_LOWBAR) {
|
|
919
|
-
return this.call(this.parseNoUnder, this.parseNumberInteger)
|
|
920
|
-
} else if (isDigit(this.char)) {
|
|
921
|
-
this.consume()
|
|
922
|
-
if (this.state.buf.length > 4) this.next(this.parseNumberInteger)
|
|
923
|
-
} else if (this.char === CHAR_E || this.char === CHAR_e) {
|
|
924
|
-
this.consume()
|
|
925
|
-
return this.next(this.parseNumberExponentSign)
|
|
926
|
-
} else if (this.char === CHAR_PERIOD) {
|
|
927
|
-
this.consume()
|
|
928
|
-
return this.call(this.parseNoUnder, this.parseNumberFloat)
|
|
929
|
-
} else if (this.char === CHAR_HYPHEN) {
|
|
930
|
-
return this.goto(this.parseDateTime)
|
|
931
|
-
} else if (this.char === CHAR_COLON) {
|
|
932
|
-
return this.goto(this.parseOnlyTimeHour)
|
|
933
|
-
} else {
|
|
934
|
-
return this.returnNow(Integer(this.state.buf))
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
parseDateTimeOnly () {
|
|
938
|
-
if (this.state.buf.length < 4) {
|
|
939
|
-
if (isDigit(this.char)) {
|
|
940
|
-
return this.consume()
|
|
941
|
-
} else if (this.char === CHAR_COLON) {
|
|
942
|
-
return this.goto(this.parseOnlyTimeHour)
|
|
943
|
-
} else {
|
|
944
|
-
throw this.error(new TomlError('Expected digit while parsing year part of a date'))
|
|
945
|
-
}
|
|
946
|
-
} else {
|
|
947
|
-
if (this.char === CHAR_HYPHEN) {
|
|
948
|
-
return this.goto(this.parseDateTime)
|
|
949
|
-
} else {
|
|
950
|
-
throw this.error(new TomlError('Expected hyphen (-) while parsing year part of date'))
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
parseNumberBaseOrDateTime () {
|
|
955
|
-
if (this.char === CHAR_b) {
|
|
956
|
-
this.consume()
|
|
957
|
-
return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerBin)
|
|
958
|
-
} else if (this.char === CHAR_o) {
|
|
959
|
-
this.consume()
|
|
960
|
-
return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerOct)
|
|
961
|
-
} else if (this.char === CHAR_x) {
|
|
962
|
-
this.consume()
|
|
963
|
-
return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerHex)
|
|
964
|
-
} else if (this.char === CHAR_PERIOD) {
|
|
965
|
-
return this.goto(this.parseNumberInteger)
|
|
966
|
-
} else if (isDigit(this.char)) {
|
|
967
|
-
return this.goto(this.parseDateTimeOnly)
|
|
968
|
-
} else {
|
|
969
|
-
return this.returnNow(Integer(this.state.buf))
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
parseIntegerHex () {
|
|
973
|
-
if (isHexit(this.char)) {
|
|
974
|
-
this.consume()
|
|
975
|
-
} else if (this.char === CHAR_LOWBAR) {
|
|
976
|
-
return this.call(this.parseNoUnderHexOctBinLiteral)
|
|
977
|
-
} else {
|
|
978
|
-
const result = Integer(this.state.buf)
|
|
979
|
-
/* istanbul ignore if */
|
|
980
|
-
if (result.isNaN()) {
|
|
981
|
-
throw this.error(new TomlError('Invalid number'))
|
|
982
|
-
} else {
|
|
983
|
-
return this.returnNow(result)
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
parseIntegerOct () {
|
|
988
|
-
if (isOctit(this.char)) {
|
|
989
|
-
this.consume()
|
|
990
|
-
} else if (this.char === CHAR_LOWBAR) {
|
|
991
|
-
return this.call(this.parseNoUnderHexOctBinLiteral)
|
|
992
|
-
} else {
|
|
993
|
-
const result = Integer(this.state.buf)
|
|
994
|
-
/* istanbul ignore if */
|
|
995
|
-
if (result.isNaN()) {
|
|
996
|
-
throw this.error(new TomlError('Invalid number'))
|
|
997
|
-
} else {
|
|
998
|
-
return this.returnNow(result)
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
parseIntegerBin () {
|
|
1003
|
-
if (isBit(this.char)) {
|
|
1004
|
-
this.consume()
|
|
1005
|
-
} else if (this.char === CHAR_LOWBAR) {
|
|
1006
|
-
return this.call(this.parseNoUnderHexOctBinLiteral)
|
|
1007
|
-
} else {
|
|
1008
|
-
const result = Integer(this.state.buf)
|
|
1009
|
-
/* istanbul ignore if */
|
|
1010
|
-
if (result.isNaN()) {
|
|
1011
|
-
throw this.error(new TomlError('Invalid number'))
|
|
1012
|
-
} else {
|
|
1013
|
-
return this.returnNow(result)
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
/* DATETIME */
|
|
1019
|
-
parseDateTime () {
|
|
1020
|
-
// we enter here having just consumed the year and about to consume the hyphen
|
|
1021
|
-
if (this.state.buf.length < 4) {
|
|
1022
|
-
throw this.error(new TomlError('Years less than 1000 must be zero padded to four characters'))
|
|
1023
|
-
}
|
|
1024
|
-
this.state.result = this.state.buf
|
|
1025
|
-
this.state.buf = ''
|
|
1026
|
-
return this.next(this.parseDateMonth)
|
|
1027
|
-
}
|
|
1028
|
-
parseDateMonth () {
|
|
1029
|
-
if (this.char === CHAR_HYPHEN) {
|
|
1030
|
-
if (this.state.buf.length < 2) {
|
|
1031
|
-
throw this.error(new TomlError('Months less than 10 must be zero padded to two characters'))
|
|
1032
|
-
}
|
|
1033
|
-
this.state.result += '-' + this.state.buf
|
|
1034
|
-
this.state.buf = ''
|
|
1035
|
-
return this.next(this.parseDateDay)
|
|
1036
|
-
} else if (isDigit(this.char)) {
|
|
1037
|
-
this.consume()
|
|
1038
|
-
} else {
|
|
1039
|
-
throw this.error(new TomlError('Incomplete datetime'))
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
parseDateDay () {
|
|
1043
|
-
if (this.char === CHAR_T || this.char === CHAR_SP) {
|
|
1044
|
-
if (this.state.buf.length < 2) {
|
|
1045
|
-
throw this.error(new TomlError('Days less than 10 must be zero padded to two characters'))
|
|
1046
|
-
}
|
|
1047
|
-
this.state.result += '-' + this.state.buf
|
|
1048
|
-
this.state.buf = ''
|
|
1049
|
-
return this.next(this.parseStartTimeHour)
|
|
1050
|
-
} else if (this.atEndOfWord()) {
|
|
1051
|
-
return this.returnNow(createDate(this.state.result + '-' + this.state.buf))
|
|
1052
|
-
} else if (isDigit(this.char)) {
|
|
1053
|
-
this.consume()
|
|
1054
|
-
} else {
|
|
1055
|
-
throw this.error(new TomlError('Incomplete datetime'))
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
parseStartTimeHour () {
|
|
1059
|
-
if (this.atEndOfWord()) {
|
|
1060
|
-
return this.returnNow(createDate(this.state.result))
|
|
1061
|
-
} else {
|
|
1062
|
-
return this.goto(this.parseTimeHour)
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
parseTimeHour () {
|
|
1066
|
-
if (this.char === CHAR_COLON) {
|
|
1067
|
-
if (this.state.buf.length < 2) {
|
|
1068
|
-
throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'))
|
|
1069
|
-
}
|
|
1070
|
-
this.state.result += 'T' + this.state.buf
|
|
1071
|
-
this.state.buf = ''
|
|
1072
|
-
return this.next(this.parseTimeMin)
|
|
1073
|
-
} else if (isDigit(this.char)) {
|
|
1074
|
-
this.consume()
|
|
1075
|
-
} else {
|
|
1076
|
-
throw this.error(new TomlError('Incomplete datetime'))
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
parseTimeMin () {
|
|
1080
|
-
if (this.state.buf.length < 2 && isDigit(this.char)) {
|
|
1081
|
-
this.consume()
|
|
1082
|
-
} else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
|
|
1083
|
-
this.state.result += ':' + this.state.buf
|
|
1084
|
-
this.state.buf = ''
|
|
1085
|
-
return this.next(this.parseTimeSec)
|
|
1086
|
-
} else {
|
|
1087
|
-
throw this.error(new TomlError('Incomplete datetime'))
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
parseTimeSec () {
|
|
1091
|
-
if (isDigit(this.char)) {
|
|
1092
|
-
this.consume()
|
|
1093
|
-
if (this.state.buf.length === 2) {
|
|
1094
|
-
this.state.result += ':' + this.state.buf
|
|
1095
|
-
this.state.buf = ''
|
|
1096
|
-
return this.next(this.parseTimeZoneOrFraction)
|
|
1097
|
-
}
|
|
1098
|
-
} else {
|
|
1099
|
-
throw this.error(new TomlError('Incomplete datetime'))
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
parseOnlyTimeHour () {
|
|
1104
|
-
/* istanbul ignore else */
|
|
1105
|
-
if (this.char === CHAR_COLON) {
|
|
1106
|
-
if (this.state.buf.length < 2) {
|
|
1107
|
-
throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'))
|
|
1108
|
-
}
|
|
1109
|
-
this.state.result = this.state.buf
|
|
1110
|
-
this.state.buf = ''
|
|
1111
|
-
return this.next(this.parseOnlyTimeMin)
|
|
1112
|
-
} else {
|
|
1113
|
-
throw this.error(new TomlError('Incomplete time'))
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
parseOnlyTimeMin () {
|
|
1117
|
-
if (this.state.buf.length < 2 && isDigit(this.char)) {
|
|
1118
|
-
this.consume()
|
|
1119
|
-
} else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
|
|
1120
|
-
this.state.result += ':' + this.state.buf
|
|
1121
|
-
this.state.buf = ''
|
|
1122
|
-
return this.next(this.parseOnlyTimeSec)
|
|
1123
|
-
} else {
|
|
1124
|
-
throw this.error(new TomlError('Incomplete time'))
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
parseOnlyTimeSec () {
|
|
1128
|
-
if (isDigit(this.char)) {
|
|
1129
|
-
this.consume()
|
|
1130
|
-
if (this.state.buf.length === 2) {
|
|
1131
|
-
return this.next(this.parseOnlyTimeFractionMaybe)
|
|
1132
|
-
}
|
|
1133
|
-
} else {
|
|
1134
|
-
throw this.error(new TomlError('Incomplete time'))
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
parseOnlyTimeFractionMaybe () {
|
|
1138
|
-
this.state.result += ':' + this.state.buf
|
|
1139
|
-
if (this.char === CHAR_PERIOD) {
|
|
1140
|
-
this.state.buf = ''
|
|
1141
|
-
this.next(this.parseOnlyTimeFraction)
|
|
1142
|
-
} else {
|
|
1143
|
-
return this.return(createTime(this.state.result))
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
parseOnlyTimeFraction () {
|
|
1147
|
-
if (isDigit(this.char)) {
|
|
1148
|
-
this.consume()
|
|
1149
|
-
} else if (this.atEndOfWord()) {
|
|
1150
|
-
if (this.state.buf.length === 0) throw this.error(new TomlError('Expected digit in milliseconds'))
|
|
1151
|
-
return this.returnNow(createTime(this.state.result + '.' + this.state.buf))
|
|
1152
|
-
} else {
|
|
1153
|
-
throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'))
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
parseTimeZoneOrFraction () {
|
|
1158
|
-
if (this.char === CHAR_PERIOD) {
|
|
1159
|
-
this.consume()
|
|
1160
|
-
this.next(this.parseDateTimeFraction)
|
|
1161
|
-
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
|
|
1162
|
-
this.consume()
|
|
1163
|
-
this.next(this.parseTimeZoneHour)
|
|
1164
|
-
} else if (this.char === CHAR_Z) {
|
|
1165
|
-
this.consume()
|
|
1166
|
-
return this.return(createDateTime(this.state.result + this.state.buf))
|
|
1167
|
-
} else if (this.atEndOfWord()) {
|
|
1168
|
-
return this.returnNow(createDateTimeFloat(this.state.result + this.state.buf))
|
|
1169
|
-
} else {
|
|
1170
|
-
throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'))
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
parseDateTimeFraction () {
|
|
1174
|
-
if (isDigit(this.char)) {
|
|
1175
|
-
this.consume()
|
|
1176
|
-
} else if (this.state.buf.length === 1) {
|
|
1177
|
-
throw this.error(new TomlError('Expected digit in milliseconds'))
|
|
1178
|
-
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
|
|
1179
|
-
this.consume()
|
|
1180
|
-
this.next(this.parseTimeZoneHour)
|
|
1181
|
-
} else if (this.char === CHAR_Z) {
|
|
1182
|
-
this.consume()
|
|
1183
|
-
return this.return(createDateTime(this.state.result + this.state.buf))
|
|
1184
|
-
} else if (this.atEndOfWord()) {
|
|
1185
|
-
return this.returnNow(createDateTimeFloat(this.state.result + this.state.buf))
|
|
1186
|
-
} else {
|
|
1187
|
-
throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'))
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
parseTimeZoneHour () {
|
|
1191
|
-
if (isDigit(this.char)) {
|
|
1192
|
-
this.consume()
|
|
1193
|
-
// FIXME: No more regexps
|
|
1194
|
-
if (/\d\d$/.test(this.state.buf)) return this.next(this.parseTimeZoneSep)
|
|
1195
|
-
} else {
|
|
1196
|
-
throw this.error(new TomlError('Unexpected character in datetime, expected digit'))
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
parseTimeZoneSep () {
|
|
1200
|
-
if (this.char === CHAR_COLON) {
|
|
1201
|
-
this.consume()
|
|
1202
|
-
this.next(this.parseTimeZoneMin)
|
|
1203
|
-
} else {
|
|
1204
|
-
throw this.error(new TomlError('Unexpected character in datetime, expected colon'))
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
parseTimeZoneMin () {
|
|
1208
|
-
if (isDigit(this.char)) {
|
|
1209
|
-
this.consume()
|
|
1210
|
-
if (/\d\d$/.test(this.state.buf)) return this.return(createDateTime(this.state.result + this.state.buf))
|
|
1211
|
-
} else {
|
|
1212
|
-
throw this.error(new TomlError('Unexpected character in datetime, expected digit'))
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
/* BOOLEAN */
|
|
1217
|
-
parseBoolean () {
|
|
1218
|
-
/* istanbul ignore else */
|
|
1219
|
-
if (this.char === CHAR_t) {
|
|
1220
|
-
this.consume()
|
|
1221
|
-
return this.next(this.parseTrue_r)
|
|
1222
|
-
} else if (this.char === CHAR_f) {
|
|
1223
|
-
this.consume()
|
|
1224
|
-
return this.next(this.parseFalse_a)
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
parseTrue_r () {
|
|
1228
|
-
if (this.char === CHAR_r) {
|
|
1229
|
-
this.consume()
|
|
1230
|
-
return this.next(this.parseTrue_u)
|
|
1231
|
-
} else {
|
|
1232
|
-
throw this.error(new TomlError('Invalid boolean, expected true or false'))
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
parseTrue_u () {
|
|
1236
|
-
if (this.char === CHAR_u) {
|
|
1237
|
-
this.consume()
|
|
1238
|
-
return this.next(this.parseTrue_e)
|
|
1239
|
-
} else {
|
|
1240
|
-
throw this.error(new TomlError('Invalid boolean, expected true or false'))
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
parseTrue_e () {
|
|
1244
|
-
if (this.char === CHAR_e) {
|
|
1245
|
-
return this.return(true)
|
|
1246
|
-
} else {
|
|
1247
|
-
throw this.error(new TomlError('Invalid boolean, expected true or false'))
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
parseFalse_a () {
|
|
1252
|
-
if (this.char === CHAR_a) {
|
|
1253
|
-
this.consume()
|
|
1254
|
-
return this.next(this.parseFalse_l)
|
|
1255
|
-
} else {
|
|
1256
|
-
throw this.error(new TomlError('Invalid boolean, expected true or false'))
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
parseFalse_l () {
|
|
1261
|
-
if (this.char === CHAR_l) {
|
|
1262
|
-
this.consume()
|
|
1263
|
-
return this.next(this.parseFalse_s)
|
|
1264
|
-
} else {
|
|
1265
|
-
throw this.error(new TomlError('Invalid boolean, expected true or false'))
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
parseFalse_s () {
|
|
1270
|
-
if (this.char === CHAR_s) {
|
|
1271
|
-
this.consume()
|
|
1272
|
-
return this.next(this.parseFalse_e)
|
|
1273
|
-
} else {
|
|
1274
|
-
throw this.error(new TomlError('Invalid boolean, expected true or false'))
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
parseFalse_e () {
|
|
1279
|
-
if (this.char === CHAR_e) {
|
|
1280
|
-
return this.return(false)
|
|
1281
|
-
} else {
|
|
1282
|
-
throw this.error(new TomlError('Invalid boolean, expected true or false'))
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
/* INLINE LISTS */
|
|
1287
|
-
parseInlineList () {
|
|
1288
|
-
if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
|
|
1289
|
-
return null
|
|
1290
|
-
} else if (this.char === Parser.END) {
|
|
1291
|
-
throw this.error(new TomlError('Unterminated inline array'))
|
|
1292
|
-
} else if (this.char === CHAR_NUM) {
|
|
1293
|
-
return this.call(this.parseComment)
|
|
1294
|
-
} else if (this.char === CHAR_RSQB) {
|
|
1295
|
-
return this.return(this.state.resultArr || InlineList())
|
|
1296
|
-
} else {
|
|
1297
|
-
return this.callNow(this.parseValue, this.recordInlineListValue)
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
recordInlineListValue (value) {
|
|
1301
|
-
if (this.state.resultArr) {
|
|
1302
|
-
const listType = this.state.resultArr[_contentType]
|
|
1303
|
-
const valueType = tomlType(value)
|
|
1304
|
-
if (listType !== valueType) {
|
|
1305
|
-
throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`))
|
|
1306
|
-
}
|
|
1307
|
-
} else {
|
|
1308
|
-
this.state.resultArr = InlineList(tomlType(value))
|
|
1309
|
-
}
|
|
1310
|
-
if (isFloat(value) || isInteger(value)) {
|
|
1311
|
-
// unbox now that we've verified they're ok
|
|
1312
|
-
this.state.resultArr.push(value.valueOf())
|
|
1313
|
-
} else {
|
|
1314
|
-
this.state.resultArr.push(value)
|
|
1315
|
-
}
|
|
1316
|
-
return this.goto(this.parseInlineListNext)
|
|
1317
|
-
}
|
|
1318
|
-
parseInlineListNext () {
|
|
1319
|
-
if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
|
|
1320
|
-
return null
|
|
1321
|
-
} else if (this.char === CHAR_NUM) {
|
|
1322
|
-
return this.call(this.parseComment)
|
|
1323
|
-
} else if (this.char === CHAR_COMMA) {
|
|
1324
|
-
return this.next(this.parseInlineList)
|
|
1325
|
-
} else if (this.char === CHAR_RSQB) {
|
|
1326
|
-
return this.goto(this.parseInlineList)
|
|
1327
|
-
} else {
|
|
1328
|
-
throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'))
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
/* INLINE TABLE */
|
|
1333
|
-
parseInlineTable () {
|
|
1334
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
1335
|
-
return null
|
|
1336
|
-
} else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
|
|
1337
|
-
throw this.error(new TomlError('Unterminated inline array'))
|
|
1338
|
-
} else if (this.char === CHAR_RCUB) {
|
|
1339
|
-
return this.return(this.state.resultTable || InlineTable())
|
|
1340
|
-
} else {
|
|
1341
|
-
if (!this.state.resultTable) this.state.resultTable = InlineTable()
|
|
1342
|
-
return this.callNow(this.parseAssign, this.recordInlineTableValue)
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
recordInlineTableValue (kv) {
|
|
1346
|
-
let target = this.state.resultTable
|
|
1347
|
-
let finalKey = kv.key.pop()
|
|
1348
|
-
for (let kw of kv.key) {
|
|
1349
|
-
if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
|
|
1350
|
-
throw this.error(new TomlError("Can't redefine existing key"))
|
|
1351
|
-
}
|
|
1352
|
-
target = target[kw] = target[kw] || Table()
|
|
1353
|
-
}
|
|
1354
|
-
if (hasKey(target, finalKey)) {
|
|
1355
|
-
throw this.error(new TomlError("Can't redefine existing key"))
|
|
1356
|
-
}
|
|
1357
|
-
if (isInteger(kv.value) || isFloat(kv.value)) {
|
|
1358
|
-
target[finalKey] = kv.value.valueOf()
|
|
1359
|
-
} else {
|
|
1360
|
-
target[finalKey] = kv.value
|
|
1361
|
-
}
|
|
1362
|
-
return this.goto(this.parseInlineTableNext)
|
|
1363
|
-
}
|
|
1364
|
-
parseInlineTableNext () {
|
|
1365
|
-
if (this.char === CHAR_SP || this.char === CTRL_I) {
|
|
1366
|
-
return null
|
|
1367
|
-
} else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
|
|
1368
|
-
throw this.error(new TomlError('Unterminated inline array'))
|
|
1369
|
-
} else if (this.char === CHAR_COMMA) {
|
|
1370
|
-
return this.next(this.parseInlineTable)
|
|
1371
|
-
} else if (this.char === CHAR_RCUB) {
|
|
1372
|
-
return this.goto(this.parseInlineTable)
|
|
1373
|
-
} else {
|
|
1374
|
-
throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'))
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
return TOMLParser
|
|
1379
|
-
}
|