1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-03-29 12:54:55 +08:00
parent b50bfeccf8
commit 45ceab38a6
3 changed files with 20 additions and 18 deletions

View File

@ -13,6 +13,7 @@ import (
type Func struct { type Func struct {
line int line int
arg []string arg []string
res []string
} }
type Frame struct { type Frame struct {
key string key string
@ -66,7 +67,7 @@ func (s *Stack) value(key string, arg ...ice.Any) ice.Any {
kit.If(len(arg) > 0, func() { f.value[key] = arg[0] }) kit.If(len(arg) > 0, func() { f.value[key] = arg[0] })
return f.value[key] return f.value[key]
} }
func (s *Stack) runable() bool { return s.peekf().status > -1 } func (s *Stack) runable() bool { return s.peekf().status > DISABLE }
func (s *Stack) parse(m *ice.Message, p string) *Stack { func (s *Stack) parse(m *ice.Message, p string) *Stack {
nfs.Open(m, p, func(r io.Reader) { nfs.Open(m, p, func(r io.Reader) {
s.key, s.peekf().key = p, p s.key, s.peekf().key = p, p
@ -78,6 +79,15 @@ func (s *Stack) parse(m *ice.Message, p string) *Stack {
} }
for s.rest = kit.Split(text, "\t ", "<!=>+-*/;"); len(s.rest) > 0; { for s.rest = kit.Split(text, "\t ", "<!=>+-*/;"); len(s.rest) > 0; {
ls, rest := _parse_rest(BEGIN, s.rest...) ls, rest := _parse_rest(BEGIN, s.rest...)
if ls[0] == END {
if f := s.peekf(); f.pop == nil {
s.last = s.popf()
} else {
f.pop()
}
s.rest = ls[1:]
continue
}
kit.If(len(rest) == 0, func() { ls, rest = _parse_rest(END, ls...) }) kit.If(len(rest) == 0, func() { ls, rest = _parse_rest(END, ls...) })
switch s.rest = []string{}; v := s.value(ls[0]).(type) { switch s.rest = []string{}; v := s.value(ls[0]).(type) {
case *Func: case *Func:
@ -104,16 +114,14 @@ func (s *Stack) show() (res []string) {
res = append(res, "") res = append(res, "")
for i, f := range s.frame { for i, f := range s.frame {
res = append(res, kit.Format("frame: %v line: %v %v %v", i, f.line, f.key, f.status)) res = append(res, kit.Format("frame: %v line: %v %v %v", i, f.line, f.key, f.status))
kit.For(f.value, func(k string, v ice.Any) { res = append(res, kit.Format("frame: %v %v: %v", i, k, v)) }) kit.For(f.value, func(k string, v ice.Any) { res = append(res, kit.Format(" %v %v: %v", i, k, v)) })
} }
return return
} }
func NewStack() *Stack { return &Stack{} } func NewStack() *Stack { return &Stack{} }
func _parse_stack(m *ice.Message) *Stack { return m.Optionv(STACK).(*Stack) } func _parse_stack(m *ice.Message) *Stack { return m.Optionv(STACK).(*Stack) }
func _parse_frame(m *ice.Message) (*Stack, *Frame) { func _parse_frame(m *ice.Message) (*Stack, *Frame) { return _parse_stack(m), _parse_stack(m).peekf() }
return _parse_stack(m), _parse_stack(m).peekf()
}
func _parse_rest(split string, arg ...string) ([]string, []string) { func _parse_rest(split string, arg ...string) ([]string, []string) {
if i := kit.IndexOf(arg, split); i == -1 { if i := kit.IndexOf(arg, split); i == -1 {
return arg, nil return arg, nil
@ -177,14 +185,6 @@ func init() {
f := s.peekf() f := s.peekf()
f.status = DISABLE f.status = DISABLE
}}, }},
END: {Name: END, Hand: func(m *ice.Message, arg ...string) {
s := _parse_stack(m)
if f := s.peekf(); f.pop == nil {
s.last = s.popf()
} else {
f.pop()
}
}},
PWD: {Name: "pwd", Hand: func(m *ice.Message, arg ...string) { PWD: {Name: "pwd", Hand: func(m *ice.Message, arg ...string) {
s := _parse_stack(m) s := _parse_stack(m)
kit.If(s.runable(), func() { kit.If(s.runable(), func() {
@ -198,9 +198,9 @@ func init() {
return return
} }
m.SetResult() m.SetResult()
m.Echo(ice.NL).Echo("output:" + ice.NL) m.Echo(ice.NL).Echo("output: %s\n", arg[0])
s := NewStack().parse(m, path.Join(nfs.SRC, path.Join(arg...))) s := NewStack().parse(m, path.Join(nfs.SRC, path.Join(arg...)))
m.Echo(ice.NL).Echo("script:" + ice.NL) m.Echo(ice.NL).Echo("script: %s\n", arg[0])
m.Echo(strings.Join(s.show(), ice.NL)) m.Echo(strings.Join(s.show(), ice.NL))
}}, }},
EXPR: {Name: "expr a = 1", Hand: func(m *ice.Message, arg ...string) { EXPR: {Name: "expr a = 1", Hand: func(m *ice.Message, arg ...string) {

View File

@ -93,7 +93,9 @@ func init() {
case ctx.INDEX: case ctx.INDEX:
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX)) m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX))
case ctx.ARGS: case ctx.ARGS:
kit.If(m.Option(ctx.INDEX) != "", func() { m.Cmdy(m.Option(ctx.INDEX)) }) kit.If(m.Option(ctx.INDEX) != "", func() {
m.Cmdy(m.Option(ctx.INDEX)).Search(m.Option(ctx.INDEX), func(key string, cmd *ice.Command) { m.Cut(kit.Format(kit.Value(cmd.List, "0.name"))) })
})
case nfs.PATH: case nfs.PATH:
m.Cmdy(nfs.DIR, p, nfs.DIR_CLI_FIELDS) m.Cmdy(nfs.DIR, p, nfs.DIR_CLI_FIELDS)
kit.If(strings.HasPrefix(p, bind[0]), func() { m.Cmdy(nfs.DIR, strings.Replace(p, bind[0], bind[1], 1), nfs.DIR_CLI_FIELDS) }) kit.If(strings.HasPrefix(p, bind[0]), func() { m.Cmdy(nfs.DIR, strings.Replace(p, bind[0], bind[1], 1), nfs.DIR_CLI_FIELDS) })

View File

@ -285,7 +285,7 @@ func (m *Message) Sort(key string, arg ...string) *Message {
if m.FieldsIsDetail() { if m.FieldsIsDetail() {
return m return m
} }
keys, cmps := kit.Split(kit.Select(key, "type,name,text")), kit.Simple() keys, cmps := kit.Split(kit.Select("type,name,text", key)), kit.Simple()
for i, k := range keys { for i, k := range keys {
cmp := kit.Select("", arg, i) cmp := kit.Select("", arg, i)
if cmp == "" { if cmp == "" {