Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some renaming

  • Loading branch information...
commit 7c0bed91e4b71764959d1a4a38aa9afcf5e1504c 1 parent b0a2975
@paulk-asert authored
View
3  README.md
@@ -2,4 +2,5 @@ Various DSL examples.
* __EinsteinsRiddle__ looks at solving a logic puzzle using prolog directly and beneath a DSL and also using the Choco
* __Numismatics__ looks at solving the problem of writing friendly expressions using a Coin Enum example
-* __WebTestingDSL__ looks at writing testing DSLs applicable to a sample web application using approaches that are friendly to testers and business users
+* __WebTestingDSL__ looks at writing testing DSLs applicable to a sample web application
+* __StockExchangeOrders__ looks at writing a DSL for orders of stocks and shares
View
12 ...kExchangeOrders/src/four/OrderDSL4.groovy → ...StockOrders_MOP_CustomBinding_GEP3.groovy
@@ -8,16 +8,16 @@ Integer.metaClass.getShares = { -> delegate }
// ---- Stock exchange orders DSL ---------------------------------
-order to buy 200.shares of GOOG {
- limitPrice 500
+order to sell 150.shares of IBM {
+ limitPrice 300
allOrNone false
- at the value of { qty * unitPrice - 100 }
+ at the value of { qty * unitPrice - 600 }
}
-order to sell 150.shares of VMW {
- limitPrice 80
+order to buy 500.shares of GOOG {
+ limitPrice 200
allOrNone true
- at the value of { qty * unitPrice }
+ at the value of { qty * unitPrice - 100 }
}
// ----- Implementation of the DSL --------------------------------
View
7 StockExchangeOrders/src/one/OrderDSL1.groovy → ...ders/src/one/StockOrders_FluentAPI.groovy
@@ -1,16 +1,17 @@
+// Example inspired from DSLs in Action: http://www.manning.com/ghosh/
package one
println new Order()
.sell(150, "IBM")
.limitPrice(300)
.allOrNone(true)
- .valueAs{ qty, unitPrice -> qty * unitPrice - 100 }
+ .valueAs{ qty, unitPrice -> qty * unitPrice - 600 }
println new Order()
- .buy(200, "GOOG")
+ .buy(500, "GOOG")
.limitPrice(200)
.allOrNone(true)
- .valueAs{ qty, unitPrice -> qty * unitPrice - 500 }
+ .valueAs{ qty, unitPrice -> qty * unitPrice - 100 }
// ----- Implementation of the Fluent API ---------------
View
6 ...ExchangeOrders/src/three/OrderDSL3.groovy → ...hree/StockOrders_MOP_CustomBinding.groovy
@@ -86,13 +86,13 @@ class CustomBinding extends Binding {
// use the script binding for retrieving IBM, etc.
binding = new CustomBinding()
-newOrder.to.buy(100.shares.of(IBM)) {
+newOrder.to.sell(150.shares.of(IBM)) {
limitPrice 300
allOrNone true
- valueAs { qty * unitPrice - 500 }
+ valueAs { qty * unitPrice - 600 }
}
-newOrder.to.sell 200.shares.of(GOOG), {
+newOrder.to.buy 500.shares.of(GOOG), {
limitPrice 200
allOrNone false
valueAs { qty * unitPrice - 100 }
View
8 StockExchangeOrders/src/two/OrderDSL2.groovy → ...angeOrders/src/two/StockOrders_MOP.groovy
@@ -70,14 +70,14 @@ class CustomBinding extends Binding {
// use the script binding for retrieving IBM, etc.
binding = new CustomBinding()
-newOrder.to.buy(100.shares.of(IBM)) {
+newOrder.to.sell(150.shares.of(IBM)) {
limitPrice 300
allOrNone true
- valueAs { qty, unitPrice -> qty * unitPrice - 200 }
+ valueAs { qty, unitPrice -> qty * unitPrice - 600 }
}
-newOrder.to.sell 200.shares.of(GOOG), {
+newOrder.to.buy 500.shares.of(GOOG), {
limitPrice 200
allOrNone false
- valueAs { qty, unitPrice -> qty * unitPrice - 500 }
+ valueAs { qty, unitPrice -> qty * unitPrice - 100 }
}
Please sign in to comment.
Something went wrong with that request. Please try again.