本文整理匯總了Golang中espra/lex.Lexer.Pos方法的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer.Pos方法的具體用法?Golang Lexer.Pos怎麽用?Golang Lexer.Pos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類espra/lex.Lexer
的用法示例。
在下文中一共展示了Lexer.Pos方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LexForExpr
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))
}
}
示例2: LexTextNode
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
}
示例3: LeftDelim
// 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
}
示例4: RightDelim
// 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
}