Beispiel #1
0
func LexForExpr(l *lex.Lexer) lex.StateFn {
	if int(l.Pos) >= len(l.Input) {
		l.Emit(lex.ItemEOF)
		return nil
	}
	if strings.HasPrefix(l.Input[l.Pos:], "in") {
		l.Pos += lex.Pos(2)
		l.Emit(ItemIn)
		return InsideAction
	}

	// any list of space separated identifiers
	switch r := l.Next(); {
	case lex.IsSpace(r):
		for lex.IsSpace(l.Peek()) {
			l.Next()
		}
		l.Emit(ItemSpace)
		return LexForExpr
	case unicode.IsLetter(r):
		return LoopIdentifier
	default:
		return l.Errorf("Unexpected Character '%s'", string(r))
	}
}
Beispiel #2
0
func LexTextNode(l *lex.Lexer) lex.StateFn {
	for {
		r := l.Next()
		if lex.IsAlphaNumeric(l.Peek()) {
			if lex.IsSpace(r) || lex.IsEndOfLine(r) {
				l.Emit(ItemText)
			}
			i := lex.Pos(strings.IndexAny(l.Input[l.Pos:], " \t\n\r"))
			if i != -1 {
				i = l.Pos + i
			} else {
				i = lex.Pos(len(l.Input) - 1)
			}
			if strings.Contains(l.Input[l.Pos:i], ":") {
				l.Pos = i
				return LexURI
			}
		}
		l.Backup()
		if strings.HasPrefix(l.Input[l.Pos:], leftDelim) {
			if l.Pos > l.Start {
				l.Emit(ItemText)
			}
			return LeftDelim
		}
		if l.Next() == lex.EOF {
			break
		}
	}
	// Correctly reached EOF.
	if l.Pos > l.Start {
		l.Emit(ItemText)
	}
	l.Emit(lex.ItemEOF)
	return nil
}
Beispiel #3
0
// LeftDelim scans the left delimiter, which is known to be present.
func LeftDelim(l *lex.Lexer) lex.StateFn {
	l.Pos += lex.Pos(len(leftDelim))
	l.Emit(ItemLeftDelim)
	return InsideAction
}
Beispiel #4
0
// RightDelim scans the right delimiter, which is known to be present.
func RightDelim(l *lex.Lexer) lex.StateFn {
	l.Pos += lex.Pos(len(rightDelim))
	l.Emit(ItemRightDelim)
	return LexTextNode
}