pest Self type added

This commit is contained in:
collin 2020-05-14 13:41:32 -07:00
parent 44b4df2404
commit b984c46a51
4 changed files with 14 additions and 6 deletions

View File

@ -1,15 +1,15 @@
circuit PedersenHash {
parameters: group[1]
function new(b: u32) -> u32 {
return b
static function new(parameters: group[1]) -> Self {
return Self { parameters: parameters }
}
}
function main() -> u32{
let parameters = [0group; 1];
let mut pedersen = PedersenHash { parameters: parameters };
let b = PedersenHash::new(3);
let pedersen = PedersenHash::new(parameters);
return b
return pedersen
}

View File

@ -198,6 +198,10 @@ pub struct CircuitType<'ast> {
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_self))]
pub struct SelfType {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_basic))]
pub enum BasicType<'ast> {
@ -222,6 +226,7 @@ pub enum Type<'ast> {
Basic(BasicType<'ast>),
Array(ArrayType<'ast>),
Circuit(CircuitType<'ast>),
SelfType(SelfType),
}
impl<'ast> fmt::Display for Type<'ast> {
@ -230,6 +235,7 @@ impl<'ast> fmt::Display for Type<'ast> {
Type::Basic(ref _type) => write!(f, "basic"),
Type::Array(ref _type) => write!(f, "array"),
Type::Circuit(ref _type) => write!(f, "struct"),
Type::SelfType(ref _type) => write!(f, "Self"),
}
}
}

View File

@ -79,10 +79,11 @@ type_integer = {
type_field = {"field"}
type_group = {"group"}
type_bool = {"bool"}
type_self = {"Self"}
type_basic = { type_field | type_group | type_bool | type_integer }
type_circuit = { identifier }
type_array = {type_basic ~ ("[" ~ value ~ "]")+ }
_type = {type_array | type_basic | type_circuit}
_type = {type_self | type_array | type_basic | type_circuit}
type_list = _{(_type ~ ("," ~ _type)*)?}
/// Values

View File

@ -694,6 +694,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::Type<'ast>> for types::Typ
ast::Type::Basic(_type) => types::Type::from(_type),
ast::Type::Array(_type) => types::Type::from(_type),
ast::Type::Circuit(_type) => types::Type::from(_type),
ast::Type::SelfType(_type) => unimplemented!("no Self yet")
}
}
}