Пример #1
0
// numericTz consumes a timezone field in the format [+-]HHMM or [+-]HH:MM
func numericTz(l *lexrec.Lexer, t lexrec.ItemType, emit bool) (success bool) {

	// leading + or -
	if !l.Accept(sign) {
		l.Errorf("expected plus or minus sign, got %q", l.Peek())
		l.Backup()
		return false
	}

	// Accept two 0-9 digits
	if !l.Accept(digits) || !l.Accept(digits) {
		l.Errorf("expected 2-digit hour, got %q", l.Peek())
		l.Backup()
		return false
	}

	// Accept optional ':'
	if ':' == l.Peek() {
		l.Next()
	}

	// Accept two 0-9 digits
	if !l.Accept(digits) || !l.Accept(digits) {
		l.Errorf("expected 2-digit minute, got %q", l.Peek())
		l.Backup()
		return false
	}

	// Note we aren't bothering to check the next character, if
	// it's a digit then we'll fail in the next StateFn.
	if emit {
		l.Emit(t)
	} else {
		l.Skip()
	}
	return true
}
Пример #2
0
// digitsOrMinus consumes either a sequence of digits or the single
// char '-' followed by a space.
func digitsOrMinus(l *lexrec.Lexer, t lexrec.ItemType, emit bool) (success bool) {
	if l.AcceptRun(digits) || (l.Accept("-") && l.Peek() == ' ') {
		if emit {
			l.Emit(t)
		} else {
			l.Skip()
		}
		return true
	}
	l.Errorf("expected a '-' or a sequence of %q, got %q", digits, l.Peek())
	return false
}