use serde::Serialize;
use wasm_bindgen::prelude::*;
mod completions;
mod diagnostics;
mod lints;
mod tokenize;
mod visit;
#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)]
struct Span {
from: usize,
to: usize,
}
impl Span {
fn new(from: usize, to: usize) -> Self {
Self { from, to }
}
}
#[cfg(feature = "examples")]
#[must_use]
#[wasm_bindgen]
pub fn query_spec() -> String {
use std::fmt::Write;
use crate::{examples, stdlib::STDLIB};
let stdlib_docs = STDLIB
.documentation(1)
.unwrap_or_else(|e| format!("**COULD NOT RENDER STDLIB DOCS**: {e}"));
let examples_section = examples::MPL
.iter()
.fold(String::new(), |mut s, (name, example)| {
let _ = write!(&mut s, "## {name}\n```\n{example}\n```\n");
s
});
format!(
"# MPL Metrics Query Specification\n\n{}\n\n# Standard library\n{}\n\n# Examples\n{}",
examples::SPEC,
stdlib_docs,
examples_section
)
}
fn to_js_value(value: &impl Serialize) -> JsValue {
value
.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
.unwrap_or(JsValue::NULL)
}