json
is_utf8_start_byte(n)
Checks if this is a byte that can appear at the start of a UTF-8 character.
Source code in genlm/control/potential/built_in/json.py
JustOneBlockIterable
Provides a single value (intended to be bytes from a context) and then signals if the reader tried to read past it. This allows us to distinguish invalid JSON from incomplete JSON by seeing if the reader tried to read more than it had or failed early.
Source code in genlm/control/potential/built_in/json.py
prune_to_validatable_prefix(context)
We don't want to run the JSON validator on objects that are in the middle of generating a string or a float. We also don't want to run it immediately at the end of a string, or on whitespace changes. This finds us a reasonable prefix that ends at a "logical unit" that makes it a good place to check. We can then cache checks based on the relevant prefix.
Source code in genlm/control/potential/built_in/json.py
Input
Convenience wrapper to provide a stateful stream-like interface that makes it easier to write parsers.
Source code in genlm/control/potential/built_in/json.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
|
get_partial_pattern(pattern)
async
If the remainder of the buffer read so far could match a prefix of pattern, or start with a complete match for the pattern return it.
Note: This is pure lookahead and does not advance the input.
Source code in genlm/control/potential/built_in/json.py
preserving_index()
Only advance the index if the operation in the context block does not error.
resetting_index()
Always reset the index to where it started at the end of this block.
Parser
Bases: Generic[T]
Very basic parser combinators for mostly unambiguous grammars.
Source code in genlm/control/potential/built_in/json.py
FixedSetParser
Bases: Parser[str]
Parser that matches a precise set of strings, some of which might be prefixes of each other, always returning the longest matching one.