Exemplo n.º 1
0
func lexUntilClosing(l *lex.Lexer, styp lex.ItemType,
	sfn lex.StateFn) lex.StateFn {

	l.AcceptUntil(isClosingBracket)
	r := l.Next()
	if r == lex.EOF {
		return l.Errorf("Unexpected end of subject")
	}
	if r == '>' {
		l.Emit(styp)
		return sfn
	}
	return l.Errorf("Invalid character %v found for itemType: %v", r, styp)
}
Exemplo n.º 2
0
// Assumes that the current rune is '_'.
func lexBlankNode(l *lex.Lexer, styp lex.ItemType,
	sfn lex.StateFn) lex.StateFn {

	// RDF Blank Node.
	// TODO: At some point do checkings based on the guidelines. For now,
	// just accept everything until space.
	l.AcceptUntil(isSpace)
	r := l.Peek()
	if r == lex.EOF {
		return l.Errorf("Unexpected end of subject")
	}

	if isSpace(r) {
		l.Emit(styp)
		return sfn
	}

	return l.Errorf("Invalid character %v found for itemType: %v", r, styp)
}
Exemplo n.º 3
0
// lexFilterFuncInside expects input to look like ("...", "...").
func lexFilterFuncInside(l *lex.Lexer) lex.StateFn {
	l.AcceptRun(isSpace)
	l.Ignore() // Any spaces encountered.

	for {
		r := l.Next()
		if isSpace(r) || r == ',' {
			l.Ignore()
		} else if r == leftRound {
			l.Emit(itemLeftRound)
		} else if r == rightRound {
			l.Emit(itemRightRound)
			return lexFilterInside
		} else if isEndLiteral(r) {
			l.Ignore()
			l.AcceptUntil(isEndLiteral) // This call will backup the ending ".
			l.Emit(itemFilterFuncArg)
			l.Next() // Consume " and ignore it.
			l.Ignore()
		} else {
			return l.Errorf("Expected quotation mark in lexFilterFuncArgs")
		}
	}
}
Exemplo n.º 4
0
func lexUidNode(l *lex.Lexer, styp lex.ItemType, sfn lex.StateFn) lex.StateFn {
	l.AcceptUntil(isSpace)
	r := l.Peek()
	if r == lex.EOF {
		return l.Errorf("Unexpected end of uid subject")
	}

	in := l.Input[l.Start:l.Pos]
	if !strings.HasPrefix(in, "_uid_:") {
		return l.Errorf("Expected _uid_: Found: %v", l.Input[l.Start:l.Pos])
	}

	if _, err := strconv.ParseUint(in[6:], 0, 64); err != nil {
		return l.Errorf("Unable to convert '%v' to UID", in[6:])
	}

	if isSpace(r) {
		l.Emit(styp)
		return sfn
	}

	return l.Errorf("Invalid character %v found for UID node itemType: %v", r,
		styp)
}