本文整理匯總了Golang中github.com/iNamik/go_lexer.Lexer.NewLine方法的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer.NewLine方法的具體用法?Golang Lexer.NewLine怎麽用?Golang Lexer.NewLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/iNamik/go_lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.NewLine方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: readLongString
func readLongString(l lex.Lexer) bool {
numEquals := longStringEquals('[', l)
if numEquals < 0 {
emitError("Expecting [ to start string.")
return false
}
// eat first [
l.NextRune()
for i := 0; i < numEquals; i++ {
if l.NextRune() != '=' {
emitError("Expected string `=` padding.")
return false
}
}
// gobble string contents
for {
char := l.NextRune()
if char == lex.RuneEOF {
emitError("Unexpected EOF. Expecting long-string close.")
return false
}
if char == '\n' {
l.NewLine()
}
// potential close
if char == ']' {
// ungobble first ]
l.BackupRune()
closingCt := longStringEquals(']', l)
if closingCt != numEquals {
// re-gobble the ]
l.NextRune()
} else {
// it was our close!
// eat the closing bits
l.NextRune()
for i := 0; i < numEquals; i++ {
if l.NextRune() != '=' {
emitError("Expected close-string `=` padding.")
}
}
l.NextRune()
return true
}
}
}
return false
}
示例3: stReadString
func stReadString(l lex.Lexer) lex.StateFn {
delim := l.NextRune()
if !(delim == '\'' || delim == '"') {
emitError("Expected `\"` or `'` to start quote-string.")
}
for {
char := l.NextRune()
switch char {
case delim:
// end of string
fmt.Println("End of the string!")
emit(l, String)
return stStart
case '\\':
l.NextRune()
case lex.RuneEOF:
l.EmitEOF()
case '\n':
l.NewLine()
}
}
return stStart
}