Source File
scanner.go
Belonging Package
github.com/go-git/gcfg/scanner
package scanner
import (
)
import (
)
type ErrorHandler func(pos token.Position, msg string)
ErrorCount int // number of errors encountered
}
type Mode uint
const (
ScanComments Mode = 1 << iota // return comments as COMMENT tokens
)
if .Size() != len() {
panic(fmt.Sprintf("file size (%d) does not match src len (%d)", .Size(), len()))
}
.file =
.dir, _ = filepath.Split(.Name())
.src =
.err =
.mode =
.ch = ' '
.offset = 0
.rdOffset = 0
.lineOffset = 0
.ErrorCount = 0
.nextVal = false
.next()
}
func ( *Scanner) ( int, string) {
if .err != nil {
.err(.file.Position(.file.Pos()), )
}
.ErrorCount++
}
:= .offset - 1 // position of initial [;#]
for .ch != '\n' && .ch >= 0 {
.next()
}
return string(.src[:.offset])
}
func ( rune) bool {
return 'a' <= && <= 'z' || 'A' <= && <= 'Z' || >= 0x80 && unicode.IsLetter()
}
func ( rune) bool {
return '0' <= && <= '9' || >= 0x80 && unicode.IsDigit()
}
func ( *Scanner) () string {
:= .offset
for isLetter(.ch) || isDigit(.ch) || .ch == '-' {
.next()
}
return string(.src[:.offset])
}
func ( *Scanner) ( bool) {
:= .offset
:= .ch
.next() // always make progress
switch {
case 'n', 't', 'b':
if {
break // ok
}
fallthrough
default:
.error(, "unknown escape sequence")
}
}
:= .offset - 1
for .ch != '"' {
:= .ch
.next()
if == '\n' || < 0 {
.error(, "string not terminated")
break
}
if == '\\' {
.scanEscape(false)
}
}
.next()
return string(.src[:.offset])
}
func ( []byte) []byte {
:= make([]byte, len())
:= 0
for , := range {
if != '\r' {
[] =
++
}
}
return [:]
}
func ( *Scanner) () string {
:= .offset
:= false
:=
:= false
:
for || .ch >= 0 && .ch != '\n' && .ch != ';' && .ch != '#' {
:= .ch
.next()
switch {
case && == '\\':
.scanEscape(true)
case ! && == '\\':
if .ch == '\r' {
= true
.next()
}
if .ch != '\n' {
.scanEscape(true)
} else {
.next()
}
case == '"':
= !
case == '\r':
= true
case < 0 || && == '\n':
.error(, "string not terminated")
break
}
if || !isWhiteSpace() {
= .offset
}
}
:= .src[:]
if {
= stripCR()
}
return string()
}
func ( rune) bool {
return == ' ' || == '\t' || == '\r'
}
func ( *Scanner) () {
for isWhiteSpace(.ch) {
.next()
}
}
switch := .ch; {
case .nextVal:
= .scanValString()
= token.STRING
.nextVal = false
case isLetter():
= .scanIdentifier()
= token.IDENT
default:
.next() // always make progress
switch {
case -1:
= token.EOF
case '\n':
= token.EOL
case '"':
= token.STRING
= .scanString()
case '[':
= token.LBRACK
case ']':
= token.RBRACK
= .scanComment()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |