Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Oct 4, 2023
1 parent 3810a42 commit a1ef4ac
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 297 deletions.
201 changes: 0 additions & 201 deletions rust/candid_parser/LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions rust/candid_parser/LICENSE
9 changes: 0 additions & 9 deletions rust/candid_parser/README.md

This file was deleted.

18 changes: 1 addition & 17 deletions rust/candid_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Provides parser for Candid type and value.
//! * `str.parse::<IDLProg>()` parses the Candid signature file to Candid AST.
//! * `str.parse::<IDLArgs>()` parses the Candid value in text format to a struct `IDLArg` that can be used for serialization and deserialization between Candid and an enum type `IDLValue` in Rust.
//! * `parse_idl_args()` parses the Candid value in text format to a struct `IDLArg` that can be used for serialization and deserialization between Candid and an enum type `IDLValue` in Rust.
pub mod grammar;

Expand All @@ -17,22 +17,6 @@ pub mod configs;
pub mod random;
pub mod test;

// impl std::str::FromStr for IDLArgs {
// type Err = crate::Error;
// fn from_str(str: &str) -> std::result::Result<Self, Self::Err> {
// let lexer = token::Tokenizer::new(str);
// Ok(grammar::ArgsParser::new().parse(lexer)?)
// }
// }

// impl std::str::FromStr for IDLValue {
// type Err = crate::Error;
// fn from_str(str: &str) -> std::result::Result<Self, Self::Err> {
// let lexer = token::Tokenizer::new(str);
// Ok(grammar::ArgParser::new().parse(lexer)?)
// }
// }

pub fn parse_idl_args(s: &str) -> crate::Result<candid::IDLArgs> {
let lexer = token::Tokenizer::new(s);
Ok(grammar::ArgsParser::new().parse(lexer)?)
Expand Down
58 changes: 0 additions & 58 deletions rust/candid_parser/src/parser/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,6 @@ impl<'a> GenState<'a> {
}
}

// impl IDLArgs {
// pub fn any(seed: &[u8], tree: &Configs, env: &TypeEnv, types: &[Type]) -> Result<Self> {
// let mut u = arbitrary::Unstructured::new(seed);
// let mut args = Vec::new();
// for (i, t) in types.iter().enumerate() {
// let tree = tree.with_method(&i.to_string());
// let mut state = GenState::new(&tree, env);
// let v = state.any(&mut u, t)?;
// args.push(v);
// }
// Ok(IDLArgs { args })
// }
// }

pub fn any(seed: &[u8], tree: &Configs, env: &TypeEnv, types: &[Type]) -> Result<IDLArgs> {
let mut u = arbitrary::Unstructured::new(seed);
let mut args = Vec::new();
Expand All @@ -237,50 +223,6 @@ pub fn any(seed: &[u8], tree: &Configs, env: &TypeEnv, types: &[Type]) -> Result
Ok(IDLArgs { args })
}

// impl TypeEnv {
// /// Approxiamte upper bound for IDLValue size of type t. Returns None if infinite.
// fn size_helper(&self, seen: &mut HashSet<String>, t: &Type) -> Option<usize> {
// use TypeInner::*;
// Some(match t.as_ref() {
// Var(id) => {
// if seen.insert(id.to_string()) {
// let ty = self.rec_find_type(id).unwrap();
// let res = self.size_helper(seen, ty)?;
// seen.remove(id);
// res
// } else {
// return None;
// }
// }
// Empty => 0,
// Opt(t) => 1 + self.size_helper(seen, t)?,
// Vec(t) => 1 + self.size_helper(seen, t)? * 2,
// Record(fs) => {
// let mut sum = 0;
// for Field { ty, .. } in fs.iter() {
// sum += self.size_helper(seen, ty)?;
// }
// 1 + sum
// }
// Variant(fs) => {
// let mut max = 0;
// for Field { ty, .. } in fs.iter() {
// let s = self.size_helper(seen, ty)?;
// if s > max {
// max = s;
// };
// }
// 1 + max
// }
// _ => 1,
// })
// }
// fn size(&self, t: &Type) -> Option<usize> {
// let mut seen = HashSet::new();
// self.size_helper(&mut seen, t)
// }
// }

fn size_helper(env: &TypeEnv, seen: &mut HashSet<String>, t: &Type) -> Option<usize> {
use TypeInner::*;
Some(match t.as_ref() {
Expand Down
11 changes: 0 additions & 11 deletions rust/candid_parser/src/parser/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ pub struct Env<'a> {
pub pre: bool,
}

// impl TypeEnv {
// /// Convert candid AST to internal Type
// pub fn ast_to_type(&self, ast: &super::types::IDLType) -> Result<Type> {
// let env = Env {
// te: &mut self.clone(),
// pre: false,
// };
// check_type(&env, ast)
// }
// }

/// Convert candid AST to internal Type
pub fn ast_to_type(env: &TypeEnv, ast: &super::types::IDLType) -> Result<Type> {
let env = Env {
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_parser/tests/parse_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ service server : {
prog.parse::<IDLProg>().unwrap();
}

#[test_generator::test_resources("rust/candid/tests/assets/*.did")]
#[test_generator::test_resources("rust/candid_parser/tests/assets/*.did")]
fn compiler_test(resource: &str) {
let base_path = std::env::current_dir().unwrap().join("tests/assets");
let mut mint = Mint::new(base_path.join("ok"));
Expand Down

0 comments on commit a1ef4ac

Please sign in to comment.