Some AstAttributes I wrote

View: New views
3 Messages — Rating Filter:   Alert me  

Some AstAttributes I wrote

by gregcnagel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Over the last week I wrote a couple attributes for my pet project
which I thought might be generally useful. If you find them
interesting, I can polish them up a bit and fully test them so you can
add them to Boo.Lang.Useful, but I was just checking to see if anyone
had advice to make them better. Note that only ComparableAttribute and
EqualityAttribute are extensively tested, and those aren't thoroughly
checked for misapplication.

http://code.google.com/p/grawlix/source/browse/trunk/Grawlix/Squean

EqualityAttribute generates .Equals, implements IEquatable, and
overloads the == and != operators when applied to a member function
that takes one parameter. The type of the parameter is the type to
compare against. The useful part is it takes care of any special null
handling and casting.

ComparisonAttribute implements both forms of IComparable, and the
other four comparison operators when given a function which takes one
parameter and returns a number.

EqualityAttribute and ComparisonAttribute can only be applied in a
struct or final class, as there's no good way to define .Equals when
the class can be overidden.

DuplicateAttribute is a simple attribute that duplicates any member
it's applied to. It avoids duplicating code on methods and properties
and has an option for methods where you can substitute self for the
first parameter. (I made this attribute for operators, so that I could
do something like alias op_Subtraction as Subtract and be CLS
compliant.)

ExceptionConstructorsAttribute is a really simple attribute that just
spawns the default constructors when applied to an exception  class
definition. Made this when I ran into errors for not including a
serialization constructor.

And the LogMacro is a simplification of log4net. A statement like
this: log Debug, "Bug detected." will find the enclosing type of its
method and define a static log named after its type. If you omit the
[Debug, Info, Warn, Error, Fatal] it'll default to Info. You can also
apply LogAttribute to a static field or property and declare it as the
log to use. You still have to initialize log4net manually.

DisposableAttribute is there so I can use it until it makes its way
into Boo.Lang.Useful.

So I don't know how interesting you find this, but I'm new to
AstAttributes and would appreciate any input you could give me.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Some AstAttributes I wrote

by rektide-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> So I don't know how interesting you find this, but I'm new to
> AstAttributes and would appreciate any input you could give me.

I find them really interesting, mainly because I dont know much about
the AST pipeline.  Its great to see some very fine examples used for
modifying rather than just compiling code.

Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Some AstAttributes I wrote

by Marcus Griep-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think this is wonderful in general.  I think that there should be a
"sub-project" set up to build on these that is officially supported by
the Boo group, something like the Boo Code Extensibility Library :
BooCEL (or other appropriate name).  I know that Bamboo had set up
boo-extensions over at google code, but I think that having a library of
AST attributes, macros, and steps that can be used will be very
beneficial.  It may be just taking Boo.Lang.Useful and moving it to
become a maintained project.  The more ingrained language extensions
should probably remain in Boo.Lang.Extensions because of their ubiquity.

What do others think?

By the way, in specific, I think the extensions are very nice.  They
embody what Boo's extensibility is good at: taking care of cross-cutting
concerns once so that you don't have to do it yourself every time.

Marcus

hangar wrote:

> Over the last week I wrote a couple attributes for my pet project
> which I thought might be generally useful. If you find them
> interesting, I can polish them up a bit and fully test them so you can
> add them to Boo.Lang.Useful, but I was just checking to see if anyone
> had advice to make them better. Note that only ComparableAttribute and
> EqualityAttribute are extensively tested, and those aren't thoroughly
> checked for misapplication.
>
> http://code.google.com/p/grawlix/source/browse/trunk/Grawlix/Squean
>
> EqualityAttribute generates .Equals, implements IEquatable, and
> overloads the == and != operators when applied to a member function
> that takes one parameter. The type of the parameter is the type to
> compare against. The useful part is it takes care of any special null
> handling and casting.
>
> ComparisonAttribute implements both forms of IComparable, and the
> other four comparison operators when given a function which takes one
> parameter and returns a number.
>
> EqualityAttribute and ComparisonAttribute can only be applied in a
> struct or final class, as there's no good way to define .Equals when
> the class can be overidden.
>
> DuplicateAttribute is a simple attribute that duplicates any member
> it's applied to. It avoids duplicating code on methods and properties
> and has an option for methods where you can substitute self for the
> first parameter. (I made this attribute for operators, so that I could
> do something like alias op_Subtraction as Subtract and be CLS
> compliant.)
>
> ExceptionConstructorsAttribute is a really simple attribute that just
> spawns the default constructors when applied to an exception  class
> definition. Made this when I ran into errors for not including a
> serialization constructor.
>
> And the LogMacro is a simplification of log4net. A statement like
> this: log Debug, "Bug detected." will find the enclosing type of its
> method and define a static log named after its type. If you omit the
> [Debug, Info, Warn, Error, Fatal] it'll default to Info. You can also
> apply LogAttribute to a static field or property and declare it as the
> log to use. You still have to initialize log4net manually.
>
> DisposableAttribute is there so I can use it until it makes its way
> into Boo.Lang.Useful.
>
> So I don't know how interesting you find this, but I'm new to
> AstAttributes and would appreciate any input you could give me.
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
> To post to this group, send email to boolang@...
> To unsubscribe from this group, send email to boolang-unsubscribe@...
> For more options, visit this group at http://groups.google.com/group/boolang
> -~----------~----~----~----~------~----~------~--~---
>
>  
--
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´




signature.asc (809 bytes) Download Attachment