MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseValue

Method parseValue

packages/effect/src/unstable/encoding/Toml.ts:188–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

186 }
187
188 private parseValue(): unknown {
189 const character = this.peek()
190 if (character === "\"") {
191 return this.parseBasicString(this.input.startsWith("\"\"\"", this.index))
192 }
193 if (character === "'") {
194 return this.parseLiteralString(this.input.startsWith("'''", this.index))
195 }
196 if (character === "[") {
197 return this.parseArray()
198 }
199 if (character === "{") {
200 return this.parseInlineTable()
201 }
202
203 const spaceSeparatedDateTime = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)/
204 .exec(this.input.slice(this.index))
205 if (spaceSeparatedDateTime !== null) {
206 this.advance(spaceSeparatedDateTime[0].length)
207 return this.parseDate(`${spaceSeparatedDateTime[1]}T${spaceSeparatedDateTime[2]}`)!
208 }
209
210 const start = this.index
211 while (!this.done && !/[\s,#\]}]/.test(this.peek())) {
212 this.advance()
213 }
214 const token = this.input.slice(start, this.index)
215 if (token === "true") return true
216 if (token === "false") return false
217 if (token.length === 0) this.fail("Expected a value")
218
219 const date = this.parseDate(token)
220 if (date !== undefined) {
221 return date
222 }
223
224 const number = this.parseNumber(token)
225 if (number !== undefined) {
226 return number
227 }
228 this.fail(`Invalid value '${token}'`)
229 }
230
231 private parseDate(token: string): Date | string | undefined {
232 const date = "\\d{4}-\\d{2}-\\d{2}"

Callers 3

parseMethod · 0.95
parseArrayMethod · 0.95
parseInlineTableMethod · 0.95

Calls 10

peekMethod · 0.95
parseBasicStringMethod · 0.95
parseLiteralStringMethod · 0.95
parseArrayMethod · 0.95
parseInlineTableMethod · 0.95
advanceMethod · 0.95
parseDateMethod · 0.95
failMethod · 0.95
parseNumberMethod · 0.95
execMethod · 0.80

Tested by

no test coverage detected