MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / parse_value_with

Function parse_value_with

std/json/src/main/parser.rs:32–74  ·  view source on GitHub ↗
(tk: &mut Tokenizer, t: Token, ctx: &LoadCtx)

Source from the content-addressed store, hash-verified

30}
31
32fn parse_value_with(tk: &mut Tokenizer, t: Token, ctx: &LoadCtx) -> Result<Handle> {
33 match t {
34 Token::Null => encode(Value::None),
35 Token::True => encode(Value::Bool(true)),
36 Token::False => encode(Value::Bool(false)),
37 Token::Int(i, src) => {
38 if let Some(hook) = &ctx.parse_int {
39 let arg = encode(Value::Bytes(src.into_bytes()))?;
40 hook.call("__call__", &[arg.raw()])
41 } else {
42 encode(Value::Int(i))
43 }
44 }
45 Token::Float(f, src) => {
46 if let Some(hook) = &ctx.parse_float {
47 let arg = encode(Value::Bytes(src.into_bytes()))?;
48 hook.call("__call__", &[arg.raw()])
49 } else {
50 encode(Value::Float(f))
51 }
52 }
53 Token::Constant(name) => {
54 if let Some(hook) = &ctx.parse_constant {
55 let arg = encode(Value::Bytes(name.into_bytes()))?;
56 hook.call("__call__", &[arg.raw()])
57 } else {
58 encode(Value::Float(match name.as_str() {
59 "NaN" => f64::NAN,
60 "Infinity" => f64::INFINITY,
61 "-Infinity" => f64::NEG_INFINITY,
62 _ => return Err(value_err(tk.pos(), "unknown constant")),
63 }))
64 }
65 }
66 Token::Str(s) => encode(Value::Bytes(s.into_bytes())),
67 Token::LBracket => parse_array(tk, ctx),
68 Token::LBrace => parse_object(tk, ctx),
69 Token::RBracket | Token::RBrace | Token::Comma | Token::Colon => {
70 Err(value_err(tk.pos(), "unexpected token"))
71 }
72 Token::Eof => Err(value_err(tk.pos(), "unexpected end of input")),
73 }
74}
75
76fn parse_array(tk: &mut Tokenizer, ctx: &LoadCtx) -> Result<Handle> {
77 let list = Handle::new_list()?;

Callers 2

parse_valueFunction · 0.85
parse_arrayFunction · 0.85

Calls 9

BytesClass · 0.85
value_errFunction · 0.85
parse_arrayFunction · 0.85
parse_objectFunction · 0.85
posMethod · 0.80
encodeFunction · 0.50
callMethod · 0.45
rawMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected