New syntax to define interfaces; start parsing it

parent 32b8e85f
......@@ -125,6 +125,8 @@ gnome_class! {
}
}
// FIXME: we need syntax to define new GTypeInterfaces
interface Blah: RequiredClass + RequiredIface + RequiredIface {
virtual fn blah(&self, ...);
}
}
```
......@@ -28,6 +28,7 @@ impl Program {
pub enum Item {
Class(Class),
Impl(Impl),
Interface(Interface),
}
pub fn get_program_classes<'a>(program: &'a Program) -> Vec<&'a Class> {
......@@ -58,6 +59,12 @@ pub struct Impl {
pub items: Vec<ImplItem>,
}
pub struct Interface {
pub name: Ident,
// FIXME: required class and interfaces
pub items: Vec<ImplItem>,
}
pub struct ImplItem {
pub attrs: Vec<Attribute>,
pub node: ImplItemKind,
......
......@@ -31,6 +31,8 @@ impl Synom for ast::Item {
syn!(ast::Class) => { |x| ast::Item::Class(x) }
|
syn!(ast::Impl) => { |x| ast::Item::Impl(x) }
|
syn!(ast::Interface) => { |x| ast::Item::Interface(x) }
));
fn description() -> Option<&'static str> {
......@@ -69,6 +71,22 @@ impl Synom for ast::Class {
}
}
impl Synom for ast::Interface {
named!(parse -> Self, do_parse!(
call!(keyword("interface")) >>
name: syn!(Ident) >>
items_and_braces: braces!(many0!(syn!(ast::ImplItem))) >>
(ast::Interface {
name: name,
items: items_and_braces.1,
})
));
fn description() -> Option<&'static str> {
Some("interface item")
}
}
impl Synom for ast::Impl {
named!(parse -> Self, do_parse!(
keyword!(impl) >>
......@@ -277,6 +295,7 @@ pub mod tests {
parses_impl_item_with_trait();
parses_class_with_private_field();
parses_impl_interface();
parses_interface();
}
fn assert_tokens_equal<T: ToTokens>(x: &T, s: &str) {
......@@ -359,4 +378,11 @@ pub mod tests {
fn parses_impl_interface() {
test_parsing_impl_item("impl interface Foo for Bar {}", Some("Foo"), "Bar", true);
}
fn parses_interface() {
let raw = "interface Foo { virtual fn bar(&self); }";
let iface = parse_str::<ast::Interface>(raw).unwrap();
assert_eq!(iface.name.as_ref(), "Foo");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment