MMQLEngine/mmql/statements/actions/buy.go

63 lines
1.4 KiB
Go
Raw Normal View History

2022-10-21 16:03:06 +00:00
package actions
import (
engine "github.com/tgckpg/mmqlengine/mmql/engine"
stmtd "github.com/tgckpg/mmqlengine/mmql/statements"
)
/*
EXPECT: BUY
THEN EXPECT: [AmountStatement] OF [ProductStatement]
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 [ProductType]
THEN EXPECT: [SOLD|BOUGHT] FROM [ExchangeType]
*/
2022-10-21 16:35:24 +00:00
func BuyStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
2022-10-21 16:03:06 +00:00
orderStmt := stmtd.OrderStatement{}
orderStmt.Action = "BUY"
2022-10-21 16:35:24 +00:00
// AmountStatement
2022-10-21 16:03:06 +00:00
readAmount := engine.LexerExpect{
Statements: true,
Keywords: false,
Brackets: false,
Quotes: false,
Key: "AMOUNT",
}
amountStmt, err := lexer.ReadStatement( &readAmount )
if err != nil {
2022-10-21 16:35:24 +00:00
return
2022-10-21 16:03:06 +00:00
}
orderStmt.For( amountStmt )
2022-10-21 16:35:24 +00:00
// OF
err = lexer.ReadKeyword( "OF" )
if err != nil {
return
}
// ProductStatement
readProduct := engine.LexerExpect{
Statements: true,
Keywords: false,
Brackets: false,
Quotes: false,
Key: "PRODUCT",
}
productStmt, err := lexer.ReadStatement( &readProduct )
if err != nil {
return
}
orderStmt.Product( productStmt )
istmt = orderStmt
return
2022-10-21 16:03:06 +00:00
}