當前位置: 首頁>>代碼示例>>Golang>>正文


Golang lex.Lexer類代碼示例

本文整理匯總了Golang中github.com/dgraph-io/dgraph/lex.Lexer的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer類的具體用法?Golang Lexer怎麽用?Golang Lexer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Lexer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: lexPredicate

func lexPredicate(l *lex.Lexer) lex.StateFn {
	r := l.Next()
	if r != '<' {
		return l.Errorf("Invalid character in lexPredicate: %v", r)
	}
	l.Depth += 1
	return lexUntilClosing(l, itemPredicate, lexText)
}
開發者ID:cayleydb,項目名稱:dgraph,代碼行數:8,代碼來源:state.go

示例2: lexArgumentVal

func lexArgumentVal(l *lex.Lexer) lex.StateFn {
	for {
		switch r := l.Next(); {
		case isSpace(r):
			l.Ignore()
		}
	}
}
開發者ID:cayleydb,項目名稱:dgraph,代碼行數:8,代碼來源:state.go

示例3: lexPredicate

func lexPredicate(l *lex.Lexer) lex.StateFn {
	r := l.Next()
	// The predicate can only be an IRI according to the spec.
	if r != '<' {
		return l.Errorf("Invalid character in lexPredicate: %v", r)
	}

	l.Depth++
	return lexUntilClosing(l, itemPredicate, lexText)
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:10,代碼來源:state.go

示例4: lexObject

func lexObject(l *lex.Lexer) lex.StateFn {
	r := l.Next()
	// The object can be an IRI, blank node or a literal.
	if r == '<' {
		l.Depth++
		return lexUntilClosing(l, itemObject, lexText)
	}

	if r == '_' {
		l.Depth++
		r = l.Next()
		// TODO - Remove this, doesn't conform to the spec.
		if r == 'u' {
			return lexUidNode(l, itemObject, lexText)
		}

		if r == ':' {
			return lexBlankNode(l, itemObject, lexText)
		}
	}
	if r == '"' {
		l.Ignore()
		return lexLiteral(l)
	}

	return l.Errorf("Invalid char: %v at lexObject", r)
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:27,代碼來源:state.go

示例5: lexTextMutation

// lexTextMutation lexes and absorbs the text inside a mutation operation block.
func lexTextMutation(l *lex.Lexer) lex.StateFn {
	for {
		r := l.Next()
		if r == lex.EOF {
			return l.Errorf("Unclosed mutation text")
		}
		if r == quote {
			return lexMutationValue
		}
		if r == leftCurl {
			l.Depth++
		}
		if r == rightCurl {
			if l.Depth > 2 {
				l.Depth--
				continue
			}
		}
		if r != rightCurl {
			// Absorb everything until we find '}'.
			continue
		}
		l.Backup()
		l.Emit(itemMutationContent)
		break
	}
	return lexInsideMutation
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:29,代碼來源:state.go

示例6: lexUntilClosing

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)
}
開發者ID:cayleydb,項目名稱:dgraph,代碼行數:14,代碼來源:state.go

示例7: lexAlias

func lexAlias(l *lex.Lexer) lex.StateFn {
	l.AcceptRun(isSpace)
	l.Ignore() // Any spaces encountered.
	for {
		r := l.Next()
		if isNameSuffix(r) {
			continue
		}
		l.Backup()
		l.Emit(itemAlias)
		break
	}
	return lexInside
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:14,代碼來源:state.go

示例8: lexScalarBlock

func lexScalarBlock(l *lex.Lexer) lex.StateFn {
	for {
		switch r := l.Next(); {
		case r == ')':
			l.Emit(itemRightRound)
			return lexText
		case isNameBegin(r):
			l.Backup()
			return lexScalarPair1
		case isSpace(r) || isEndOfLine(r):
			l.Ignore()
		default:
			return l.Errorf("Invalid schema. Unexpected %s", l.Input[l.Start:l.Pos])
		}
	}
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:16,代碼來源:state.go

示例9: lexObjectBlock

func lexObjectBlock(l *lex.Lexer) lex.StateFn {
	for {
		switch r := l.Next(); {
		case r == leftCurl:
			l.Emit(itemLeftCurl)
		case isSpace(r) || isEndOfLine(r):
			l.Ignore()
		case r == rightCurl:
			l.Emit(itemRightCurl)
			return lexText
		case isNameBegin(r):
			return lexObjectPair
		default:
			return l.Errorf("Invalid schema. Unexpected %s", l.Input[l.Start:l.Pos])
		}
	}
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:17,代碼來源:state.go

示例10: lexMutationValue

// This function is used to absorb the object value.
func lexMutationValue(l *lex.Lexer) lex.StateFn {
	for {
		r := l.Next()
		if r == '\\' {
			// So that we don't count \" as end of value.
			if l.Next() == quote {
				continue
			}

		}
		// This is an end of value so lets return.
		if r == quote {
			break
		}
		// We absorb everything else.
		continue
	}
	return lexTextMutation
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:20,代碼來源:state.go

示例11: lexBlankNode

// 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)
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:20,代碼來源:state.go

示例12: lexOperationType

func lexOperationType(l *lex.Lexer) lex.StateFn {
	for {
		r := l.Next()
		if isNameSuffix(r) {
			continue // absorb
		}
		l.Backup()
		word := l.Input[l.Start:l.Pos]
		if word == "mutation" {
			l.Emit(itemOpType)
			l.Mode = mutationMode

		} else if word == "query" {
			l.Emit(itemOpType)
			l.Mode = queryMode
		}
		break
	}
	return lexText
}
開發者ID:ashwin95r,項目名稱:dgraph,代碼行數:20,代碼來源:state.go

示例13: lexLabel

func lexLabel(l *lex.Lexer) lex.StateFn {
	r := l.Next()
	// Graph label can either be an IRI or a blank node according to spec.
	if r == '<' {
		l.Depth++
		return lexUntilClosing(l, itemLabel, lexText)
	}

	if r == '_' {
		l.Depth++
		r = l.Next()
		if r != ':' {
			return l.Errorf("Invalid char: %c at lexLabel", r)
		}

		l.Backup()
		return lexBlankNode(l, itemLabel, lexText)
	}
	return l.Errorf("Invalid char: %v at lexLabel", r)
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:20,代碼來源:state.go

示例14: lexStart

func lexStart(l *lex.Lexer) lex.StateFn {
	for {
		r := l.Next()
		if isNameSuffix(r) {
			continue // absorb
		}
		l.Backup()
		// l.Pos would be index of the end of operation type + 1.
		word := l.Input[l.Start:l.Pos]
		if word == "scalar" {
			l.Emit(itemScalar)
			return lexScalar
		} else if word == "type" {
			l.Emit(itemType)
			return lexObject
		} else {
			return l.Errorf("Invalid schema")
		}
	}

}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:21,代碼來源:state.go

示例15: lexObject

func lexObject(l *lex.Lexer) lex.StateFn {
	r := l.Next()
	if r == '<' {
		l.Depth += 1
		return lexUntilClosing(l, itemObject, lexText)
	}
	if r == '_' {
		l.Depth += 1
		return lexBlankNode(l, itemObject, lexText)
	}
	if r == '"' {
		l.Ignore()
		return lexLiteral(l)
	}

	return l.Errorf("Invalid char: %v at lexObject", r)
}
開發者ID:cayleydb,項目名稱:dgraph,代碼行數:17,代碼來源:state.go


注:本文中的github.com/dgraph-io/dgraph/lex.Lexer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。