示例#1
0
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
0
func (a *Parser) Start(p *parse.Parser) parse.StateFn {
	fmt.Println("Start")
	a.currNote = ""
	switch tok := p.Peek(); tok.Type {
	case lex.TokEOF:
		return nil
	case tokBeginTrans:
		fmt.Printf("type %v: %+v\n", tokNames[tok.Type], tok)
		return a.pTrans
	case tokNewline:
		return a.Start
	case tokMeta:
		p.Push(a.Start)
		return a.pNote
	default:
		panic(fmt.Sprintf("unexpected token %v: '%v'", tokNames[tok.Type], tok.Val))
	}
}
示例#3
0
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
}