本文整理匯總了Golang中github.com/hialin/hialin/parse/internal/engine/lexer.Lexer.Location方法的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer.Location方法的具體用法?Golang Lexer.Location怎麽用?Golang Lexer.Location使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hialin/hialin/parse/internal/engine/lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.Location方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: errorRecovery
func (p *Parser) errorRecovery(lex lexer.Lexer, tok lexer.Token, stateStack []ItemSetID, dataStack []interface{}) (lexer.Token, []ItemSetID, []interface{}, error) {
parseErr := ParseError{
Invalid: []lexer.Token{tok},
Location: lex.Location(),
}
topState := stateStack[len(stateStack)-1]
for expectedTok := range p.parsetable[topState] {
parseErr.Expected = append(parseErr.Expected, p.Syms.Get(expectedTok))
}
// rewind the state stack searching for an error rule
action, found := p.parsetable[topState][syms.ERROR]
for !(found && action.actiontype == Shift) {
stateStack = stateStack[:len(stateStack)-1]
if len(stateStack) == 0 {
break
}
topState = stateStack[len(stateStack)-1]
action, found = p.parsetable[topState][syms.ERROR]
}
parseErr.Valid = append(parseErr.Valid, dataStack[len(stateStack):]...)
dataStack = dataStack[:len(stateStack)]
if len(stateStack) == 0 {
err := UnexpectedTerminalParseError("parse error; could not find a suitable error rule")
dataStack = append(dataStack, parseErr)
if p.debug {
fmt.Println("\nParse error, no error recovery possible", p.fmtStacks(stateStack, dataStack))
}
return tok, stateStack, dataStack, err
}
stateStack = append(stateStack, action.state)
// now search for next action by discarding unfitting tokens
actionMap := p.parsetable[action.state]
action, found = actionMap[tok.ID]
parseErr.Invalid = nil
for !found {
parseErr.Invalid = append(parseErr.Invalid, tok)
if tok.ID == syms.EOF {
err := UnexpectedTerminalParseError("parse error; could not find a suitable error rule before EOF")
dataStack = append(dataStack, parseErr)
if p.debug {
fmt.Println("\nParse error, EOF while recovering",
"\nRecovery state expected one of:", p.symNames(actionMap),
p.fmtStacks(stateStack, dataStack))
}
return tok, stateStack, dataStack, err
}
var err error
tok, err = p.nextToken(lex)
if err != nil {
dataStack = append(dataStack, parseErr)
return tok, stateStack, dataStack, err
}
action, found = actionMap[tok.ID]
}
dataStack = append(dataStack, parseErr)
if p.debug {
fmt.Println("\nParse error, stack unwinded", p.fmtStacks(stateStack, dataStack))
}
return tok, stateStack, dataStack, nil
}