Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions json/json_path.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub impl Show for JsonPath with fn output(self, logger) {
}
for ch in token.iter() {
match ch {
'~' => logger.write_string("~0")
'/' => logger.write_string("~1")
'~' => logger <+ "~0"
'/' => logger <+ "~1"
_ => logger.write_char(ch)
}
}
Expand All @@ -60,16 +60,12 @@ pub impl Show for JsonPath with fn output(self, logger) {
fn build_path(path : JsonPath, logger : &Logger) -> Unit {
match path {
Root => ()
Key(parent, key~) => {
build_path(parent, logger)
logger.write_char('/')
write_token(logger, key)
}
Index(parent, index~) => {
build_path(parent, logger)
logger.write_char('/')
logger.write_object(index)
}
Key(parent, key~) =>
logger <+
"\{cb => build_path(parent, cb)}/\{cb => write_token(cb, key)}"
Index(parent, index~) =>
logger <+
"\{cb => build_path(parent, cb)}/\{cb => cb.write_object(index)}"
}
}

Expand Down
47 changes: 17 additions & 30 deletions json/types.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ pub impl Show for ParseError with fn output(self, logger) {
InvalidChar({ line, column, }, c) =>
logger <+
$|Invalid character \{c.escape()} at line \{line}, column \{column}
InvalidEof => logger.write_string("Unexpected end of file")
InvalidEof => logger <+ "Unexpected end of file"
InvalidNumber({ line, column, }, s) =>
logger <+
$|Invalid number \{s} at line \{line}, column \{column}
InvalidIdentEscape({ line, column, }) =>
logger <+
$|Invalid escape sequence in identifier at line \{line}, column \{column}
DepthLimitExceeded =>
logger.write_string(
"Depth limit exceeded, please increase the max_nesting_depth parameter",
)
logger <+
$|Depth limit exceeded, please increase the max_nesting_depth parameter
}
}

Expand All @@ -57,34 +56,22 @@ pub impl Show for Json
#warnings("-deprecated")
pub impl Show for Json with fn output(self, logger) {
match self {
Null => logger.write_string("Null")
True => logger.write_string("True")
False => logger.write_string("False")
Null => logger <+ "Null"
True => logger <+ "True"
False => logger <+ "False"
Number(n, repr~) => {
logger.write_string("Number(")
Show::output(n, logger)
if repr is Some(repr) {
logger.write_string(", repr=")
logger.write_string("Some(")
Show::output(repr, logger)
logger.write_string(")")
fn write_contents(cb : &Logger) -> Unit {
Show::output(n, cb)
if repr is Some(repr) {
cb.write_string(", repr=Some(")
Show::output(repr, cb)
cb.write_string(")")
}
}
logger.write_string(")")
}
String(s) => {
logger.write_string("String(")
Show::output(s, logger)
logger.write_string(")")
}
Array(a) => {
logger.write_string("Array(")
Show::output(a, logger)
logger.write_string(")")
}
Object(o) => {
logger.write_string("Object(")
Show::output(o, logger)
logger.write_string(")")
logger <+ "Number(\{cb => write_contents(cb)})"
}
String(s) => logger <+ "String(\{cb => Show::output(s, cb)})"
Array(a) => logger <+ "Array(\{cb => Show::output(a, cb)})"
Object(o) => logger <+ "Object(\{cb => Show::output(o, cb)})"
}
}
Loading