forked from x/ContextOS
tce add cli.scan_file
This commit is contained in:
parent
87c8d7a002
commit
e4a597678b
2
Makefile
2
Makefile
@ -6,7 +6,7 @@ install:
|
||||
@cp etc/shy.vim ~/.vim/syntax/
|
||||
@touch etc/local.shy
|
||||
go install $(BENCH)
|
||||
@md5 `which bench`
|
||||
# @md5 `which bench`
|
||||
@date
|
||||
|
||||
build:
|
||||
|
@ -1,9 +1,9 @@
|
||||
scan_file etc/demo.shy
|
||||
|
||||
return
|
||||
source etc/local.shy
|
||||
|
||||
~aaa
|
||||
login root root
|
||||
~web
|
||||
command add get "https://chat.shylinux.com"
|
||||
|
||||
~yac
|
||||
scan_file etc/demo.shy demo_file
|
||||
|
@ -293,6 +293,7 @@ func (cli *CLI) Close(m *ctx.Message, arg ...string) bool { // {{{
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
return true
|
||||
}
|
||||
@ -739,15 +740,15 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
if !m.Caps("skip") {
|
||||
msg := m.Spawn(cli)
|
||||
msg.Start(fmt.Sprintf("%s_%d_%s", key, msg.Optioni("level", msg.Capi("level")+1), arg[0]), "脚本文件", arg[0])
|
||||
<-msg.Target().Exit
|
||||
m.Copy(msg, "result").Copy(msg, "append")
|
||||
nfs := msg.Sesss("nfs")
|
||||
nfs.Target().Close(nfs)
|
||||
|
||||
sub, _ := msg.Target().Server.(*CLI)
|
||||
if sub.target != msg.Target() {
|
||||
cli.target = sub.target
|
||||
}
|
||||
// <-msg.Target().Exit
|
||||
// m.Copy(msg, "result").Copy(msg, "append")
|
||||
// nfs := msg.Sesss("nfs")
|
||||
// nfs.Target().Close(nfs)
|
||||
//
|
||||
// sub, _ := msg.Target().Server.(*CLI)
|
||||
// if sub.target != msg.Target() {
|
||||
// cli.target = sub.target
|
||||
// }
|
||||
} // }}}
|
||||
}},
|
||||
"return": &ctx.Command{Name: "return result...", Help: "结束脚本, rusult: 返回值", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
@ -837,6 +838,16 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
"echo": &ctx.Command{Name: "echo arg...", Help: "函数调用, name: 函数名, arg: 参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
m.Echo("%s", strings.Join(arg, ""))
|
||||
}},
|
||||
"scan_file": &ctx.Command{Name: "scan_file", Help: "函数调用, name: 函数名, arg: 参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
m.Find("yac").Call(func(cmd *ctx.Message) *ctx.Message {
|
||||
cmd.Source(m.Target())
|
||||
cmd.Target(m.Target())
|
||||
m.Log("fuck", nil, "------cmd run- %v %s", cmd.Meta, cmd.Hand)
|
||||
cmd.Cmd()
|
||||
m.Log("fuck", nil, "------cmd run- %v", cmd.Meta)
|
||||
return nil
|
||||
}, "scan_file", arg[0])
|
||||
}},
|
||||
},
|
||||
Index: map[string]*ctx.Context{
|
||||
"void": &ctx.Context{Name: "void",
|
||||
|
@ -302,7 +302,6 @@ func (lex *LEX) scan(m *ctx.Message, page int, line []byte) (hash int, rest []by
|
||||
s, star = star, 0
|
||||
}
|
||||
}
|
||||
m.Log("fucK", nil, "why %d", pos)
|
||||
|
||||
if pos == len(line) {
|
||||
hash, pos, word = -1, 0, word[:0]
|
||||
@ -430,10 +429,8 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
||||
page = lex.index("npage", arg[1])
|
||||
}
|
||||
|
||||
m.Log("fuck", nil, "%d %s %s", page, arg[1], arg[0])
|
||||
hash, rest, word := lex.scan(m, page, []byte(arg[0]))
|
||||
m.Result(0, hash, string(rest), string(word))
|
||||
m.Log("fuck", nil, "\033[31m[%v]\033[0m %d [%v]", string(word), hash, string(rest))
|
||||
} // }}}
|
||||
}},
|
||||
"split": &ctx.Command{Name: "split line page void help", Help: "分割语句", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
|
@ -441,8 +441,8 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||
for {
|
||||
buf := make([]byte, m.Confi("buffer_size"))
|
||||
n, e := in.Read(buf)
|
||||
if m.Assert(e); n == 0 {
|
||||
break
|
||||
if e != nil && e != io.EOF {
|
||||
m.Assert(e)
|
||||
}
|
||||
|
||||
buf = buf[0:n]
|
||||
@ -450,6 +450,9 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||
m.Put("append", m.Cap("nread"), buf)
|
||||
m.Capi("nread", n)
|
||||
m.Back(m)
|
||||
if n == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -258,95 +258,59 @@ func (yac *YAC) parse(m *ctx.Message, cli *ctx.Context, page, void int, line str
|
||||
|
||||
// }}}
|
||||
func (yac *YAC) scan(m *ctx.Message, page int, void int, line string) (string, []string) { // {{{
|
||||
|
||||
hash, word := 0, []string{}
|
||||
for star, s := 0, page; s != 0 && len(line) > 0; {
|
||||
line := m.Find("lex").Cmd("scan", line, yac.name(void)).Result(1)
|
||||
lex := m.Find("lex").Cmd("scan", line, yac.name(s))
|
||||
|
||||
if lex.Result(0) == "-1" {
|
||||
return line, word
|
||||
}
|
||||
|
||||
c := byte(lex.Resulti(0))
|
||||
state := yac.mat[s][c]
|
||||
|
||||
if state != nil {
|
||||
if key := m.Find("lex").Cmd("parse", line, "key"); key.Resulti(0) == 0 || len(key.Result(2)) <= len(lex.Result(2)) {
|
||||
m.Log("debug", nil, "%s|%d get(%d,%d): %v \033[31m(%s)\033[0m", m.Cap("label")[0:level], level, s, c, state, lex.Result(2))
|
||||
line, word = lex.Result(1), append(word, lex.Result(2))
|
||||
} else {
|
||||
state = nil
|
||||
m.Log("fuck", nil, "begin--%v-----%v", page, yac.word[page])
|
||||
if line == "" { //加载数据
|
||||
if data, ok := m.Optionv("data").(chan []byte); ok {
|
||||
if buf := <-data; len(buf) > 0 {
|
||||
line = string(buf)
|
||||
}
|
||||
}
|
||||
|
||||
if state == nil {
|
||||
for i := 0; i < yac.Capi("ncell"); i++ {
|
||||
if x := yac.mat[s][byte(i)]; i < m.Capi("nlang") && x != nil {
|
||||
m.Log("debug", nil, "%s|%d try(%d,%d): %v", m.Cap("label")[0:level], level, s, i, x)
|
||||
|
||||
if c, l, w := yac.parse(m, cli, i, void, line); l != line {
|
||||
m.Log("debug", nil, "%s|%d get(%d,%d): %v", m.Cap("label")[0:level], level, s, i, x)
|
||||
line, word = l, append(word, w...)
|
||||
|
||||
cli, state = c, x
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
return
|
||||
cli := m.Target()
|
||||
page := m.Optioni("page")
|
||||
void := m.Optioni("void")
|
||||
|
||||
level := m.Capi("level", 1)
|
||||
yac.Log("debug", nil, fmt.Sprintf("%s\\%d %s(%d):", m.Cap("label")[0:level], level, yac.word[page], page))
|
||||
|
||||
hash, word := 0, []string{}
|
||||
for star, s := 0, page; s != 0 && len(line) > 0; {
|
||||
line = m.Sesss("lex", "lex").Cmd("scan", line, yac.name(void)).Result(1)
|
||||
lex := m.Sesss("lex", "lex").Cmd("scan", line, yac.name(s))
|
||||
|
||||
line = yac.Sess("lex").Cmd("parse", line, yac.name(void)).Result(1)
|
||||
lex := yac.Sess("lex").Cmd("parse", line, yac.name(s))
|
||||
if lex.Result(0) == "-1" { //加载数据
|
||||
if data, ok := m.Optionv("data").(chan []byte); ok {
|
||||
if buf := <-data; len(buf) > 0 {
|
||||
line += string(buf)
|
||||
continue
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
c := byte(lex.Resulti(0))
|
||||
state := yac.mat[s][c]
|
||||
|
||||
if state != nil {
|
||||
if key := yac.Sess("lex").Cmd("parse", line, "key"); key.Resulti(0) == 0 || len(key.Result(2)) <= len(lex.Result(2)) {
|
||||
m.Log("debug", nil, "%s|%d get(%d,%d): %v \033[31m(%s)\033[0m", m.Cap("label")[0:level], level, s, c, state, lex.Result(2))
|
||||
line, word = lex.Result(1), append(word, lex.Result(2))
|
||||
} else {
|
||||
state = nil
|
||||
}
|
||||
if state != nil { //全局语法检查
|
||||
line, word = lex.Result(1), append(word, lex.Result(2))
|
||||
// if key := m.Find("lex").Cmd("parse", line, "key"); key.Resulti(0) == 0 || len(key.Result(2)) <= len(lex.Result(2)) {
|
||||
// } else {
|
||||
// state = nil
|
||||
// }
|
||||
}
|
||||
|
||||
if state == nil {
|
||||
if state == nil { //嵌套语法递归解析
|
||||
for i := 0; i < yac.Capi("ncell"); i++ {
|
||||
if x := yac.mat[s][byte(i)]; i < m.Capi("nlang") && x != nil {
|
||||
m.Log("debug", nil, "%s|%d try(%d,%d): %v", m.Cap("label")[0:level], level, s, i, x)
|
||||
|
||||
if c, l, w := yac.parse(m, cli, i, void, line); l != line {
|
||||
m.Log("debug", nil, "%s|%d get(%d,%d): %v", m.Cap("label")[0:level], level, s, i, x)
|
||||
if l, w := yac.scan(m, i, void, line); l != line {
|
||||
line, word = l, append(word, w...)
|
||||
|
||||
cli, state = c, x
|
||||
state = x
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if state == nil {
|
||||
if state == nil { //语法切换
|
||||
s, star = star, 0
|
||||
continue
|
||||
}
|
||||
|
||||
if s, star, hash = state.next, state.star, state.hash; s == 0 {
|
||||
if s, star, hash = state.next, state.star, state.hash; s == 0 { //状态切换
|
||||
s, star = star, 0
|
||||
}
|
||||
}
|
||||
@ -354,20 +318,14 @@ func (yac *YAC) scan(m *ctx.Message, page int, void int, line string) (string, [
|
||||
if hash == 0 {
|
||||
word = word[:0]
|
||||
} else {
|
||||
if msg := m.Spawn(cli).Cmd(yac.hand[hash], word); msg.Hand {
|
||||
m.Log("debug", nil, "%s>%d set(%d): \033[31m%v\033[0m->\033[32m%v\033[0m",
|
||||
m.Cap("label")[0:level], level, hash, word, msg.Meta["result"])
|
||||
msg := m.Spawn().Add("detail", yac.hand[hash], word...)
|
||||
if m.Back(msg); msg.Hand {
|
||||
word = msg.Meta["result"]
|
||||
|
||||
m.Copy(msg, "append", "back", "return")
|
||||
if cli = msg.Target(); msg.Has("cli") {
|
||||
cli = msg.Data["cli"].(*ctx.Context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m.Log("debug", nil, "%s/%d %s(%d):", m.Cap("label")[0:level], level, yac.hand[hash], hash)
|
||||
m.Capi("level", -1)
|
||||
m.Log("fuck", nil, "return--%s-----%v", line, word)
|
||||
return line, word
|
||||
}
|
||||
|
||||
// }}}
|
||||
@ -549,13 +507,18 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
||||
m.Optioni("page", yac.page["line"])
|
||||
m.Optioni("void", yac.page["void"])
|
||||
|
||||
rest, word := m.Option("rest"), []string{}
|
||||
|
||||
data := make(chan []byte)
|
||||
m.Find("nfs").Call(func(nfs *ctx.Message) *ctx.Message {
|
||||
data := nfs.Appendv(nfs.Result(0)).([]byte)
|
||||
rest, word = yac.scan(m, m.Optioni("page"), m.Optioni("void"), rest+string(data))
|
||||
buf := nfs.Appendv(nfs.Result(0)).([]byte)
|
||||
data <- buf
|
||||
return nil
|
||||
}, "scan_file", arg[0], "脚本解析")
|
||||
|
||||
go func() {
|
||||
m.Optionv("data", data)
|
||||
line, word := yac.scan(m, m.Optioni("page"), m.Optioni("void"), "")
|
||||
m.Log("fuck", nil, "----%s---%v", line, word)
|
||||
}()
|
||||
}
|
||||
// }}}
|
||||
}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user