|
Re: SQL Integration: msg#00008lang.boo.devel
On Thu, 3 Feb 2005 09:27:29 -0600, Greg Fitzgerald <garious-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx> wrote: > On a somewhat related note, has there been any thought of integrating > Nemerle's macro syntax into Boo? http://nemerle.org/macros.html Yes, Rodrigo supports making it easier to create macros too: http://jira.codehaus.org/browse/BOO-95 We need a "macro" macro. It's a little tricky. If anyone works on it, I'd be glad to help, or Rodrigo if you have any tips about implementing it I can work on it. I have a little pseudo-code below but there are still a lot of holes. If you have any tips about implementing slicing of duck types, too (http://jira.codehaus.org/browse/BOO-192) I'd appreciate it. Should I add a Slice(object, begin, end) function to boo.lang.runtimeservices that handles slicing at runtime based on whether the object is an array, list, hash, IQuackfu, string, etc. But what about when you are assigning to a slice of a duck type: m[0] = 3 ////////////////////////// See the With macro under examples/macro/ for a related example. class MacroMacro(AbstractAstMacro): def Expand(macro as MacroStatement): assert macro.arg.count is 1, arg[0] is a MethodInvocation //create the proper name for the macro (ex: PerformtransactionMacro) macroname = (macro.arg[0] as MethodInvocation).Name macroname = macroname[0].ToUpper() + macroname[1:] + "Macro" //create the new macro class to hold the macro macroclass = ClassDefinition() macroclass.Name = macroname macroclass.BaseTypes += (AbstractAstMacro,) //add an "Expand" method to this macro class: expand = Method() ...set expand's name, parameters, return type macroclass.Members["Expand"] = expand ...set expand's typemembermodifiers to public and override //loop through body (using MacroExpander visitor) //and replace references to args and body //with reference to ??? originalblock = macro.Block me = MacroExpander(macro) me.Visit(originalblock) newblock = Block() ...add statements to the newblock to return the original block when the macro is actually executed ...add the new block to the expand method expand.Block = newblock ...add the macro class to the parent module return null //Visitor class that replaces references to "args" or "body" (based on //code from the "With" macro in the examples folder: private class MacroExpander(DepthFirstTransformer): _macro as MacroStatement def constructor(macro as MacroStatement): _macro = macro override def OnReferenceExpression(node as ReferenceExpression): if node.Name == "args": print "found args reference" replace it with what? elif node.Name == "body": print "found body reference" replace it with what? ///////////////////////// fake sample macro: import DBLibrary macro performtransaction(args, body) _transaction = args[0].BeginTransaction() try: body _transaction.Commit() except: _transaction.Revert() finally: _transaction.End() //////////////////////// using the macro: performtransaction myconn: myconn.Execute(cmd1) myconn.Execute(cmd2)
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [jira] Created: (BOO-246) Implicit duck typing option, jira-yCVjj/EcxBJg9hUCZPvPmw |
|---|---|
| Next by Date: | Re: SQL Integration, Doug H |
| Previous by Thread: | Re: SQL Integration, Greg Fitzgerald |
| Next by Thread: | Re: SQL Integration, Doug H |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |