[svn] r7480: nemerle/trunk/ncc: parsing/MainParser.n
testsuite/positive/macrolib.n testsuite/positive/synt...
Luntain
svnadmin at nemerle.org
Sat Feb 24 14:53:06 CET 2007
Log:
enhance custom members feature with handing modifiers and attributes
Author: Luntain
Date: Sat Feb 24 14:53:05 2007
New Revision: 7480
Modified:
nemerle/trunk/ncc/parsing/MainParser.n
nemerle/trunk/ncc/testsuite/positive/macrolib.n
nemerle/trunk/ncc/testsuite/positive/syntax_extension_custom_members.n
Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n (original)
+++ nemerle/trunk/ncc/parsing/MainParser.n Sat Feb 24 14:53:05 2007
@@ -762,7 +762,11 @@
| Token.LooseGroup (toks) =>
push_stream (toks);
mutable customs = get_customs ();
+
+ def first_modifier = peek_token();
def mods = Modifiers (get_modifiers (), []);
+ def first_no_modifier = peek_token();
+ def last_modifier = last_tok;
mutable parsed_custom_member = false;
when (class_modifiers != null) {
@@ -770,10 +774,25 @@
parse_top_extensions (collect_type_macro_inv, MacroTargets.Class);
if (!collect_type_macro_inv.IsEmpty && stream == null) {
// End of the current "member" loose group; there is nothing left
- // to be parsed as a regular member, so we threat it as a macro invocation with special syntax.
+ // to be parsed as a regular member, so we treat it as a macro invocation with special syntax.
parsed_custom_member = true;
foreach (type_macro_attr in collect_type_macro_inv.GetCustomAttributes()) {
- class_modifiers.AddCustomAttribute(type_macro_attr)
+ match (type_macro_attr) {
+ | PExpr.MacroCall(name,name_space,parms) =>
+ def modifiers_group = Token.LooseGroup(if (!first_no_modifier.Equals(first_modifier)) {
+ last_modifier.Next = null;
+ first_modifier
+ } else {
+ null });
+ def custom_attrs_group = Token.LooseGroup(if (customs.Length>0) {
+ customs.Last.Next = null;
+ customs.Head
+ } else
+ null);
+ def new_parms = parms+[SyntaxElement.RawToken(modifiers_group),SyntaxElement.RawToken(custom_attrs_group)];
+ class_modifiers.AddCustomAttribute(PExpr.MacroCall(name,name_space,new_parms))
+ | _ => ()
+ }
}
}
else {
Modified: nemerle/trunk/ncc/testsuite/positive/macrolib.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/macrolib.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/macrolib.n Sat Feb 24 14:53:05 2007
@@ -449,21 +449,15 @@
// for syntax_extension_custom_members.n
[Nemerle.MacroUsage(Nemerle.MacroPhase.BeforeInheritance, Nemerle.MacroTargets.Class)]
-macro abrakadabra( type_builder: TypeBuilder, _loose_group: Token)
-syntax("abrakadabra", _loose_group) {
-
- def field_for_instance = <[ decl: static mutable field_for_instance: $(type_builder.ParsedName: name); ]>;
- type_builder.Define(field_for_instance);
-
- def lazy_accessor = <[
+macro abrakadabra( type_builder: TypeBuilder,name: Token, _body:Token, modifiers: Token, custom_attributes: Token)
+syntax("abrakadabra","(",name,")",_body) {
+ def prop = <[
decl:
- public static $("Instance": dyn): $( type_builder.ParsedName: name) {
+ public static $(name.ToString().Trim(): dyn): string {
get {
- when (field_for_instance == null)
- field_for_instance = $(type_builder.ParsedName: name)();
- field_for_instance
+ $(modifiers.ToString(): string)+ $(custom_attributes.ToString(): string)
}
}
]>;
- type_builder.Define(lazy_accessor);
+ type_builder.Define(prop);
}
Modified: nemerle/trunk/ncc/testsuite/positive/syntax_extension_custom_members.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/syntax_extension_custom_members.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/syntax_extension_custom_members.n Sat Feb 24 14:53:05 2007
@@ -4,20 +4,42 @@
public class Foo {
public MethodOfFoo(): void {
- print("hello there\n");
+ print("From base method\n");
}
- abrakadabra { // custom member, creates static instance property, macro is defined in macrolib.n
- "asdf"
+ public internal protected private abrakadabra(WithModifiers) { //;)
+ }
+
+ abrakadabra(WithoutModifiers) {
+ }
+
+ [Bla] abrakadabra(WithCustomAttributes){
+ }
+
+ [Bla][Bla2] public abrakadabra(WithCustomAttributesAndModifiers){
}
public static Main(): void {
- Foo.Instance.MethodOfFoo(); // note Instance property, it should be created by abrakadabra macro
+ print(Foo.WithModifiers);
+ print("\n--\n");
+ print(Foo.WithoutModifiers);
+ print("\n--\n");
+ print(Foo.WithCustomAttributes);
+ print("\n--\n");
+ print(Foo.WithCustomAttributesAndModifiers);
+ print("\n--\n");
}
}
/*
BEGIN-OUTPUT
-hello there
+public internal protected private
+--
+
+--
+[Bla , ]
+--
+public [Bla , ] [Bla2 , ]
+--
END-OUTPUT
*/
More information about the svn
mailing list