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