Exemplo n.º 1
0
func lexItem(l *lex.Lexer) lex.StateFn {
	l.Push(lexMeta)
	l.Push(lexAmount)
	l.Push(lexAt)
	l.Push(lexAmount)
	l.Push(lexAccount)
	return lexStatus
}
Exemplo n.º 2
0
func lexTrans(l *lex.Lexer) lex.StateFn {
	l.Emit(tokBeginTrans)

	l.Push(lexEndTrans)
	l.Push(lexItems)
	l.Push(lexMeta)
	l.Push(lexPayee)
	l.Push(lexStatus)
	return lexDate
}
Exemplo n.º 3
0
func lexItems(l *lex.Lexer) lex.StateFn {
	if l.AcceptRun(indent) == 0 {
		return nil
	} else if string(l.Peek()) == meta {
		l.Push(lexItems)
		return lexMeta
	}

	l.Ignore()

	l.Push(lexItems)
	return lexItem
}
Exemplo n.º 4
0
// lexStart looks for a comment or a transaction, it emits everything
// inbetween as tokText
func lexStart(l *lex.Lexer) lex.StateFn {
	switch r := l.Peek(); {
	case string(r) == meta:
		l.Push(lexStart)
		return lexMeta
	case unicode.IsDigit(r):
		l.Push(lexStart)
		return lexTrans
	case isSpace(r) || isNewline(r):
		l.Push(lexStart)
		return lexBlankLine
	case r == lex.EOF:
		l.Emit(lex.TokEOF)
		return nil
	default:
		l.Errorf("unexpected text on line %v", l.LineNumber())
		l.Push(lexStart)
		return lexSkipLine
	}
}