forked from syndicate-lang/preserves
Introduce TField::Any and TField::Embedded
This commit is contained in:
parent
87227b5623
commit
6348524542
|
@ -104,7 +104,7 @@ fn store_wrap(is_struct: bool, ty: &TField, expr: &str) -> String {
|
|||
} else {
|
||||
format!("std::boxed::Box::new({})", expr)
|
||||
},
|
||||
TField::Base(_) => format!("{}.clone()", expr),
|
||||
TField::Base(_) | TField::Any | TField::Embedded => format!("{}.clone()", expr),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ fn store_wrap(is_struct: bool, ty: &TField, expr: &str) -> String {
|
|||
} else {
|
||||
format!("std::boxed::Box::new({})", expr)
|
||||
},
|
||||
TField::Base(_) => expr.to_owned(),
|
||||
TField::Base(_) | TField::Any | TField::Embedded => expr.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ pub enum TSimple {
|
|||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
|
||||
pub enum TField {
|
||||
Unit,
|
||||
Any,
|
||||
Embedded,
|
||||
Array(Box<TField>),
|
||||
Set(Box<TField>),
|
||||
Map(Box<TField>, Box<TField>),
|
||||
|
@ -142,7 +144,7 @@ pub fn promote(p: &NamedSimplePattern) -> NamedPattern {
|
|||
|
||||
pub fn field_type(p: &SimplePattern) -> TField {
|
||||
match p {
|
||||
SimplePattern::Any => TField::Base("_Any".to_owned()),
|
||||
SimplePattern::Any => TField::Any,
|
||||
SimplePattern::Atom { atom_kind: k } =>
|
||||
match **k {
|
||||
AtomKind::Boolean => TField::Base("bool".to_owned()),
|
||||
|
@ -153,7 +155,7 @@ pub fn field_type(p: &SimplePattern) -> TField {
|
|||
AtomKind::ByteString => TField::Base("std::vec::Vec<u8>".to_owned()),
|
||||
AtomKind::Symbol => TField::Base("std::string::String".to_owned()),
|
||||
},
|
||||
SimplePattern::Embedded { .. } => TField::Base("_Ptr".to_owned()),
|
||||
SimplePattern::Embedded { .. } => TField::Embedded,
|
||||
SimplePattern::Lit { .. } => TField::Unit,
|
||||
SimplePattern::Seqof { pattern: t } => TField::Array(Box::new(field_type(t))),
|
||||
SimplePattern::Setof { pattern: t } => TField::Set(Box::new(field_type(t))),
|
||||
|
@ -170,6 +172,8 @@ pub fn render_field_type(
|
|||
) -> impl Emittable {
|
||||
match t {
|
||||
TField::Unit => seq!["()"],
|
||||
TField::Any => seq!["_Any"],
|
||||
TField::Embedded => seq!["_Ptr"],
|
||||
TField::Array(t) => seq!["std::vec::Vec<", render_field_type(ctxt, false, t), ">"],
|
||||
TField::Set(t) => seq!["preserves::value::Set<", render_field_type(ctxt, false, t), ">"],
|
||||
TField::Map(k, v) => seq!["preserves::value::Map",
|
||||
|
|
|
@ -476,14 +476,15 @@ fn read_compound_pattern_tuple<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mu
|
|||
_tmp0.shift(Some(_support::B::Item::RecordField));
|
||||
r.boundary(&_tmp0)?;
|
||||
r.open_sequence()?;
|
||||
let mut _tmp3 = _support::B::Type::default();
|
||||
let mut _tmp2 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp3, &_support::B::Item::SequenceValue)? {
|
||||
_tmp3.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp3)?;
|
||||
let _tmp4 = NamedPattern::deserialize(r)?;
|
||||
_tmp2.push(_tmp4);
|
||||
let mut _tmp4 = _support::B::Type::default();
|
||||
let mut _tmp3 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp4, &_support::B::Item::SequenceValue)? {
|
||||
_tmp4.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp4)?;
|
||||
let _tmp5 = NamedPattern::deserialize(r)?;
|
||||
_tmp3.push(_tmp5);
|
||||
}
|
||||
let _tmp2 = _tmp3;
|
||||
r.ensure_complete(_tmp0, &_support::B::Item::RecordField)?;
|
||||
Ok(CompoundPattern::Tuple {patterns: _tmp2})
|
||||
}
|
||||
|
@ -504,19 +505,20 @@ fn read_compound_pattern_tuple_prefix<'de, R: _support::Reader<'de, _Ptr, _Any>>
|
|||
_tmp0.shift(Some(_support::B::Item::RecordField));
|
||||
r.boundary(&_tmp0)?;
|
||||
r.open_sequence()?;
|
||||
let mut _tmp3 = _support::B::Type::default();
|
||||
let mut _tmp2 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp3, &_support::B::Item::SequenceValue)? {
|
||||
_tmp3.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp3)?;
|
||||
let _tmp4 = NamedPattern::deserialize(r)?;
|
||||
_tmp2.push(_tmp4);
|
||||
let mut _tmp4 = _support::B::Type::default();
|
||||
let mut _tmp3 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp4, &_support::B::Item::SequenceValue)? {
|
||||
_tmp4.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp4)?;
|
||||
let _tmp5 = NamedPattern::deserialize(r)?;
|
||||
_tmp3.push(_tmp5);
|
||||
}
|
||||
let _tmp2 = _tmp3;
|
||||
_tmp0.shift(Some(_support::B::Item::RecordField));
|
||||
r.boundary(&_tmp0)?;
|
||||
let _tmp5 = NamedSimplePattern::deserialize(r)?;
|
||||
let _tmp6 = NamedSimplePattern::deserialize(r)?;
|
||||
r.ensure_complete(_tmp0, &_support::B::Item::RecordField)?;
|
||||
Ok(CompoundPattern::TuplePrefix {fixed: _tmp2, variable: std::boxed::Box::new(_tmp5)})
|
||||
Ok(CompoundPattern::TuplePrefix {fixed: _tmp2, variable: std::boxed::Box::new(_tmp6)})
|
||||
}
|
||||
|
||||
fn read_compound_pattern_dict<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
|
@ -667,13 +669,14 @@ fn read_definition_or<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> s
|
|||
_tmp2.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp4 = NamedAlternative::deserialize(r)?;
|
||||
let mut _tmp5 = std::vec::Vec::new();
|
||||
let mut _tmp6 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp2, &_support::B::Item::SequenceValue)? {
|
||||
_tmp2.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp6 = NamedAlternative::deserialize(r)?;
|
||||
_tmp5.push(_tmp6);
|
||||
let _tmp7 = NamedAlternative::deserialize(r)?;
|
||||
_tmp6.push(_tmp7);
|
||||
}
|
||||
let _tmp5 = _tmp6;
|
||||
r.ensure_complete(_tmp0, &_support::B::Item::RecordField)?;
|
||||
Ok(Definition::Or {
|
||||
pattern_0: std::boxed::Box::new(_tmp3),
|
||||
|
@ -705,13 +708,14 @@ fn read_definition_and<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) ->
|
|||
_tmp2.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp4 = NamedPattern::deserialize(r)?;
|
||||
let mut _tmp5 = std::vec::Vec::new();
|
||||
let mut _tmp6 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp2, &_support::B::Item::SequenceValue)? {
|
||||
_tmp2.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp6 = NamedPattern::deserialize(r)?;
|
||||
_tmp5.push(_tmp6);
|
||||
let _tmp7 = NamedPattern::deserialize(r)?;
|
||||
_tmp6.push(_tmp7);
|
||||
}
|
||||
let _tmp5 = _tmp6;
|
||||
r.ensure_complete(_tmp0, &_support::B::Item::RecordField)?;
|
||||
Ok(Definition::And {
|
||||
pattern_0: std::boxed::Box::new(_tmp3),
|
||||
|
@ -823,17 +827,18 @@ impl std::convert::From<&Definition> for _Any {
|
|||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Definitions {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_dictionary()?;
|
||||
let mut _tmp1 = _support::B::Type::default();
|
||||
let mut _tmp0 = preserves::value::Map::new();
|
||||
while !r.close_compound(&mut _tmp1, &_support::B::Item::DictionaryKey)? {
|
||||
_tmp1.shift(Some(_support::B::Item::DictionaryKey));
|
||||
r.boundary(&_tmp1)?;
|
||||
let _tmp2 = r.next_symbol()?.into_owned();
|
||||
_tmp1.shift(Some(_support::B::Item::DictionaryValue));
|
||||
r.boundary(&_tmp1)?;
|
||||
let _tmp3 = Definition::deserialize(r)?;
|
||||
_tmp0.insert(_tmp2, _tmp3);
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
let mut _tmp1 = preserves::value::Map::new();
|
||||
while !r.close_compound(&mut _tmp2, &_support::B::Item::DictionaryKey)? {
|
||||
_tmp2.shift(Some(_support::B::Item::DictionaryKey));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp3 = r.next_symbol()?.into_owned();
|
||||
_tmp2.shift(Some(_support::B::Item::DictionaryValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp4 = Definition::deserialize(r)?;
|
||||
_tmp1.insert(_tmp3, _tmp4);
|
||||
}
|
||||
let _tmp0 = _tmp1;
|
||||
Ok(Definitions(_tmp0))
|
||||
}
|
||||
}
|
||||
|
@ -861,17 +866,18 @@ impl std::convert::From<&Definitions> for _Any {
|
|||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for DictionaryEntries {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_dictionary()?;
|
||||
let mut _tmp1 = _support::B::Type::default();
|
||||
let mut _tmp0 = preserves::value::Map::new();
|
||||
while !r.close_compound(&mut _tmp1, &_support::B::Item::DictionaryKey)? {
|
||||
_tmp1.shift(Some(_support::B::Item::DictionaryKey));
|
||||
r.boundary(&_tmp1)?;
|
||||
let _tmp2 = r.demand_next(true)?;
|
||||
_tmp1.shift(Some(_support::B::Item::DictionaryValue));
|
||||
r.boundary(&_tmp1)?;
|
||||
let _tmp3 = NamedSimplePattern::deserialize(r)?;
|
||||
_tmp0.insert(_tmp2, _tmp3);
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
let mut _tmp1 = preserves::value::Map::new();
|
||||
while !r.close_compound(&mut _tmp2, &_support::B::Item::DictionaryKey)? {
|
||||
_tmp2.shift(Some(_support::B::Item::DictionaryKey));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp3 = r.demand_next(true)?;
|
||||
_tmp2.shift(Some(_support::B::Item::DictionaryValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp4 = NamedSimplePattern::deserialize(r)?;
|
||||
_tmp1.insert(_tmp3, _tmp4);
|
||||
}
|
||||
let _tmp0 = _tmp1;
|
||||
Ok(DictionaryEntries(_tmp0))
|
||||
}
|
||||
}
|
||||
|
@ -954,14 +960,15 @@ impl std::convert::From<&EmbeddedTypeName> for _Any {
|
|||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for ModulePath {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_sequence()?;
|
||||
let mut _tmp1 = _support::B::Type::default();
|
||||
let mut _tmp0 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp1, &_support::B::Item::SequenceValue)? {
|
||||
_tmp1.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp1)?;
|
||||
let _tmp2 = r.next_symbol()?.into_owned();
|
||||
_tmp0.push(_tmp2);
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
let mut _tmp1 = std::vec::Vec::new();
|
||||
while !r.close_compound(&mut _tmp2, &_support::B::Item::SequenceValue)? {
|
||||
_tmp2.shift(Some(_support::B::Item::SequenceValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp3 = r.next_symbol()?.into_owned();
|
||||
_tmp1.push(_tmp3);
|
||||
}
|
||||
let _tmp0 = _tmp1;
|
||||
Ok(ModulePath(_tmp0))
|
||||
}
|
||||
}
|
||||
|
@ -990,17 +997,18 @@ impl std::convert::From<&ModulePath> for _Any {
|
|||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Modules {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_dictionary()?;
|
||||
let mut _tmp1 = _support::B::Type::default();
|
||||
let mut _tmp0 = preserves::value::Map::new();
|
||||
while !r.close_compound(&mut _tmp1, &_support::B::Item::DictionaryKey)? {
|
||||
_tmp1.shift(Some(_support::B::Item::DictionaryKey));
|
||||
r.boundary(&_tmp1)?;
|
||||
let _tmp2 = ModulePath::deserialize(r)?;
|
||||
_tmp1.shift(Some(_support::B::Item::DictionaryValue));
|
||||
r.boundary(&_tmp1)?;
|
||||
let _tmp3 = Schema::deserialize(r)?;
|
||||
_tmp0.insert(_tmp2, _tmp3);
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
let mut _tmp1 = preserves::value::Map::new();
|
||||
while !r.close_compound(&mut _tmp2, &_support::B::Item::DictionaryKey)? {
|
||||
_tmp2.shift(Some(_support::B::Item::DictionaryKey));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp3 = ModulePath::deserialize(r)?;
|
||||
_tmp2.shift(Some(_support::B::Item::DictionaryValue));
|
||||
r.boundary(&_tmp2)?;
|
||||
let _tmp4 = Schema::deserialize(r)?;
|
||||
_tmp1.insert(_tmp3, _tmp4);
|
||||
}
|
||||
let _tmp0 = _tmp1;
|
||||
Ok(Modules(_tmp0))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue