Skip to content

Commit

Permalink
Simplify with imports
Browse files Browse the repository at this point in the history
  • Loading branch information
timbod7 committed Aug 4, 2022
1 parent d2f60b1 commit 0c2fe8e
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions rust/compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use std::collections::HashMap;
use crate::adlgen::sys::{adlast2 as adlast};

use crate::adlrt::custom::sys::types::map::Map;
use crate::adlrt::custom::sys::types::maybe::Maybe;

use nom::{
*,
character::{
Expand Down Expand Up @@ -181,7 +184,7 @@ pub fn module(i: &str) -> Res<&str,adlast::Module<TypeExpr0>> {
name,
Vec::new(),
decls,
crate::adlrt::custom::sys::types::map::Map::new(Vec::new()),
Map::new(Vec::new()),
);

Ok( (i,module) )
Expand All @@ -195,7 +198,7 @@ pub fn decl(i: &str) -> Res<&str,adlast::Decl<TypeExpr0>> {
name: name.to_string(),
r#type: dtype,
annotations: merge_annotations(annotations),
version: crate::adlrt::custom::sys::types::maybe::Maybe::nothing()
version: Maybe::nothing()
};
Ok((i,decl))
}
Expand All @@ -222,7 +225,7 @@ pub fn merge_annotations(anns: Vec<(adlast::ScopedName, serde_json::Value)>) ->
if !ds.is_empty() {
hm.insert(docstring_scoped_name(), serde_json::Value::from(ds.join("\n")));
}
crate::adlrt::custom::sys::types::map::Map(hm)
Map(hm)
}

pub fn docstring_scoped_name() -> adlast::ScopedName {
Expand Down Expand Up @@ -331,7 +334,7 @@ pub fn field(i: &str) -> Res<&str,adlast::Field<TypeExpr0>> {
serialized_name: name.to_string(),
type_expr: texpr,
default: maybe_from_option(default),
annotations: crate::adlrt::custom::sys::types::map::Map::new(Vec::new()),
annotations: Map::new(Vec::new()),
};
Ok((i,field))
}
Expand Down Expand Up @@ -469,10 +472,10 @@ pub fn json_array(i: &str) -> Res<&str, serde_json::Value> {
)(i)
}

pub fn maybe_from_option<T>(v : Option<T>) -> crate::adlrt::custom::sys::types::maybe::Maybe<T> {
pub fn maybe_from_option<T>(v : Option<T>) ->Maybe<T> {
match v {
Some(v) => crate::adlrt::custom::sys::types::maybe::Maybe::just(v),
None => crate::adlrt::custom::sys::types::maybe::Maybe::nothing(),
Some(v) => Maybe::just(v),
None => Maybe::nothing(),
}
}

Expand Down Expand Up @@ -574,22 +577,22 @@ mod tests {
decl("struct A { F f1; G f2; }"),
Ok(("", adlast::Decl{
name: "A".to_string(),
version: mk_empty_maybe(),
annotations: mk_empty_annotations(),
version: Maybe::nothing(),
annotations: Map::new(Vec::new()),
r#type: adlast::DeclType::Struct(adlast::Struct{
type_params: Vec::new(),
fields: vec![
adlast::Field{
name: "f1".to_string(),
annotations: mk_empty_annotations(),
default: mk_empty_maybe(),
annotations: Map::new(Vec::new()),
default: Maybe::nothing(),
serialized_name: "f1".to_string(),
type_expr: mk_typeexpr0(mk_scoped_name("", "F")),
},
adlast::Field{
name: "f2".to_string(),
annotations: mk_empty_annotations(),
default: mk_empty_maybe(),
annotations: Map::new(Vec::new()),
default: Maybe::nothing(),
serialized_name: "f2".to_string(),
type_expr: mk_typeexpr0(mk_scoped_name("", "G")),
}
Expand All @@ -606,8 +609,8 @@ mod tests {
decl("@X.Z true @Y \"xyzzy\" struct A {}"),
Ok(("", adlast::Decl{
name: "A".to_string(),
version: mk_empty_maybe(),
annotations: crate::adlrt::custom::sys::types::map::Map::from_iter(vec![
version: Maybe::nothing(),
annotations: Map::from_iter(vec![
(mk_scoped_name("", "Y"), serde_json::Value::String("xyzzy".to_owned())),
(mk_scoped_name("X", "Z"), serde_json::Value::Bool(true)),
]),
Expand All @@ -627,8 +630,8 @@ mod tests {
decl("/// Some doc\n struct A {}"),
Ok(("", adlast::Decl{
name: "A".to_string(),
version: mk_empty_maybe(),
annotations: crate::adlrt::custom::sys::types::map::Map::from_iter(vec![
version: Maybe::nothing(),
annotations: Map::from_iter(vec![
(docstring_scoped_name(), serde_json::Value::from(" Some doc")),
]),
r#type: adlast::DeclType::Struct(adlast::Struct{
Expand All @@ -642,8 +645,8 @@ mod tests {
decl("/// Some doc\n /// with line 2\n struct A {}"),
Ok(("", adlast::Decl{
name: "A".to_string(),
version: mk_empty_maybe(),
annotations: crate::adlrt::custom::sys::types::map::Map::from_iter(vec![
version: Maybe::nothing(),
annotations: Map::from_iter(vec![
(mk_scoped_name("sys.annotations", "Doc"), serde_json::Value::from(" Some doc\n with line 2")),
]),
r#type: adlast::DeclType::Struct(adlast::Struct{
Expand Down Expand Up @@ -722,11 +725,4 @@ mod tests {
fn mk_typeexpr0(type_ref: adlast::ScopedName) -> adlast::TypeExpr<adlast::ScopedName> {
adlast::TypeExpr{type_ref, parameters: vec![]}
}

fn mk_empty_annotations() -> crate::adlrt::custom::sys::types::map::Map<adlast::ScopedName,serde_json::Value> {
crate::adlrt::custom::sys::types::map::Map::new(Vec::new())
}
fn mk_empty_maybe<T>() -> crate::adlrt::custom::sys::types::maybe::Maybe<T> {
crate::adlrt::custom::sys::types::maybe::Maybe::nothing()
}
}

0 comments on commit 0c2fe8e

Please sign in to comment.