Skip to content

Commit

Permalink
update examples to latest syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo B. de Oliveira committed Oct 4, 2010
1 parent e80dec4 commit 551ce7f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 51 deletions.
62 changes: 13 additions & 49 deletions examples/macros/PerformTransaction/PerformTransactionMacro.boo
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion


import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast

class PerformTransactionMacro(AbstractAstMacro):
macro performTransaction(connection as Boo.Lang.Compiler.Ast.Expression):
"""
performTransaction connection:
connection.Execute(cmd1)
Expand All @@ -47,50 +44,17 @@ ensure:
transaction.End()
"""

override def Expand(macro as MacroStatement):

assert 1 == len(macro.Arguments)

connection = macro.Arguments[0]

block = Block()
block.Add(
BinaryExpression(
BinaryOperatorType.Assign,
ReferenceExpression("transaction"),
MethodInvocationExpression(
MemberReferenceExpression(
connection,
"BeginTransaction"))))

stmt = TryStatement()
stmt.ProtectedBlock = macro.Body
stmt.ProtectedBlock.Add(
MethodInvocationExpression(
MemberReferenceExpression(
ReferenceExpression("transaction"),
"Commit")))

handler = ExceptionHandler()
handler.Block.Add(
MethodInvocationExpression(
MemberReferenceExpression(
ReferenceExpression("transaction"),
"Revert")))
handler.Block.Add(
RaiseStatement())
stmt.ExceptionHandlers.Add(handler)

stmt.EnsureBlock = Block()
stmt.EnsureBlock.Add(
MethodInvocationExpression(
MemberReferenceExpression(
ReferenceExpression("transaction"),
"End")))

block.Add(stmt)

return block
yield [| transaction = $connection.BeginTransaction() |]
yield [|
try:
$(performTransaction.Body)
transaction.Commit()
except:
transaction.Revert()
raise
ensure:
transaction.End()
|]



3 changes: 2 additions & 1 deletion examples/macros/PerformTransaction/default.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<target name="expand" depends="compile-macro">
<booc
target="library"
output="nothanks"
pipeline="boo">

Expand All @@ -25,7 +26,7 @@
</target>

<target name="init">
<loadtasks assembly="../../../bin/Boo.NAnt.Tasks.dll" />
<loadtasks assembly="../../../build/Boo.NAnt.Tasks.dll" />
</target>

</project>
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/lines.boo
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ import System.IO
fname, = argv
using stream = File.OpenText(fname):
for index, line in enumerate(stream):
print("${index}: ${line}")
print "$index: $line"

0 comments on commit 551ce7f

Please sign in to comment.