Skip to content

Commit

Permalink
rename bindings::candid as pretty_printer
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Oct 12, 2023
1 parent 2c37c43 commit 5715c9b
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 36 deletions.
4 changes: 0 additions & 4 deletions rust/candid/src/bindings/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion rust/candid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub mod utils;
pub use utils::{decode_args, decode_one, encode_args, encode_one, write_args};
pub mod pretty;

pub mod bindings;
pub mod pretty_printer;

// Candid hash function comes from
// https://caml.inria.fr/pub/papers/garrigue-polymorphic_variants-ml98.pdf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn compile(env: &TypeEnv, actor: &Option<Type>) -> String {
}

pub mod value {
use crate::bindings::candid::{ident_string, pp_text};
use super::{ident_string, pp_text};
use crate::pretty::*;
use crate::types::value::{IDLArgs, IDLField, IDLValue};
use crate::types::{number::pp_num_str, Label};
Expand Down Expand Up @@ -325,12 +325,7 @@ pub mod value {
Reserved => write!(f, "null : reserved"),
Principal(id) => write!(f, "principal \"{id}\""),
Service(id) => write!(f, "service \"{id}\""),
Func(id, meth) => write!(
f,
"func \"{}\".{}",
id,
crate::bindings::candid::ident_string(meth)
),
Func(id, meth) => write!(f, "func \"{}\".{}", id, ident_string(meth)),
Opt(v) if has_type_annotation(v) => write!(f, "opt ({v:?})"),
Opt(v) => write!(f, "opt {v:?}"),
Vec(vs) => {
Expand Down
16 changes: 4 additions & 12 deletions rust/candid/src/types/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,12 @@ impl Type {
}
impl fmt::Display for Type {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", crate::bindings::candid::pp_ty(self).pretty(80))
write!(f, "{}", crate::pretty_printer::pp_ty(self).pretty(80))
}
}
impl fmt::Display for TypeInner {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
crate::bindings::candid::pp_ty_inner(self).pretty(80)
)
write!(f, "{}", crate::pretty_printer::pp_ty_inner(self).pretty(80))
}
}
pub(crate) fn text_size(t: &Type, limit: i32) -> Result<i32, ()> {
Expand Down Expand Up @@ -410,7 +406,7 @@ impl fmt::Display for Field {
write!(
f,
"{}",
crate::bindings::candid::pp_field(self, false).pretty(80)
crate::pretty_printer::pp_field(self, false).pretty(80)
)
}
}
Expand Down Expand Up @@ -478,11 +474,7 @@ pub struct Function {
}
impl fmt::Display for Function {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
crate::bindings::candid::pp_function(self).pretty(80)
)
write!(f, "{}", crate::pretty_printer::pp_function(self).pretty(80))
}
}
impl Function {
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/src/types/subtype.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::internal::{find_type, Field, Label, Type, TypeInner};
use crate::bindings::candid::pp_args;
use crate::pretty_printer::pp_args;
use crate::types::TypeEnv;
use crate::{Error, Result};
use anyhow::Context;
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_derive/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub(crate) fn export_service(path: Option<TokenStream>) -> TokenStream {
fn __export_service() -> String {
#service
#actor
let result = #candid::bindings::candid::compile(&env.env, &actor);
let result = #candid::pretty_printer::compile(&env.env, &actor);
format!("{}", result)
}
};
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_parser/src/bindings/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ pub fn compile(env: &TypeEnv, actor: &Option<Type>) -> String {
}

pub mod value {
use super::super::candid::value::number_to_string;
use candid::pretty::*;
use candid::pretty_printer::value::number_to_string;
use candid::types::value::{IDLArgs, IDLField, IDLValue};
use candid::types::Label;
use pretty::RcDoc;
Expand Down
3 changes: 0 additions & 3 deletions rust/candid_parser/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Candid bindings for different languages.
// This module assumes the input are type checked, it is safe to use unwrap.

// pub mod candid;
use ::candid::bindings::candid;

pub mod analysis;
pub mod javascript;
pub mod motoko;
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_parser/src/bindings/motoko.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// This module implements the Candid to Motoko binding as specified in
// https://github.com/dfinity/motoko/blob/master/design/IDL-Motoko.md

use super::candid::is_valid_as_id;
use candid::pretty::*;
use candid::pretty_printer::is_valid_as_id;
use candid::types::FuncMode;
use candid::types::{Field, Function, Label, SharedLabel, Type, TypeEnv, TypeInner};
use pretty::RcDoc;
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_parser/src/bindings/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn pp_args(args: &[Type]) -> RcDoc {
fn pp_ty_func(f: &Function) -> RcDoc {
let args = pp_args(&f.args);
let rets = pp_args(&f.rets);
let modes = super::candid::pp_modes(&f.modes);
let modes = candid::pretty_printer::pp_modes(&f.modes);
args.append(" ->")
.append(RcDoc::space())
.append(rets.append(modes))
Expand Down
4 changes: 2 additions & 2 deletions rust/candid_parser/tests/parse_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use candid::bindings::candid as candid_export;
use candid::pretty_printer::compile;
use candid::types::TypeEnv;
use candid_parser::bindings::{javascript, motoko, rust, typescript};
use candid_parser::parser::types::IDLProg;
Expand Down Expand Up @@ -42,7 +42,7 @@ fn compiler_test(resource: &str) {
Ok((env, actor)) => {
{
let mut output = mint.new_goldenfile(filename.with_extension("did")).unwrap();
let content = candid_export::compile(&env, &actor);
let content = compile(&env, &actor);
// Type check output
let ast = content.parse::<IDLProg>().unwrap();
check_prog(&mut TypeEnv::new(), &ast).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tools/didc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn main() -> Result<()> {
let content = match target.as_str() {
"js" => candid_parser::bindings::javascript::compile(&env, &actor),
"ts" => candid_parser::bindings::typescript::compile(&env, &actor),
"did" => candid::bindings::candid::compile(&env, &actor),
"did" => candid::pretty_printer::compile(&env, &actor),
"mo" => candid_parser::bindings::motoko::compile(&env, &actor),
"rs" => {
let config = candid_parser::bindings::rust::Config::new();
Expand Down Expand Up @@ -257,7 +257,7 @@ fn main() -> Result<()> {
"blob" => {
let mut res = String::new();
for ch in bytes.iter() {
res.push_str(&candid::bindings::candid::value::pp_char(*ch));
res.push_str(&candid::pretty_printer::value::pp_char(*ch));
}
format!("blob \"{res}\"")
}
Expand Down

0 comments on commit 5715c9b

Please sign in to comment.