本文整理汇总了Golang中github.com/spearson78/guardian/script/scanner.Scanner.Scan方法的典型用法代码示例。如果您正苦于以下问题:Golang Scanner.Scan方法的具体用法?Golang Scanner.Scan怎么用?Golang Scanner.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spearson78/guardian/script/scanner.Scanner
的用法示例。
在下文中一共展示了Scanner.Scan方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: seekElse
func seekElse(s *scanner.Scanner) error {
ifDepth := 0
loop:
for {
tok := s.Scan()
switch tok {
case token.ENDOFSCRIPT:
return errors.New("Unclosed IF Statements")
case token.IF:
ifDepth++
case token.ENDIF:
if ifDepth == 0 {
break loop
} else {
ifDepth--
}
case token.ELSE:
if ifDepth == 0 {
break loop
}
}
}
return nil
}
示例2: Subscriptify
func Subscriptify(script []byte, sig []byte) ([]byte, error) {
s := new(scanner.Scanner)
s.Init(script, nil)
subscript := make([]byte, 0, len(script))
loop:
for {
tok := s.Scan()
switch tok {
case token.DATA:
//Suppress the signature
if !bytes.Equal(s.Data(), sig) {
subscript = append(subscript, s.ByteCode())
subscript = append(subscript, s.Data()...)
}
case token.CODESEPARATOR:
//Remove code separators
case token.ENDOFSCRIPT:
break loop
case token.INVALID:
return nil, errors.New("Invalid Token")
default:
//All other tokens are passed straight through
subscript = append(subscript, s.ByteCode())
}
}
if s.ErrorCount() != 0 {
return nil, errors.New("Scanner Errors Occured")
}
return subscript, nil
}
示例3: execScanner
func (this *Executor) execScanner(script []byte) error {
s := new(scanner.Scanner)
s.Init(script, nil)
ifDepth := 0
loop:
for {
tok := s.Scan()
switch tok {
case token.DATA:
this.Push(s.Data())
case token.OPERATION:
impl := opCodeImpls[s.Op()]
if impl == nil {
return errors.New("Unknown OpCode - " + s.Op().String())
}
err := impl(&this.Context)
if err != nil {
return err
}
case token.ENDOFSCRIPT:
break loop
case token.NUMBER:
this.PushNumber(s.Number())
case token.CODESEPARATOR:
this.codeSeparatorPos = s.Pos()
case token.IF:
ifDepth++
top := this.PopBool()
if !top {
seekElse(s)
}
case token.NOTIF:
ifDepth++
top := this.PopBool()
if top {
seekElse(s)
}
case token.ELSE:
if ifDepth == 0 {
return errors.New("Unexpected EndIf")
}
ifDepth--
seekEndIf(s)
case token.ENDIF:
if ifDepth == 0 {
return errors.New("Unexpected Else")
}
ifDepth--
case token.INVALID:
return errors.New("Invalid Token")
}
}
if ifDepth != 0 {
return errors.New("Unclosed If")
}
if s.ErrorCount() != 0 {
return errors.New("TokenSource reported errors")
}
return nil
}