本文整理汇总了Golang中github.com/iNamik/go_lexer.Lexer.PeekRune方法的典型用法代码示例。如果您正苦于以下问题:Golang Lexer.PeekRune方法的具体用法?Golang Lexer.PeekRune怎么用?Golang Lexer.PeekRune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/iNamik/go_lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.PeekRune方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: stWhitespace
func stWhitespace(l lex.Lexer) lex.StateFn {
for next := l.PeekRune(0); inMapR(next, whitespaceChars); next = l.PeekRune(0) {
l.NextRune()
if next == '\n' {
l.NewLine()
}
}
emit(l, Whitespace)
return stStart
}
示例2: stHex
func stHex(l lex.Lexer) lex.StateFn {
if l.NextRune() != '0' {
emitError("Hex numbers should start with 0")
return nil
}
if unicode.ToLower(l.NextRune()) != 'x' {
emitError("Malformatted hex number (no x)")
return nil
}
baseChars := 0
for ; inMapR(l.PeekRune(0), hexdigits); baseChars++ {
l.NextRune()
}
fmt.Println("Base Chars:", baseChars)
if l.PeekRune(0) == '.' {
l.NextRune()
if !l.MatchOneOrMoreBytes(hexdigits_b) {
emitError("Malformed hex number.")
return nil
}
} else if baseChars == 0 {
emitError("Malformed hex number (no base chars or decimal).")
return nil
}
if unicode.ToLower(l.PeekRune(0)) == 'p' {
l.NextRune()
next := l.PeekRune(0)
if next == '+' || next == '-' {
l.NextRune()
}
if !l.MatchOneOrMoreBytes(digits_b) {
emitError("Malformed hex number (no digits after p)")
return nil
}
}
emit(l, HexNumber)
return stStart
}
示例3: longStringEquals
// longStringEquals peeks the bytestream to see if
// a long string beginning is directly ahead. It returns the amount
// of equals the long string has, or -1 if
// no string found
func longStringEquals(delim rune, l lex.Lexer) int {
if l.PeekRune(0) != delim {
return -1
}
equalsCt := 0
for l.PeekRune(equalsCt+1) == '=' {
equalsCt++
}
if l.PeekRune(equalsCt+1) != delim {
return -1
}
return equalsCt
}
示例4: stStart
func stStart(l lex.Lexer) lex.StateFn {
char := l.PeekRune(0)
switch true {
case char == lex.RuneEOF:
l.EmitEOF()
return nil
// Read comments
case char == '-' && l.PeekRune(1) == '-':
return stComment
// Double-quote string
case char == '"' || char == '\'':
return stReadString
// Read 3char symbols
case inMapR(char, symbols_3c_1) && inMap(concatRunes(char, l.PeekRune(1), l.PeekRune(2)), symbols_3c):
l.NextRune()
l.NextRune()
l.NextRune()
emit(l, Symbol)
return stStart
// 2char symbols
case inMapR(char, symbols_2c_1) && inMap(concatRunes(char, l.PeekRune(1)), symbols_2c):
l.NextRune()
l.NextRune()
emit(l, Symbol)
return stStart
// 1char symbols
case inMapR(char, symbols_1c):
l.NextRune()
emit(l, Symbol)
return stStart
// Read a Name identifier
case inMapR(char, nameFirstChar):
return stReadName
// Read whitespace
case inMapR(char, whitespaceChars):
emit(l, Whitespace)
return stWhitespace
// Read Long strings
case longStringEquals('[', l) >= 0:
return stLongString
// Read hex numbers
case char == '0' && (unicode.ToLower(l.PeekRune(1)) == 'x'):
return stHex
// Read normal numbers
case inMapR(char, digits):
return stNumber
}
return nil
}