mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-11 23:12:39 -07:00
fix: [CI SKIP] A bit more clean-up.
This commit is contained in:
parent
568c35ab83
commit
af92d9c089
2 changed files with 30 additions and 30 deletions
|
@ -6,16 +6,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PT_ESC is @TODO
|
* pt_ESC is @TODO
|
||||||
*/
|
*/
|
||||||
const (
|
const (
|
||||||
PT_ESC = iota
|
pt_ESC = iota
|
||||||
PT_STR
|
pt_STR
|
||||||
PT_CMD
|
pt_CMD
|
||||||
PT_VAR
|
pt_VAR
|
||||||
PT_SEP
|
pt_SEP
|
||||||
PT_EOL
|
pt_EOL
|
||||||
PT_EOF
|
pt_EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
type parserStruct struct {
|
type parserStruct struct {
|
||||||
|
@ -26,7 +26,7 @@ type parserStruct struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitParser(text string) *parserStruct {
|
func InitParser(text string) *parserStruct {
|
||||||
return &parserStruct{text, 0, 0, 0, len(text), 0, PT_EOL}
|
return &parserStruct{text, 0, 0, 0, len(text), 0, pt_EOL}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parserStruct) next() {
|
func (p *parserStruct) next() {
|
||||||
|
@ -53,7 +53,7 @@ func (p *parserStruct) parseSep() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.end = p.p
|
p.end = p.p
|
||||||
p.Type = PT_SEP
|
p.Type = pt_SEP
|
||||||
return p.token()
|
return p.token()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func (p *parserStruct) parseEol() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.end = p.p
|
p.end = p.p
|
||||||
p.Type = PT_EOL
|
p.Type = pt_EOL
|
||||||
return p.token()
|
return p.token()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ Loop:
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
p.end = p.p
|
p.end = p.p
|
||||||
p.Type = PT_CMD
|
p.Type = pt_CMD
|
||||||
if p.p < len(p.text) && p.current() == ']' {
|
if p.p < len(p.text) && p.current() == ']' {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ func (p *parserStruct) parseVar() string {
|
||||||
p.start = p.p
|
p.start = p.p
|
||||||
|
|
||||||
if p.current() == '{' {
|
if p.current() == '{' {
|
||||||
p.Type = PT_VAR
|
p.Type = pt_VAR
|
||||||
return p.parseBrace()
|
return p.parseBrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,10 +127,10 @@ func (p *parserStruct) parseVar() string {
|
||||||
if p.start == p.p { // It's just a single char string "$"
|
if p.start == p.p { // It's just a single char string "$"
|
||||||
p.start = p.p - 1
|
p.start = p.p - 1
|
||||||
p.end = p.p
|
p.end = p.p
|
||||||
p.Type = PT_STR
|
p.Type = pt_STR
|
||||||
} else {
|
} else {
|
||||||
p.end = p.p
|
p.end = p.p
|
||||||
p.Type = PT_VAR
|
p.Type = pt_VAR
|
||||||
}
|
}
|
||||||
return p.token()
|
return p.token()
|
||||||
}
|
}
|
||||||
|
@ -164,10 +164,10 @@ Loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parserStruct) parseString() string {
|
func (p *parserStruct) parseString() string {
|
||||||
newword := p.Type == PT_SEP || p.Type == PT_EOL || p.Type == PT_STR
|
newword := p.Type == pt_SEP || p.Type == pt_EOL || p.Type == pt_STR
|
||||||
|
|
||||||
if c := p.current(); newword && c == '{' {
|
if c := p.current(); newword && c == '{' {
|
||||||
p.Type = PT_STR
|
p.Type = pt_STR
|
||||||
return p.parseBrace()
|
return p.parseBrace()
|
||||||
} else if newword && c == '"' {
|
} else if newword && c == '"' {
|
||||||
p.insidequote = 1
|
p.insidequote = 1
|
||||||
|
@ -188,7 +188,7 @@ Loop:
|
||||||
case '"':
|
case '"':
|
||||||
if p.insidequote != 0 {
|
if p.insidequote != 0 {
|
||||||
p.end = p.p
|
p.end = p.p
|
||||||
p.Type = PT_ESC
|
p.Type = pt_ESC
|
||||||
p.next()
|
p.next()
|
||||||
p.insidequote = 0
|
p.insidequote = 0
|
||||||
return p.token()
|
return p.token()
|
||||||
|
@ -202,7 +202,7 @@ Loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
p.end = p.p
|
p.end = p.p
|
||||||
p.Type = PT_ESC
|
p.Type = pt_ESC
|
||||||
return p.token()
|
return p.token()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,10 +216,10 @@ func (p *parserStruct) parseComment() string {
|
||||||
func (p *parserStruct) GetToken() string {
|
func (p *parserStruct) GetToken() string {
|
||||||
for {
|
for {
|
||||||
if p.ln == 0 {
|
if p.ln == 0 {
|
||||||
if p.Type != PT_EOL && p.Type != PT_EOF {
|
if p.Type != pt_EOL && p.Type != pt_EOF {
|
||||||
p.Type = PT_EOL
|
p.Type = pt_EOL
|
||||||
} else {
|
} else {
|
||||||
p.Type = PT_EOF
|
p.Type = pt_EOF
|
||||||
}
|
}
|
||||||
return p.token()
|
return p.token()
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ func (p *parserStruct) GetToken() string {
|
||||||
case '$':
|
case '$':
|
||||||
return p.parseVar()
|
return p.parseVar()
|
||||||
case '#':
|
case '#':
|
||||||
if p.Type == PT_EOL {
|
if p.Type == pt_EOL {
|
||||||
p.parseComment()
|
p.parseComment()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,33 +83,33 @@ func (i *Interp) Eval(t string) (string, error) {
|
||||||
prevtype := p.Type
|
prevtype := p.Type
|
||||||
// XXX
|
// XXX
|
||||||
t = p.GetToken()
|
t = p.GetToken()
|
||||||
if p.Type == PT_EOF {
|
if p.Type == pt_EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
switch p.Type {
|
switch p.Type {
|
||||||
case PT_VAR:
|
case pt_VAR:
|
||||||
v, ok := i.Var(t)
|
v, ok := i.Var(t)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("no such variable '%s'", t)
|
return "", fmt.Errorf("no such variable '%s'", t)
|
||||||
}
|
}
|
||||||
t = string(v)
|
t = string(v)
|
||||||
case PT_CMD:
|
case pt_CMD:
|
||||||
result, err = i.Eval(t)
|
result, err = i.Eval(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
} else {
|
} else {
|
||||||
t = result
|
t = result
|
||||||
}
|
}
|
||||||
case PT_ESC:
|
case pt_ESC:
|
||||||
// XXX: escape handling missing!
|
// XXX: escape handling missing!
|
||||||
case PT_SEP:
|
case pt_SEP:
|
||||||
prevtype = p.Type
|
prevtype = p.Type
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have a complete command + args. Call it!
|
// We have a complete command + args. Call it!
|
||||||
if p.Type == PT_EOL {
|
if p.Type == pt_EOL {
|
||||||
prevtype = p.Type
|
prevtype = p.Type
|
||||||
if len(argv) != 0 {
|
if len(argv) != 0 {
|
||||||
c := i.Command(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?
|
// We have a new token, append to the previous or as new arg?
|
||||||
if prevtype == PT_SEP || prevtype == PT_EOL {
|
if prevtype == pt_SEP || prevtype == pt_EOL {
|
||||||
argv = append(argv, t)
|
argv = append(argv, t)
|
||||||
} else { // Interpolation
|
} else { // Interpolation
|
||||||
argv[len(argv)-1] = strings.Join([]string{argv[len(argv)-1], t}, "")
|
argv[len(argv)-1] = strings.Join([]string{argv[len(argv)-1], t}, "")
|
||||||
|
|
Loading…
Add table
Reference in a new issue