← 输入框|github.com|刷新
Skip to content
fe-langPublic

About

JSON for Fe: a parser, a writer and a document tree

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json

JSON (RFC 8259) for Fe: a document tree, a parser and a writer. It needs a compiler built from Fe's master, and is tested on the native backend.

[dependencies]
json = { source = "https://github.com/fe-lang/json", rev = "<commit>" }
use json::{Value, parse}

let doc = match parse(text.span()) {
    Result::Ok(doc) => doc
    Result::Err(e) => { eprintln!(e); return 1 }
}
let complete = doc["complete"].as_bool()
let seconds = doc["checks"][0]["seconds"].as_u64()

var report = Value::object()
report.set("name", Value::string("soak"))
report.set("runs", Value::number(3 as u64))
var out = MemBuffer::empty()
report.write_pretty(mut out, indent: 2)   // the layout of json.dumps(indent=2)
  • Objects keep their members in source order. A repeated key stays, and lookups find the last one.
  • Numbers keep their source text, so a document round-trips exactly. as_u64, as_i64, as_u256 and as_i256 read integers; 1.0 and 1e2 are not.
  • Strings hold UTF-8. Invalid UTF-8 and lone surrogates are rejected.
  • Nesting deeper than 128 is rejected, which bounds the stack.

Checks

  • fe test --backend native . runs the unit tests.
  • conformance/run.py <binary> <test_parsing dir> [file...] runs JSONTestSuite and compares output with CPython's json, layout included. Build the binary with fe build --backend native -O 2 --emit executable --out-dir out/conformance conformance.
  • bench/compare.py compares speed with a line-for-line Rust port of this parser and with serde_json, using bench/build.sh and bench/fetch_corpus.sh. The port uses the same containers and malloc and keeps its bounds checks, so a difference from it is the compiler's, not the library's design.

License

Licensed under the Apache License, Version 2.0.

About

JSON for Fe: a parser, a writer and a document tree

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages