本文整理匯總了Golang中github.com/rwcarlsen/goledger/parse.Parser.Next方法的典型用法代碼示例。如果您正苦於以下問題:Golang Parser.Next方法的具體用法?Golang Parser.Next怎麽用?Golang Parser.Next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rwcarlsen/goledger/parse.Parser
的用法示例。
在下文中一共展示了Parser.Next方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pTrans
func (a *Parser) pTrans(p *parse.Parser) parse.StateFn {
fmt.Println("Trans")
tok := p.Next()
if tok.Type != tokBeginTrans {
panic(fmt.Sprintf("unexpected token %v: '%v'", tokNames[tok.Type], tok.Val))
}
a.currTrans = &Trans{}
p.Push(a.pEndTrans)
return a.pHeader
}
示例2: pExAmount
func (a *Parser) pExAmount(p *parse.Parser) parse.StateFn {
fmt.Println("examount")
tok := p.Peek()
if tok.Type == tokUnit {
tok = p.Next()
a.currItem.ExCommod = tok.Val
}
switch tok := p.Peek(); tok.Type {
case tokNewline, tokEndTrans:
p.Next()
case tokAmount:
tok = p.Next()
rat := big.NewRat(0, 1)
var success bool
a.currItem.ExAmount, success = rat.SetString(tok.Val)
if !success {
panic("invalid amount")
}
if tok = p.Peek(); tok.Type == tokCommod {
tok = p.Next()
a.currItem.ExCommod = tok.Val
}
}
return nil
}
示例3: pItem
func (a *Parser) pItem(p *parse.Parser) parse.StateFn {
fmt.Println("Item")
tok := p.Next()
a.currItem = &Item{}
// check for status
if tok.Type == tokStatus {
fmt.Println("status")
a.currItem.Status = tok.Val
tok = p.Next()
}
// check for account (required)
if tok.Type == tokAccount {
fmt.Println("account: ", tok.Val)
a.currItem.Account = tok.Val
tok = p.Next()
} else {
panic(fmt.Sprintf("unexpected token %v: '%v'", tokNames[tok.Type], tok.Val))
}
p.Push(a.pEndItem)
p.Push(a.pNote)
p.Push(a.pExchange)
return a.pAmount
}
示例4: pNote
func (a *Parser) pNote(p *parse.Parser) parse.StateFn {
switch tok := p.Peek(); tok.Type {
case tokMeta:
p.Next()
tok = p.Next()
a.currNote = tok.Val
if tok = p.Next(); tok.Type != tokNewline {
panic(fmt.Sprintf("unexpected token %v: '%v'", tokNames[tok.Type], tok.Val))
}
return nil
default:
return nil
}
}
示例5: pHeader
func (a *Parser) pHeader(p *parse.Parser) parse.StateFn {
tok := p.Next()
// check for date (required)
if tok.Type == tokDate {
var err error
a.currTrans.Date, err = time.Parse("06/1/2", tok.Val)
if err != nil {
panic(err.Error())
}
tok = p.Next()
} else {
panic(fmt.Sprintf("unexpected token %v: '%v'", tokNames[tok.Type], tok.Val))
}
// check for status
if tok.Type == tokStatus {
a.currTrans.Status = tok.Val
tok = p.Next()
}
// check for payee (required)
if tok.Type == tokPayee {
a.currTrans.Descrip = tok.Val
tok = p.Next()
} else {
panic(fmt.Sprintf("unexpected token %v: '%v'", tokNames[tok.Type], tok.Val))
}
// check for note
if tok.Type == tokMeta {
a.currTrans.Note = p.Next().Val
tok = p.Next()
}
if tok.Type != tokNewline {
panic(fmt.Sprintf("unexpected token %v: '%v'", tokNames[tok.Type], tok.Val))
}
return a.pItem
}