Skip to content

Commit

Permalink
fastn-jdebug 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 15, 2024
1 parent 1ae5f27 commit 8200661
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 71 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ members = [
"fastn-ds",
"fastn-expr",
"fastn-issues",
"fastn-jdebug",
"fastn-js",
"fastn-lang",
"fastn-package",
Expand Down
3 changes: 0 additions & 3 deletions fastn-jdebug/src/lib.rs

This file was deleted.

9 changes: 9 additions & 0 deletions v0.5/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions v0.5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"fastn-static",
"fastn-unresolved",
"fastn-update",
"fastn-jdebug",
]
exclude = []
resolver = "2"
Expand Down Expand Up @@ -39,6 +40,7 @@ homepage = "https://fastn.com"

fastn-lang = { path = "fastn-lang" }
fastn-type = "0.1.1"
fastn-jdebug = { version = "0.1.0", path = "fastn-jdebug" }
fastn-section = { path = "fastn-section" }
fastn-static = { path = "fastn-static" }
fastn-core = { path = "fastn-core" }
Expand Down
2 changes: 1 addition & 1 deletion fastn-jdebug/Cargo.toml → v0.5/fastn-jdebug/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastn-jdebug"
version = "0.1.0"
version = "0.1.1"
authors.workspace = true
edition.workspace = true
description.workspace = true
Expand Down
36 changes: 36 additions & 0 deletions v0.5/fastn-jdebug/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#![allow(clippy::derive_partial_eq_without_eq, clippy::get_first)]
#![deny(unused_crate_dependencies)]
#![warn(clippy::used_underscore_binding)]

extern crate self as fastn_jdebug;

pub trait JDebug {
fn debug(&self, source: &str) -> serde_json::Value;
}

impl<T: fastn_jdebug::JDebug> fastn_jdebug::JDebug for Vec<T> {
fn debug(&self, source: &str) -> serde_json::Value {
serde_json::Value::Array(self.iter().map(|v| v.debug(source)).collect())
}
}

impl<T: fastn_jdebug::JDebug> fastn_jdebug::JDebug for Option<T> {
fn debug(&self, source: &str) -> serde_json::Value {
self.as_ref()
.map(|v| v.debug(source))
.unwrap_or(serde_json::Value::Null)
}
}

impl<K: AsRef<std::ops::Range<usize>>, V: fastn_jdebug::JDebug> fastn_jdebug::JDebug
for std::collections::HashMap<K, V>
{
fn debug(&self, source: &str) -> serde_json::Value {
let mut o = serde_json::Map::new();
for (k, v) in self {
let r = k.as_ref();
o.insert(source[r.start..r.end].to_string(), v.debug(source));
}
serde_json::Value::Object(o)
}
}
3 changes: 3 additions & 0 deletions v0.5/fastn-section/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ homepage.workspace = true

[dependencies]
serde.workspace = true

[dev-dependencies]
serde_json.workspace = true
fastn-jdebug.workspace = true


77 changes: 24 additions & 53 deletions v0.5/fastn-section/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,33 @@
fn span(s: &fastn_section::Span, key: &str, source: &str) -> serde_json::Value {
serde_json::json!({ key: (source[s.start..s.end]).to_string()})
}
// fn span(s: &fastn_section::Span, key: &str, source: &str) -> serde_json::Value {
// serde_json::json!({ key: (source[s.start..s.end]).to_string()})
// }

impl fastn_section::JDebug for fastn_section::Span {
impl fastn_jdebug::JDebug for fastn_section::Span {
fn debug(&self, source: &str) -> serde_json::Value {
let t = &source[self.start..self.end];
if t.is_empty() { "<empty>" } else { t }.into()
}
}

impl<T: fastn_section::JDebug> fastn_section::JDebug for fastn_section::Spanned<T> {
impl<T: fastn_jdebug::JDebug> fastn_jdebug::JDebug for fastn_section::Spanned<T> {
fn debug(&self, source: &str) -> serde_json::Value {
self.value.debug(source)
}
}

impl fastn_section::JDebug for fastn_section::Spanned<()> {
fn debug(&self, source: &str) -> serde_json::Value {
span(&self.span, "spanned", source)
}
}

impl<T: fastn_section::JDebug> fastn_section::JDebug for Vec<T> {
fn debug(&self, source: &str) -> serde_json::Value {
serde_json::Value::Array(self.iter().map(|v| v.debug(source)).collect())
}
}

impl<T: fastn_section::JDebug> fastn_section::JDebug
for std::collections::HashMap<fastn_section::Identifier, T>
{
fn debug(&self, source: &str) -> serde_json::Value {
let mut o = serde_json::Map::new();
for (k, v) in self {
o.insert(
source[k.name.start..k.name.end].to_string(),
v.debug(source),
);
}
serde_json::Value::Object(o)
}
}

impl<T: fastn_section::JDebug> fastn_section::JDebug for Option<T> {
fn debug(&self, source: &str) -> serde_json::Value {
self.as_ref()
.map(|v| v.debug(source))
.unwrap_or(serde_json::Value::Null)
}
}
// impl fastn_jdebug::JDebug for fastn_section::Spanned<()> {
// fn debug(&self, source: &str) -> serde_json::Value {
// span(&self.span, "spanned", source)
// }
// }

impl fastn_section::JDebug for fastn_section::Visibility {
impl fastn_jdebug::JDebug for fastn_section::Visibility {
fn debug(&self, _source: &str) -> serde_json::Value {
format!("{self:?}").into()
}
}

impl fastn_section::JDebug for fastn_section::Document {
impl fastn_jdebug::JDebug for fastn_section::Document {
fn debug(&self, source: &str) -> serde_json::Value {
let mut o = serde_json::Map::new();
if self.module_doc.is_some() {
Expand All @@ -80,7 +51,7 @@ impl fastn_section::JDebug for fastn_section::Document {
}
}

impl fastn_section::JDebug for fastn_section::Section {
impl fastn_jdebug::JDebug for fastn_section::Section {
fn debug(&self, source: &str) -> serde_json::Value {
// todo: add headers etc (only if they are not null)
let mut o = serde_json::Map::new();
Expand All @@ -94,13 +65,13 @@ impl fastn_section::JDebug for fastn_section::Section {
}
}

impl fastn_section::JDebug for fastn_section::SectionInit {
impl fastn_jdebug::JDebug for fastn_section::SectionInit {
fn debug(&self, source: &str) -> serde_json::Value {
self.name.debug(source)
}
}

impl fastn_section::JDebug for fastn_section::KindedName {
impl fastn_jdebug::JDebug for fastn_section::KindedName {
fn debug(&self, source: &str) -> serde_json::Value {
let mut o = serde_json::Map::new();
if let Some(kind) = &self.kind {
Expand All @@ -111,7 +82,7 @@ impl fastn_section::JDebug for fastn_section::KindedName {
}
}

impl fastn_section::JDebug for fastn_section::Kind {
impl fastn_jdebug::JDebug for fastn_section::Kind {
fn debug(&self, source: &str) -> serde_json::Value {
if let Some(v) = self.to_identifier() {
return v.debug(source);
Expand All @@ -132,7 +103,7 @@ impl fastn_section::JDebug for fastn_section::Kind {
}
}

impl fastn_section::JDebug for fastn_section::QualifiedIdentifier {
impl fastn_jdebug::JDebug for fastn_section::QualifiedIdentifier {
fn debug(&self, source: &str) -> serde_json::Value {
if self.terms.is_empty() {
return self.module.debug(source);
Expand All @@ -145,13 +116,13 @@ impl fastn_section::JDebug for fastn_section::QualifiedIdentifier {
}
}

impl fastn_section::JDebug for fastn_section::HeaderValue {
impl fastn_jdebug::JDebug for fastn_section::HeaderValue {
fn debug(&self, source: &str) -> serde_json::Value {
self.0.debug(source)
}
}

impl fastn_section::JDebug for fastn_section::Tes {
impl fastn_jdebug::JDebug for fastn_section::Tes {
fn debug(&self, source: &str) -> serde_json::Value {
match self {
fastn_section::Tes::Text(e) => e.debug(source),
Expand All @@ -161,13 +132,13 @@ impl fastn_section::JDebug for fastn_section::Tes {
}
}

impl fastn_section::JDebug for fastn_section::Identifier {
impl fastn_jdebug::JDebug for fastn_section::Identifier {
fn debug(&self, source: &str) -> serde_json::Value {
self.name.debug(source)
}
}

impl fastn_section::JDebug for fastn_section::PackageName {
impl fastn_jdebug::JDebug for fastn_section::PackageName {
fn debug(&self, source: &str) -> serde_json::Value {
format!(
"{} as {}",
Expand All @@ -178,7 +149,7 @@ impl fastn_section::JDebug for fastn_section::PackageName {
}
}

impl fastn_section::JDebug for fastn_section::AliasableIdentifier {
impl fastn_jdebug::JDebug for fastn_section::AliasableIdentifier {
fn debug(&self, source: &str) -> serde_json::Value {
if self.alias.is_none() {
return self.name.debug(source);
Expand All @@ -191,7 +162,7 @@ impl fastn_section::JDebug for fastn_section::AliasableIdentifier {
}
}

impl fastn_section::JDebug for fastn_section::ModuleName {
impl fastn_jdebug::JDebug for fastn_section::ModuleName {
fn debug(&self, source: &str) -> serde_json::Value {
if self.path.is_empty()
&& self.name.alias.is_none()
Expand Down Expand Up @@ -220,7 +191,7 @@ impl fastn_section::JDebug for fastn_section::ModuleName {
}
}

impl fastn_section::JDebug for fastn_section::Error {
impl fastn_jdebug::JDebug for fastn_section::Error {
fn debug(&self, source: &str) -> serde_json::Value {
error(self, &Default::default(), source)
}
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-section/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn document(scanner: &mut fastn_section::Scanner<fastn_section::Document>) {
#[cfg(test)]
#[track_caller]
fn p<
T: fastn_section::JDebug,
T: fastn_jdebug::JDebug,
F: FnOnce(&mut fastn_section::Scanner<fastn_section::Document>) -> T,
>(
source: &str,
Expand Down
3 changes: 2 additions & 1 deletion v0.5/fastn-unresolved/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ serde.workspace = true
fastn-type.workspace = true

[dev-dependencies]
serde_json.workspace = true
fastn-jdebug.workspace = true
serde_json.workspace = true
10 changes: 5 additions & 5 deletions v0.5/fastn-unresolved/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde_json::Value;

impl fastn_section::JDebug for fastn_unresolved::Import {
impl fastn_jdebug::JDebug for fastn_unresolved::Import {
fn debug(&self, source: &str) -> serde_json::Value {
let mut o = serde_json::Map::new();

Expand Down Expand Up @@ -33,7 +33,7 @@ impl fastn_section::JDebug for fastn_unresolved::Import {
}
}

impl fastn_section::JDebug for fastn_unresolved::Export {
impl fastn_jdebug::JDebug for fastn_unresolved::Export {
fn debug(&self, source: &str) -> serde_json::Value {
match self {
fastn_unresolved::Export::All => "all".into(),
Expand All @@ -44,7 +44,7 @@ impl fastn_section::JDebug for fastn_unresolved::Export {
}
}

impl fastn_section::JDebug for fastn_unresolved::AliasableIdentifier {
impl fastn_jdebug::JDebug for fastn_unresolved::AliasableIdentifier {
fn debug(&self, _source: &str) -> serde_json::Value {
match self.alias {
Some(ref v) => format!("{}=>{}", self.name.0, v.0),
Expand All @@ -54,13 +54,13 @@ impl fastn_section::JDebug for fastn_unresolved::AliasableIdentifier {
}
}

impl fastn_section::JDebug for fastn_unresolved::ComponentInvocation {
impl fastn_jdebug::JDebug for fastn_unresolved::ComponentInvocation {
fn debug(&self, _source: &str) -> Value {
todo!()
}
}

impl<U: fastn_section::JDebug, R: fastn_section::JDebug> fastn_section::JDebug
impl<U: fastn_jdebug::JDebug, R: fastn_jdebug::JDebug> fastn_jdebug::JDebug
for fastn_unresolved::UR<U, R>
{
fn debug(&self, _source: &str) -> Value {
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-unresolved/src/parser/component_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod tests {
assert_eq!(d.content.len(), 1);

assert_eq!(
fastn_section::JDebug::debug(&d.content.pop().unwrap(), source),
fastn_jdebug::JDebug::debug(&d.content.pop().unwrap(), source),
expected
)
}
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-unresolved/src/parser/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ mod tests {
assert_eq!(d.imports.len(), 1);

assert_eq!(
fastn_section::JDebug::debug(&d.imports.pop().unwrap(), source),
fastn_jdebug::JDebug::debug(&d.imports.pop().unwrap(), source),
expected
)
}
Expand Down

0 comments on commit 8200661

Please sign in to comment.