tag mode II

master
Paulo Simão 2021-11-03 23:31:34 -03:00
parent 59a4e22ee8
commit 1c1151ffd6
1 changed files with 23 additions and 17 deletions

40
lib.go
View File

@ -88,6 +88,18 @@ func Tokens(str string) ([]string, error) {
default: default:
return nil, errors.New(fmt.Sprintf("Error at char %d - cant add space here. Mode: %s", i, mode.String())) return nil, errors.New(fmt.Sprintf("Error at char %d - cant add space here. Mode: %s", i, mode.String()))
} }
case '=':
switch mode {
case MODE_NORMAL:
if sb.Len() > 0 {
params = append(params, sb.String())
sb = strings.Builder{}
}
params = append(params, "=")
case MODE_STR, MODE_ESCAPE_STR:
sb.WriteRune(a)
}
case '\n': case '\n':
switch mode { switch mode {
case MODE_NORMAL: case MODE_NORMAL:
@ -105,13 +117,6 @@ func Tokens(str string) ([]string, error) {
switch mode { switch mode {
case MODE_NORMAL: case MODE_NORMAL:
if sb.Len() > 0 { if sb.Len() > 0 {
lchar := sb.String()[sb.Len()-1]
if lchar == '=' {
sb.WriteRune(a)
mode = MODE_TAG
continue
}
params = append(params, sb.String()) params = append(params, sb.String())
sb = strings.Builder{} sb = strings.Builder{}
mode = MODE_STR mode = MODE_STR
@ -122,7 +127,6 @@ func Tokens(str string) ([]string, error) {
params = append(params, sb.String()) params = append(params, sb.String())
sb = strings.Builder{} sb = strings.Builder{}
mode = MODE_NORMAL mode = MODE_NORMAL
case MODE_STR: case MODE_STR:
params = append(params, sb.String()) params = append(params, sb.String())
sb = strings.Builder{} sb = strings.Builder{}
@ -227,12 +231,12 @@ func Lines(str string) ([]Line, error) {
Tokens: make([]string, 0), Tokens: make([]string, 0),
} }
default: default:
//if len(line.Tokens) > 2 && line.Tokens[len(line.Tokens)-1] == "=" { if len(line.Tokens) > 2 && line.Tokens[len(line.Tokens)-1] == "=" {
// line.Tokens[len(line.Tokens)-2] = line.Tokens[len(line.Tokens)-2] + "=" + tk line.Tokens[len(line.Tokens)-2] = line.Tokens[len(line.Tokens)-2] + "=" + tk
// line.Tokens = line.Tokens[:len(line.Tokens)-1] line.Tokens = line.Tokens[:len(line.Tokens)-1]
//} else { } else {
line.Tokens = append(line.Tokens, tk) line.Tokens = append(line.Tokens, tk)
//} }
} }
} }
@ -308,17 +312,19 @@ func Exec(str string, opts ...*Opts) ([]*exec.Cmd, error) {
if filepath.IsAbs(l.Tokens[1]) { if filepath.IsAbs(l.Tokens[1]) {
cmdwd = l.Tokens[1] cmdwd = l.Tokens[1]
} else { } else {
cmdwd, err = filepath.Abs(filepath.Join(wd, l.Tokens[1])) cmdwd, err = filepath.Abs(filepath.Join(cmdwd, l.Tokens[1]))
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
log.Printf("CMDWD NOW IS: %s", cmdwd) if opt.Debug {
log.Printf("CMDWD NOW IS: %s", cmdwd)
}
continue continue
case LINETYPE_SERIAL: case LINETYPE_SERIAL:
cmd := prepCmd(l) cmd := prepCmd(l)
if opt.Debug { if opt.Debug {
log.Printf("Running %s from dir %s with params %v", cmd.Path, cmd.Dir, cmd.Args) log.Printf("Running %s from dir %s with params %s", cmd.Path, cmd.Dir, strings.Join(cmd.Args, ","))
} }
err = cmd.Run() err = cmd.Run()
if opt.Debug { if opt.Debug {