Add named types
This commit is contained in:
parent
d076a329d2
commit
65ee161a96
@ -22,6 +22,7 @@ pub enum Type {
|
||||
ListOf(Box<Type>),
|
||||
ListExact(Vec<Type>),
|
||||
Map,
|
||||
Named(Identifier),
|
||||
None,
|
||||
Range,
|
||||
String,
|
||||
@ -140,6 +141,7 @@ impl Display for Type {
|
||||
write!(f, ") : {return_type}")
|
||||
}
|
||||
Type::Structure { .. } => todo!(),
|
||||
Type::Named(name) => write!(f, "{name}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ pub fn parser<'src>() -> impl Parser<
|
||||
just(Token::Keyword("range")).to(Type::Range),
|
||||
just(Token::Keyword("str")).to(Type::String),
|
||||
just(Token::Keyword("list")).to(Type::List),
|
||||
identifier.clone().map(|name| Type::Named(name)),
|
||||
))
|
||||
})
|
||||
.map_with(|r#type, state| r#type.with_position(state.span()));
|
||||
|
@ -39,7 +39,7 @@ fn nested_structure() {
|
||||
}
|
||||
|
||||
Foo {
|
||||
bar = Baz {
|
||||
bar = Bar {
|
||||
baz = 42
|
||||
}
|
||||
}
|
||||
@ -47,10 +47,13 @@ fn nested_structure() {
|
||||
),
|
||||
Ok(Some(Value::structure(
|
||||
Identifier::new("Foo"),
|
||||
vec![
|
||||
(Identifier::new("bar"), Value::integer(42)),
|
||||
(Identifier::new("baz"), Value::string("hiya".to_string())),
|
||||
]
|
||||
vec![(
|
||||
Identifier::new("bar"),
|
||||
Value::structure(
|
||||
Identifier::new("Bar"),
|
||||
vec![(Identifier::new("baz"), Value::integer(42))]
|
||||
)
|
||||
),]
|
||||
)))
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user