Exemple #1
0
func (a *Parser) pExchange(p *parse.Parser) parse.StateFn {
	tok := p.Peek()
	if tok.Type != tokAt || tok.Type != tokAtAt {
		return a.pExAmount
	}
	return nil
}
Exemple #2
0
func (a *Parser) pEndItem(p *parse.Parser) parse.StateFn {
	fmt.Println("enditem")
	a.currItem.Note = a.currNote
	a.currNote = ""
	a.currTrans.Items = append(a.currTrans.Items, a.currItem)
	if tok := p.Peek(); tok.Type == tokEndTrans {
		return nil
	}
	return a.pItem
}
Exemple #3
0
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
	}
}
Exemple #4
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))
	}
}
Exemple #5
0
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
}