mirror of https://github.com/tildeio/helix
[BREAKING] Allow arbitrary attributes for classes
We no longer automatically derive Clone and Debug on the structs. Fixes #143
This commit is contained in:
parent
a8e1f37362
commit
750be7995d
|
@ -4,6 +4,7 @@
|
|||
extern crate helix;
|
||||
|
||||
ruby! {
|
||||
#[derive(Debug)]
|
||||
class Console {
|
||||
def log(&self, string: String) {
|
||||
println!("{}", string);
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
extern crate helix;
|
||||
|
||||
ruby! {
|
||||
#[doc(hidden)]
|
||||
#[ruby_name="AttributesTest"]
|
||||
#[no_mangle]
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg(not(foo="bar"))]
|
||||
class Attributes {
|
||||
#[doc(hidden)]
|
||||
#[ruby_name="foo"]
|
||||
|
|
|
@ -4,6 +4,7 @@ macro_rules! codegen_allocator {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: $meta:tt,
|
||||
struct: (),
|
||||
methods: $methods:tt
|
||||
|
@ -13,6 +14,7 @@ macro_rules! codegen_allocator {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: false },
|
||||
struct: $struct:tt,
|
||||
methods: [ $($method:tt)* ]
|
||||
|
|
|
@ -31,6 +31,7 @@ macro_rules! codegen {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: $reopen:tt },
|
||||
struct: $struct:tt,
|
||||
methods: [ $($method:tt)* ]
|
||||
|
@ -45,7 +46,7 @@ macro_rules! codegen {
|
|||
{
|
||||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
struct: { codegen_struct! { pub: $pub, rust_name: $rust_name, ruby_name: $ruby_name, struct: $struct } },
|
||||
struct: { codegen_struct! { pub: $pub, rust_name: $rust_name, ruby_name: $ruby_name, attributes: $attributes, struct: $struct } },
|
||||
methods: [ $( codegen_method! { $method } )* ]
|
||||
}
|
||||
],
|
||||
|
@ -56,6 +57,7 @@ macro_rules! codegen {
|
|||
type: class,
|
||||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
attributes: $attributes,
|
||||
meta: { pub: $pub, reopen: $reopen },
|
||||
struct: $struct,
|
||||
methods: [ $($method)* ]
|
||||
|
@ -90,6 +92,7 @@ macro_rules! codegen_pub_classes {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: $reopen:tt },
|
||||
struct: $struct:tt,
|
||||
methods: [ $($method:tt)* ]
|
||||
|
@ -124,30 +127,31 @@ macro_rules! codegen_pub_classes {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! codegen_struct {
|
||||
{ pub: false, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, struct: () } => {
|
||||
codegen_struct! { pub: {}, rust_name: $rust_name, ruby_name: $ruby_name, struct: {} }
|
||||
{ pub: false, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, attributes: $attributes:tt, struct: () } => {
|
||||
codegen_struct! { pub: {}, rust_name: $rust_name, ruby_name: $ruby_name, attributes: $attributes, struct: {} }
|
||||
};
|
||||
|
||||
{ pub: true, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, struct: () } => {
|
||||
codegen_struct! { pub: { pub }, rust_name: $rust_name, ruby_name: $ruby_name, struct: {} }
|
||||
{ pub: true, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, attributes: $attributes:tt, struct: () } => {
|
||||
codegen_struct! { pub: { pub }, rust_name: $rust_name, ruby_name: $ruby_name, attributes: $attributes, struct: {} }
|
||||
};
|
||||
|
||||
{ pub: false, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, struct: { $($rest:tt)* } } => {
|
||||
codegen_struct! { pub: {}, rust_name: $rust_name, ruby_name: $ruby_name, struct: { $($rest)* } }
|
||||
{ pub: false, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, attributes: $attributes:tt, struct: { $($rest:tt)* } } => {
|
||||
codegen_struct! { pub: {}, rust_name: $rust_name, ruby_name: $ruby_name, attributes: $attributes, struct: { $($rest)* } }
|
||||
};
|
||||
|
||||
{ pub: true, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, struct: { $($rest:tt)* } } => {
|
||||
codegen_struct! { pub: { pub }, rust_name: $rust_name, ruby_name: $ruby_name, struct: { $($rest)* } }
|
||||
{ pub: true, rust_name: $rust_name:tt, ruby_name: $ruby_name:tt, attributes: $attributes:tt, struct: { $($rest:tt)* } } => {
|
||||
codegen_struct! { pub: { pub }, rust_name: $rust_name, ruby_name: $ruby_name, attributes: $attributes, struct: { $($rest)* } }
|
||||
};
|
||||
|
||||
{
|
||||
pub: { $($pub:tt)* },
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: { $($attributes:tt)* },
|
||||
struct: { $($struct:tt)* }
|
||||
} => {
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
$($attributes)*
|
||||
$($pub)* struct $rust_name {
|
||||
helix: $crate::Metadata,
|
||||
$($struct)*
|
||||
|
|
|
@ -4,6 +4,7 @@ macro_rules! codegen_coercions {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: $reopen:tt },
|
||||
struct: (),
|
||||
methods: $methods:tt
|
||||
|
@ -36,6 +37,7 @@ macro_rules! codegen_coercions {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: false },
|
||||
struct: $struct:tt,
|
||||
methods: $methods:tt
|
||||
|
|
|
@ -9,11 +9,12 @@ macro_rules! print_ast {
|
|||
({
|
||||
type: class,
|
||||
name: $name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: $reopen:tt },
|
||||
struct: $struct:tt,
|
||||
methods: $methods:tt
|
||||
}) => {
|
||||
println!("\nCLASS\n=====\nclass {} (pub:{} reopen:{})", stringify!($name), stringify!($pub), stringify!($reopen));
|
||||
println!("\nCLASS\n=====\nclass {} (pub:{} reopen:{}, attributes: {})", stringify!($name), stringify!($pub), stringify!($reopen), stringify!($attributes));
|
||||
println!("{}", format_ast_class_struct!({ name: $name, tuple: $struct }));
|
||||
println!("\nMETHODS\n=======\n{}\n\n", format_ast_methods!($methods));
|
||||
};
|
||||
|
|
|
@ -19,6 +19,7 @@ macro_rules! codegen_class_binding {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: false },
|
||||
struct: (),
|
||||
methods: [ $($method:tt)* ]
|
||||
|
@ -37,6 +38,7 @@ macro_rules! codegen_class_binding {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: true },
|
||||
struct: (),
|
||||
methods: [ $($method:tt)* ]
|
||||
|
@ -55,6 +57,7 @@ macro_rules! codegen_class_binding {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: $reopen:tt },
|
||||
struct: { $($struct:tt)* },
|
||||
methods: [ $($method:tt)* ]
|
||||
|
@ -136,6 +139,7 @@ macro_rules! codegen_define_method {
|
|||
type: class,
|
||||
rust_name: $cls_rust_name:tt,
|
||||
ruby_name: $cls_ruby_name:tt,
|
||||
attributes: $cls_attributes:tt,
|
||||
meta: $meta:tt,
|
||||
struct: $struct:tt,
|
||||
$($rest:tt)*
|
||||
|
@ -144,7 +148,7 @@ macro_rules! codegen_define_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
attributes: $metohd_attributes:tt,
|
||||
self: { ownership: { $($ownership:tt)* }, name: $self:tt },
|
||||
args: [ $($arg:tt : $argty:ty),* ],
|
||||
ret: { $($ret:tt)* },
|
||||
|
@ -221,6 +225,7 @@ macro_rules! codegen_define_method {
|
|||
type: class,
|
||||
rust_name: $cls_rust_name:tt,
|
||||
ruby_name: $cls_ruby_name:tt,
|
||||
attributes: $cls_attributes:tt,
|
||||
meta: $meta:tt,
|
||||
struct: $struct:tt,
|
||||
$($rest:tt)*
|
||||
|
@ -229,7 +234,7 @@ macro_rules! codegen_define_method {
|
|||
rust_name: $rust_name:tt,
|
||||
ruby_name: { $($ruby_name:tt)* },
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
attributes: $methohd_attributes:tt,
|
||||
self: { ownership: {}, name: $self:tt },
|
||||
args: [ $($arg:tt : $argty:ty),* ],
|
||||
ret: { $($ret:tt)* },
|
||||
|
|
|
@ -87,10 +87,11 @@ macro_rules! parse {
|
|||
stack: { $($stack: tt)* }
|
||||
} => {
|
||||
parse! {
|
||||
state: parse_class,
|
||||
state: parse_class_attributes,
|
||||
buffer: $buffer,
|
||||
stack: {
|
||||
ruby_name: uninitialized,
|
||||
attributes: {},
|
||||
pub: false,
|
||||
reopen: false,
|
||||
$($stack)*
|
||||
|
@ -98,35 +99,66 @@ macro_rules! parse {
|
|||
}
|
||||
};
|
||||
|
||||
// STATE: parse_class_attributes
|
||||
|
||||
{
|
||||
state: parse_class_attributes,
|
||||
buffer: { #[ruby_name = $ruby_name:tt] $($rest:tt)* },
|
||||
stack: {
|
||||
ruby_name: uninitialized,
|
||||
$($stack:tt)*
|
||||
}
|
||||
} => {
|
||||
parse! {
|
||||
state: parse_class_attributes,
|
||||
buffer: { $($rest)* },
|
||||
stack: {
|
||||
ruby_name: { $ruby_name },
|
||||
$($stack)*
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
state: parse_class_attributes,
|
||||
buffer: { #[$($attribute:tt)*] $($rest:tt)* },
|
||||
stack: {
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: { $($attributes:tt)* },
|
||||
$($stack:tt)*
|
||||
}
|
||||
} => {
|
||||
parse! {
|
||||
state: parse_class_attributes,
|
||||
buffer: { $($rest)* },
|
||||
stack: {
|
||||
ruby_name: $ruby_name,
|
||||
attributes: { $($attributes)* #[$($attribute)*] },
|
||||
$($stack)*
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
state: parse_class_attributes,
|
||||
buffer: $buffer:tt,
|
||||
stack: $stack:tt
|
||||
} => {
|
||||
parse! {
|
||||
state: parse_class,
|
||||
buffer: $buffer,
|
||||
stack: $stack
|
||||
}
|
||||
};
|
||||
|
||||
// STATE: parse_class
|
||||
|
||||
{
|
||||
state: parse_class,
|
||||
buffer: { #[ruby_name = $ruby_name:tt] $($rest:tt)* },
|
||||
stack: {
|
||||
ruby_name: uninitialized,
|
||||
pub: false,
|
||||
reopen: false,
|
||||
$($stack:tt)*
|
||||
}
|
||||
} => {
|
||||
parse! {
|
||||
state: parse_class,
|
||||
buffer: { $($rest)* },
|
||||
stack: {
|
||||
ruby_name: { $ruby_name },
|
||||
pub: false,
|
||||
reopen: false,
|
||||
$($stack)*
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
state: parse_class,
|
||||
buffer: { pub $($rest:tt)* },
|
||||
stack: {
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
pub: false,
|
||||
reopen: false,
|
||||
$($stack:tt)*
|
||||
|
@ -137,6 +169,7 @@ macro_rules! parse {
|
|||
buffer: { $($rest)* },
|
||||
stack: {
|
||||
ruby_name: $ruby_name,
|
||||
attributes: $attributes,
|
||||
pub: true,
|
||||
reopen: false,
|
||||
$($stack)*
|
||||
|
@ -149,6 +182,7 @@ macro_rules! parse {
|
|||
buffer: { reopen $($rest:tt)* },
|
||||
stack: {
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
pub: $pub:tt,
|
||||
reopen: false,
|
||||
$($stack:tt)*
|
||||
|
@ -159,6 +193,7 @@ macro_rules! parse {
|
|||
buffer: { $($rest)* },
|
||||
stack: {
|
||||
ruby_name: $ruby_name,
|
||||
attributes: $attributes,
|
||||
pub: $pub,
|
||||
reopen: true,
|
||||
$($stack)*
|
||||
|
@ -189,6 +224,7 @@ macro_rules! parse {
|
|||
buffer: { class $name:tt { $($body:tt)* } $($rest:tt)* },
|
||||
stack: {
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
pub: $pub:tt,
|
||||
reopen: $reopen:tt,
|
||||
|
||||
|
@ -203,6 +239,7 @@ macro_rules! parse {
|
|||
type: class,
|
||||
rust_name: $name,
|
||||
ruby_name: $ruby_name,
|
||||
attributes: $attributes,
|
||||
meta: { pub: $pub, reopen: $reopen },
|
||||
struct: (),
|
||||
methods: []
|
||||
|
@ -223,6 +260,7 @@ macro_rules! parse {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: $reopen:tt },
|
||||
struct: (),
|
||||
methods: []
|
||||
|
@ -240,6 +278,7 @@ macro_rules! parse {
|
|||
type: class,
|
||||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
attributes: $attributes,
|
||||
meta: { pub: $pub, reopen: $reopen },
|
||||
struct: { $($struct)* },
|
||||
methods: []
|
||||
|
@ -857,7 +896,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_method_name:tt,
|
||||
ruby_name: $ruby_method_name:tt,
|
||||
ruby_visibility: $ruby_visibility:tt,
|
||||
attributes: $attributes:tt,
|
||||
attributes: $metod_attributes:tt,
|
||||
self: $self:tt,
|
||||
args: $args:tt,
|
||||
ret: uninitialized,
|
||||
|
@ -867,6 +906,7 @@ macro_rules! parse {
|
|||
type: class,
|
||||
rust_name: $rust_class_name:ident,
|
||||
ruby_name: $ruby_class_name:tt,
|
||||
attributes: $class_attributes:tt,
|
||||
meta: $meta:tt,
|
||||
struct: $struct:tt,
|
||||
methods: $methods:tt
|
||||
|
@ -883,7 +923,7 @@ macro_rules! parse {
|
|||
rust_name: $rust_method_name,
|
||||
ruby_name: $ruby_method_name,
|
||||
ruby_visibility: $ruby_visibility,
|
||||
attributes: $attributes,
|
||||
attributes: $metod_attributes,
|
||||
self: $self,
|
||||
args: $args,
|
||||
ret: { $rust_class_name },
|
||||
|
@ -893,6 +933,7 @@ macro_rules! parse {
|
|||
type: class,
|
||||
rust_name: $rust_class_name,
|
||||
ruby_name: $ruby_class_name,
|
||||
attributes: $class_attributes,
|
||||
meta: $meta,
|
||||
struct: $struct,
|
||||
methods: $methods
|
||||
|
@ -951,6 +992,7 @@ macro_rules! parse {
|
|||
type: class,
|
||||
rust_name: $rust_name:ident,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: $meta:tt,
|
||||
struct: $struct:tt,
|
||||
methods: [ $($methods:tt)* ]
|
||||
|
@ -966,6 +1008,7 @@ macro_rules! parse {
|
|||
type: class,
|
||||
rust_name: $rust_name,
|
||||
ruby_name: $ruby_name,
|
||||
attributes: $attributes,
|
||||
meta: $meta,
|
||||
struct: $struct,
|
||||
methods: [ $($methods)* $method ]
|
||||
|
@ -1025,6 +1068,7 @@ macro_rules! assert_not_reopen {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: { pub: $pub:tt, reopen: $reopen:tt },
|
||||
struct: $struct:tt,
|
||||
methods: $methods:tt
|
||||
|
@ -1044,6 +1088,7 @@ macro_rules! assert_has_initialize {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: $meta:tt,
|
||||
struct: $struct:tt,
|
||||
methods: $methods:tt
|
||||
|
@ -1067,6 +1112,7 @@ macro_rules! assert_has_struct {
|
|||
type: class,
|
||||
rust_name: $rust_name:tt,
|
||||
ruby_name: $ruby_name:tt,
|
||||
attributes: $attributes:tt,
|
||||
meta: $meta:tt,
|
||||
struct: $struct:tt,
|
||||
methods: $methods:tt
|
||||
|
|
Loading…
Reference in New Issue