mirror of
https://github.com/dragonheim/gagent.git
synced 2025-02-23 03:29:54 -08:00
fix: [CI SKIP] Well, golint did not like that. :(
This commit is contained in:
parent
af92d9c089
commit
8f8ac47155
2 changed files with 32 additions and 32 deletions
|
@ -6,16 +6,16 @@ import (
|
|||
)
|
||||
|
||||
/*
|
||||
* pt_ESC is @TODO
|
||||
* ptESC is @TODO
|
||||
*/
|
||||
const (
|
||||
pt_ESC = iota
|
||||
pt_STR
|
||||
pt_CMD
|
||||
pt_VAR
|
||||
pt_SEP
|
||||
pt_EOL
|
||||
pt_EOF
|
||||
ptESC = iota
|
||||
ptSTR
|
||||
ptCMD
|
||||
ptVAR
|
||||
ptSEP
|
||||
ptEOL
|
||||
ptEOF
|
||||
)
|
||||
|
||||
type parserStruct struct {
|
||||
|
@ -25,8 +25,8 @@ type parserStruct struct {
|
|||
Type int
|
||||
}
|
||||
|
||||
func InitParser(text string) *parserStruct {
|
||||
return &parserStruct{text, 0, 0, 0, len(text), 0, pt_EOL}
|
||||
func initParser(text string) *parserStruct {
|
||||
return &parserStruct{text, 0, 0, 0, len(text), 0, ptEOL}
|
||||
}
|
||||
|
||||
func (p *parserStruct) next() {
|
||||
|
@ -53,7 +53,7 @@ func (p *parserStruct) parseSep() string {
|
|||
}
|
||||
}
|
||||
p.end = p.p
|
||||
p.Type = pt_SEP
|
||||
p.Type = ptSEP
|
||||
return p.token()
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ func (p *parserStruct) parseEol() string {
|
|||
}
|
||||
|
||||
p.end = p.p
|
||||
p.Type = pt_EOL
|
||||
p.Type = ptEOL
|
||||
return p.token()
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ Loop:
|
|||
p.next()
|
||||
}
|
||||
p.end = p.p
|
||||
p.Type = pt_CMD
|
||||
p.Type = ptCMD
|
||||
if p.p < len(p.text) && p.current() == ']' {
|
||||
p.next()
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ func (p *parserStruct) parseVar() string {
|
|||
p.start = p.p
|
||||
|
||||
if p.current() == '{' {
|
||||
p.Type = pt_VAR
|
||||
p.Type = ptVAR
|
||||
return p.parseBrace()
|
||||
}
|
||||
|
||||
|
@ -127,10 +127,10 @@ func (p *parserStruct) parseVar() string {
|
|||
if p.start == p.p { // It's just a single char string "$"
|
||||
p.start = p.p - 1
|
||||
p.end = p.p
|
||||
p.Type = pt_STR
|
||||
p.Type = ptSTR
|
||||
} else {
|
||||
p.end = p.p
|
||||
p.Type = pt_VAR
|
||||
p.Type = ptVAR
|
||||
}
|
||||
return p.token()
|
||||
}
|
||||
|
@ -164,10 +164,10 @@ Loop:
|
|||
}
|
||||
|
||||
func (p *parserStruct) parseString() string {
|
||||
newword := p.Type == pt_SEP || p.Type == pt_EOL || p.Type == pt_STR
|
||||
newword := p.Type == ptSEP || p.Type == ptEOL || p.Type == ptSTR
|
||||
|
||||
if c := p.current(); newword && c == '{' {
|
||||
p.Type = pt_STR
|
||||
p.Type = ptSTR
|
||||
return p.parseBrace()
|
||||
} else if newword && c == '"' {
|
||||
p.insidequote = 1
|
||||
|
@ -188,7 +188,7 @@ Loop:
|
|||
case '"':
|
||||
if p.insidequote != 0 {
|
||||
p.end = p.p
|
||||
p.Type = pt_ESC
|
||||
p.Type = ptESC
|
||||
p.next()
|
||||
p.insidequote = 0
|
||||
return p.token()
|
||||
|
@ -202,7 +202,7 @@ Loop:
|
|||
}
|
||||
|
||||
p.end = p.p
|
||||
p.Type = pt_ESC
|
||||
p.Type = ptESC
|
||||
return p.token()
|
||||
}
|
||||
|
||||
|
@ -216,10 +216,10 @@ func (p *parserStruct) parseComment() string {
|
|||
func (p *parserStruct) GetToken() string {
|
||||
for {
|
||||
if p.ln == 0 {
|
||||
if p.Type != pt_EOL && p.Type != pt_EOF {
|
||||
p.Type = pt_EOL
|
||||
if p.Type != ptEOL && p.Type != ptEOF {
|
||||
p.Type = ptEOL
|
||||
} else {
|
||||
p.Type = pt_EOF
|
||||
p.Type = ptEOF
|
||||
}
|
||||
return p.token()
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ func (p *parserStruct) GetToken() string {
|
|||
case '$':
|
||||
return p.parseVar()
|
||||
case '#':
|
||||
if p.Type == pt_EOL {
|
||||
if p.Type == ptEOL {
|
||||
p.parseComment()
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func (i *Interp) RegisterCommand(name string, fn CmdFunc, privdata interface{})
|
|||
|
||||
/* EVAL! */
|
||||
func (i *Interp) Eval(t string) (string, error) {
|
||||
p := InitParser(t)
|
||||
p := initParser(t)
|
||||
var result string
|
||||
var err error
|
||||
|
||||
|
@ -83,33 +83,33 @@ func (i *Interp) Eval(t string) (string, error) {
|
|||
prevtype := p.Type
|
||||
// XXX
|
||||
t = p.GetToken()
|
||||
if p.Type == pt_EOF {
|
||||
if p.Type == ptEOF {
|
||||
break
|
||||
}
|
||||
|
||||
switch p.Type {
|
||||
case pt_VAR:
|
||||
case ptVAR:
|
||||
v, ok := i.Var(t)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("no such variable '%s'", t)
|
||||
}
|
||||
t = string(v)
|
||||
case pt_CMD:
|
||||
case ptCMD:
|
||||
result, err = i.Eval(t)
|
||||
if err != nil {
|
||||
return result, err
|
||||
} else {
|
||||
t = result
|
||||
}
|
||||
case pt_ESC:
|
||||
case ptESC:
|
||||
// XXX: escape handling missing!
|
||||
case pt_SEP:
|
||||
case ptSEP:
|
||||
prevtype = p.Type
|
||||
continue
|
||||
}
|
||||
|
||||
// We have a complete command + args. Call it!
|
||||
if p.Type == pt_EOL {
|
||||
if p.Type == ptEOL {
|
||||
prevtype = p.Type
|
||||
if len(argv) != 0 {
|
||||
c := i.Command(argv[0])
|
||||
|
@ -127,7 +127,7 @@ func (i *Interp) Eval(t string) (string, error) {
|
|||
}
|
||||
|
||||
// We have a new token, append to the previous or as new arg?
|
||||
if prevtype == pt_SEP || prevtype == pt_EOL {
|
||||
if prevtype == ptSEP || prevtype == ptEOL {
|
||||
argv = append(argv, t)
|
||||
} else { // Interpolation
|
||||
argv[len(argv)-1] = strings.Join([]string{argv[len(argv)-1], t}, "")
|
||||
|
|
Loading…
Add table
Reference in a new issue