Source File
parser.go
Belonging Package
github.com/kevinburke/ssh_config
package ssh_config
import (
)
type sshParser struct {
flow chan token
config *Config
tokensBuffer []token
currentTable []string
system bool
depth uint8
}
type sshParserStateFn func() sshParserStateFn
panic(.Position.String() + ": " + .Error())
}
func ( *sshParser) () {
for := .parseStart; != nil; {
= ()
}
}
func ( *sshParser) () *token {
if len(.tokensBuffer) != 0 {
return &(.tokensBuffer[0])
}
, := <-.flow
if ! {
return nil
}
.tokensBuffer = append(.tokensBuffer, )
return &
}
func ( *sshParser) () *token {
if len(.tokensBuffer) != 0 {
:= .tokensBuffer[0]
.tokensBuffer = .tokensBuffer[1:]
return &
}
, := <-.flow
if ! {
return nil
}
return &
}
func ( *sshParser) () sshParserStateFn {
:= .peek()
if == nil {
return nil
}
switch .typ {
case tokenComment, tokenEmptyLine:
return .parseComment
case tokenKey:
return .parseKV
case tokenEOF:
return nil
default:
.raiseErrorf(, fmt.Sprintf("unexpected token %q\n", ))
}
return nil
}
func ( *sshParser) () sshParserStateFn {
:= .getToken()
:= false
:= .getToken()
if .typ == tokenEquals {
= true
= .getToken()
}
:= ""
:= .peek()
if == nil {
= &token{typ: tokenEOF}
}
if .typ == tokenComment && .Position.Line == .Position.Line {
= .getToken()
= .val
}
.raiseErrorf(, "ssh_config: Match directive parsing is unsupported")
return nil
}
if strings.ToLower(.val) == "host" {
:= strings.Split(.val, " ")
:= make([]*Pattern, 0)
for := range {
if [] == "" {
continue
}
, := NewPattern([])
if != nil {
.raiseErrorf(, "Invalid host pattern: %v", )
return nil
}
= append(, )
}
.config.Hosts = append(.config.Hosts, &Host{
Patterns: ,
Nodes: make([]Node, 0),
EOLComment: ,
hasEquals: ,
})
return .parseStart
}
:= .config.Hosts[len(.config.Hosts)-1]
if strings.ToLower(.val) == "include" {
, := NewInclude(strings.Split(.val, " "), , .Position, , .system, .depth+1)
if == ErrDepthExceeded {
.raiseError(, )
return nil
}
if != nil {
.raiseErrorf(, "Error parsing Include directive: %v", )
return nil
}
.Nodes = append(.Nodes, )
return .parseStart
}
:= &KV{
Key: .val,
Value: .val,
Comment: ,
hasEquals: ,
leadingSpace: .Position.Col - 1,
position: .Position,
}
.Nodes = append(.Nodes, )
return .parseStart
}
func ( *sshParser) () sshParserStateFn {
:= .getToken()
:= .config.Hosts[len(.config.Hosts)-1]
.Nodes = append(.Nodes, &Empty{
leadingSpace: .Position.Col - 2,
position: .Position,
})
return .parseStart
}
![]() |
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. |