Moved things around
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
engine "github.com/tgckpg/mmqlengine/mmql/engine"
|
||||
stmtd "github.com/tgckpg/mmqlengine/mmql/statements"
|
||||
)
|
||||
|
||||
/*
|
||||
EXPECT: [Number] [Units]
|
||||
OR
|
||||
EXPECT: [FUNCTION]( ...params )
|
||||
*/
|
||||
|
||||
func AmountStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
|
||||
stmt := stmtd.AmountStatement{}
|
||||
|
||||
val, err := lexer.ReadDecimal()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
stmt.Value = val
|
||||
|
||||
unit, err := lexer.ReadAlpha()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
stmt.Unit = unit
|
||||
|
||||
istmt = stmt
|
||||
return
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
engine "github.com/tgckpg/mmqlengine/mmql/engine"
|
||||
stmtd "github.com/tgckpg/mmqlengine/mmql/statements"
|
||||
)
|
||||
|
||||
/*
|
||||
EXPECT: BUY
|
||||
THEN EXPECT: [AmountStatement] OF [FinancialInstrumentStatement]
|
||||
THEN EXPECT: FOR [AmountStatement]
|
||||
THEN EXPECT: FROM [ExchangeType]
|
||||
THEN OPT EXPECT: [ExchangeType]
|
||||
THEN OPT EXPECT: [AND|OR]
|
||||
THEN EXPECT: [ActionExpression]
|
||||
THEN OPT EXPECT: FOR EVERY
|
||||
THEN EXPECT: [AmountType] OF [FinancialInstrumentType]
|
||||
THEN EXPECT: [SOLD|BOUGHT] FROM [ExchangeType]
|
||||
*/
|
||||
|
||||
func BuyStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
|
||||
orderStmt := stmtd.OrderStatement{}
|
||||
orderStmt.Action = "BUY"
|
||||
|
||||
// AmountStatement
|
||||
readAmount := engine.LexerExpect{
|
||||
Statements: true,
|
||||
Keywords: false,
|
||||
Brackets: false,
|
||||
Quotes: false,
|
||||
Key: "AMOUNT",
|
||||
}
|
||||
|
||||
amountStmt, err := lexer.ReadStatement( &readAmount )
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
orderStmt.For( amountStmt )
|
||||
|
||||
// OF
|
||||
err = lexer.ReadKeyword( "OF" )
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// FinancialInstrumentStatement
|
||||
readFI := engine.LexerExpect{
|
||||
Statements: true,
|
||||
Keywords: false,
|
||||
Brackets: false,
|
||||
Quotes: false,
|
||||
Key: "FINANCIAL_INSTRUMENT",
|
||||
}
|
||||
productStmt, err := lexer.ReadStatement( &readFI )
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
orderStmt.FinancialInstrument( productStmt )
|
||||
|
||||
istmt = orderStmt
|
||||
return
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"testing"
|
||||
engine "github.com/tgckpg/mmqlengine/mmql/engine"
|
||||
stmtd "github.com/tgckpg/mmqlengine/mmql/statements"
|
||||
)
|
||||
|
||||
func TestBuyStatement( t *testing.T ) {
|
||||
lexer := engine.Lexer{}
|
||||
supportedStmts := map[string] func( *engine.Lexer ) ( stmtd.IStatement, error ) {
|
||||
"BUY": BuyStatement,
|
||||
"AMOUNT": AmountStatement,
|
||||
"FINANCIAL_INSTRUMENT": FinancialInstrumentStatement,
|
||||
}
|
||||
lexer.SupportedStmts = &supportedStmts
|
||||
|
||||
_, err := lexer.Parse( `
|
||||
BUY 1 SHARES OF BTC_ETF
|
||||
FOR 10 USD
|
||||
FROM "MyBrokerAccount"
|
||||
WITH LIMIT OF PURCHASING_POWER( "MyBrokerAccount", "QQQ" )
|
||||
FOR EVERY
|
||||
1 BTC OF USD_BTC SOLD
|
||||
FROM "CoinBase"
|
||||
` )
|
||||
if err != nil {
|
||||
t.Error( err )
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
engine "github.com/tgckpg/mmqlengine/mmql/engine"
|
||||
stmtd "github.com/tgckpg/mmqlengine/mmql/statements"
|
||||
)
|
||||
|
||||
/*
|
||||
EXPECT: [NAME]
|
||||
OR
|
||||
EXPECT: [FUNCTION]( ...params )
|
||||
*/
|
||||
|
||||
func FinancialInstrumentStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
|
||||
stmt := stmtd.FinancialInstrumentStatement{}
|
||||
|
||||
name, err := lexer.ReadAlpha()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
stmt.Name = name
|
||||
|
||||
istmt = stmt
|
||||
return
|
||||
}
|
24
mmql/statements/amount.go
Normal file
24
mmql/statements/amount.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package statements
|
||||
|
||||
type AmountStatement struct {
|
||||
IStatement
|
||||
_value float64
|
||||
_unit string
|
||||
_func *FunctionStatement
|
||||
}
|
||||
|
||||
func ( this *AmountStatement ) SetValue( v float64 ) {
|
||||
this._value = v
|
||||
}
|
||||
|
||||
func ( this *AmountStatement ) Value() float64 {
|
||||
return this._value
|
||||
}
|
||||
|
||||
func ( this *AmountStatement ) SetUnit( v string ) {
|
||||
this._unit = v
|
||||
}
|
||||
|
||||
func ( this *AmountStatement ) Unit() string {
|
||||
return this._unit
|
||||
}
|
35
mmql/statements/order.go
Normal file
35
mmql/statements/order.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package statements
|
||||
|
||||
type OrderStatement struct {
|
||||
IStatement
|
||||
IActionStatement
|
||||
Action string
|
||||
|
||||
_amount *AmountStatement
|
||||
_for *AmountStatement
|
||||
_fi *FinancialInstrumentStatement
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) SetAmount( stmt *AmountStatement ) {
|
||||
this._amount = stmt
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) Amount() *AmountStatement {
|
||||
return this._amount
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) SetFor( stmt *AmountStatement ) {
|
||||
this._for = stmt
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) For() *AmountStatement {
|
||||
return this._for
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) SetFinancialInstrument( stmt *FinancialInstrumentStatement ) {
|
||||
this._fi = stmt
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) FinancialInstrument() *FinancialInstrumentStatement {
|
||||
return this._fi
|
||||
}
|
@@ -19,10 +19,10 @@ type BracketedValue struct {
|
||||
Brackets string
|
||||
}
|
||||
|
||||
type AmountStatement struct {
|
||||
type FunctionStatement struct {
|
||||
IStatement
|
||||
Value float64
|
||||
Unit string
|
||||
Name string
|
||||
Params *[] string
|
||||
}
|
||||
|
||||
type FinancialInstrumentStatement struct {
|
||||
@@ -31,18 +31,3 @@ type FinancialInstrumentStatement struct {
|
||||
}
|
||||
|
||||
type IActionStatement interface { }
|
||||
|
||||
|
||||
|
||||
|
||||
type OrderStatement struct {
|
||||
IStatement
|
||||
IActionStatement
|
||||
Action string
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) For( stmt IStatement ) {
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) FinancialInstrument( stmt IStatement ) {
|
||||
}
|
||||
|
Reference in New Issue
Block a user