1#![deny(rust_2018_idioms, unsafe_code)]
4#![allow(clippy::derive_partial_eq_without_eq)]
5
6pub use self::{parser::parse_schema, reformat::reformat, source_file::SourceFile};
7
8pub mod ast;
11
12mod parser;
13mod reformat;
14mod renderer;
15mod source_file;
16
17pub fn string_literal(s: &str) -> impl std::fmt::Display + '_ {
29 struct StringLiteral<'a>(&'a str);
30
31 impl std::fmt::Display for StringLiteral<'_> {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 f.write_str("\"")?;
34 for c in self.0.char_indices() {
35 match c {
36 (_, '\t') => f.write_str("\\t")?,
37 (_, '\n') => f.write_str("\\n")?,
38 (_, '"') => f.write_str("\\\"")?,
39 (_, '\r') => f.write_str("\\r")?,
40 (_, '\\') => f.write_str("\\\\")?,
41 (_, c) if c.is_ascii_control() => {
43 let mut b = [0];
44 c.encode_utf8(&mut b);
45 f.write_fmt(format_args!("\\u{:04x}", b[0]))?;
46 }
47 (start, other) => f.write_str(&self.0[start..(start + other.len_utf8())])?,
48 }
49 }
50 f.write_str("\"")
51 }
52 }
53
54 StringLiteral(s)
55}