Restore 0.1.5 version from stash

This commit is contained in:
liaibo
2025-12-08 19:56:24 +08:00
parent de189e938d
commit 8db3f4e32d
8578 changed files with 2703426 additions and 217 deletions
@@ -0,0 +1,28 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..json_parser import JSONParser # noqa: TID252
def parse_boolean_or_null(parser: "JSONParser") -> bool | str | None:
# <boolean> is one of the literal strings 'true', 'false', or 'null' (unquoted)
char = (parser.get_char_at() or "").lower()
value_map: dict[str, tuple[str, bool | None]] = {
"t": ("true", True),
"f": ("false", False),
"n": ("null", None),
}
value: tuple[str, bool | None] = value_map[char]
i = 0
starting_index = parser.index
while char and i < len(value[0]) and char == value[0][i]:
i += 1
parser.index += 1
char = (parser.get_char_at() or "").lower()
if i == len(value[0]):
return value[1]
# If nothing works reset the index before returning
parser.index = starting_index
return ""
@@ -0,0 +1,19 @@
from typing import TYPE_CHECKING
from ..utils.constants import JSONReturnType # noqa: TID252
if TYPE_CHECKING:
from ..json_parser import JSONParser # noqa: TID252
def parse_json_llm_block(parser: "JSONParser") -> JSONReturnType:
"""
Extracts and normalizes JSON enclosed in ```json ... ``` blocks.
"""
# Try to find a ```json ... ``` block
if parser.json_str[parser.index : parser.index + 7] == "```json":
i = parser.skip_to_character("`", idx=7)
if parser.json_str[parser.index + i : parser.index + i + 3] == "```":
parser.index += 7 # Move past ```json
return parser.parse_json()
return False