本文整理匯總了Golang中espra/lex.Lexer.Errorf方法的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer.Errorf方法的具體用法?Golang Lexer.Errorf怎麽用?Golang Lexer.Errorf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類espra/lex.Lexer
的用法示例。
在下文中一共展示了Lexer.Errorf方法的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: Number
func Number(l *lex.Lexer) lex.StateFn {
if !l.ScanNumber() {
return l.Errorf("bad number syntax: %q", l.Input[l.Start:l.Pos])
}
l.Emit(ItemNumber)
return InsideAction
}
示例3: InsideAction
func InsideAction(l *lex.Lexer) lex.StateFn {
if l.Name == "LexTextNode" && strings.HasPrefix(l.Input[l.Pos:], rightDelim) {
if l.IntState[ActionParenDepth] > 0 {
return l.Errorf("unmatched parentheses")
}
return RightDelim
}
switch r := l.Next(); {
case (r == lex.EOF || lex.IsEndOfLine(r)):
if l.Name == "LexIfExpr" {
return LexIfExpr
}
if l.Name == "LexForExpr" {
return LexForExpr
}
// if reach eof throw while still in action throw error
return l.Errorf("unclosed action")
case lex.IsSpace(r):
return Space
case unicode.IsLetter(r): //variable and function must begin with a letter
return Identifier
case r == '!':
if unicode.IsLetter(l.Peek()) {
return Identifier
}
return l.Errorf("invalid character in builtin")
case r == '#' || r == '+':
if unicode.IsLetter(l.Peek()) {
return EspraURI
}
return l.Errorf("invalid character in URI")
case r == '-' || unicode.IsDigit(r):
l.Backup()
return Number
case r == '\'' || r == '"':
l.Emit(ItemOpenQuote)
return String
case r == '(':
l.IntState[ActionParenDepth] += 1
l.Emit(ItemLeftParen)
case r == ')':
l.IntState[ActionParenDepth] -= 1
l.Emit(ItemRightParen)
case r == '|':
l.Emit(ItemPipe)
default:
return l.Errorf("Unexpected Character '%s'", string(r))
}
return InsideAction
}
示例4: String
// Quote scans a quoted string.
func String(l *lex.Lexer) lex.StateFn {
Loop:
for {
switch l.Next() {
case '\\':
// ???
if r := l.Next(); r != lex.EOF && r != '\n' {
break
}
fallthrough
case lex.EOF, '\n':
return l.Errorf("unterminated quoted string")
case '"', '\'':
l.Backup()
break Loop
}
}
l.Emit(ItemString)
l.Next()
l.Emit(ItemCloseQuote)
return InsideAction
}