Beispiel #1
0
func lexNewline(l *lex.Lexer) lex.StateFn {
	l.AcceptRun(indent)
	if l.AcceptRun(lineend) == 0 {
		l.Errorf("lexer error - missing expected newline")
	} else {
		l.Emit(tokNewline)
	}
	return nil
}
Beispiel #2
0
func lexBlankLine(l *lex.Lexer) lex.StateFn {
	l.AcceptRun(indent)
	l.Ignore()

	if l.AcceptRun(lineend) == 0 {
		l.Errorf("unexpected non-blank line at line %v", l.LineNumber())
		return lexSkipLine
	}
	l.Ignore()
	return nil
}
Beispiel #3
0
func lexAt(l *lex.Lexer) lex.StateFn {
	if n := l.AcceptRun(at); n > 2 {
		l.Errorf("invalid token on line %v", l.LineNumber())
		return lexSkipLine
	} else if n == 1 {
		l.Emit(tokAt)
	} else if n == 2 {
		l.Emit(tokAtAt)
	}
	return nil
}
Beispiel #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
	}
}
Beispiel #5
0
func lexDate(l *lex.Lexer) lex.StateFn {
	fail := false
	if l.AcceptRun(digit) == 0 {
		fail = true
	} else if !l.Accept("/") {
		fail = true
	} else if l.AcceptRun(digit) == 0 {
		fail = true
	} else if !l.Accept("/") {
		fail = true
	} else if l.AcceptRun(digit) == 0 {
		fail = true
	}

	if fail {
		l.AcceptRunNot(whitespace + meta)
		l.Errorf("invalid date on line %v", l.LineNumber())
		l.Ignore()
	} else {
		l.Emit(tokDate)
	}
	return nil
}