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/
|
@cp etc/shy.vim ~/.vim/syntax/
|
||||||
@touch etc/local.shy
|
@touch etc/local.shy
|
||||||
go install $(BENCH)
|
go install $(BENCH)
|
||||||
@md5 `which bench`
|
# @md5 `which bench`
|
||||||
@date
|
@date
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
scan_file etc/demo.shy
|
||||||
|
|
||||||
|
return
|
||||||
source etc/local.shy
|
source etc/local.shy
|
||||||
|
|
||||||
~aaa
|
~aaa
|
||||||
login root root
|
login root root
|
||||||
~web
|
~web
|
||||||
command add get "https://chat.shylinux.com"
|
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
|
return true
|
||||||
}
|
}
|
||||||
@ -739,15 +740,15 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
if !m.Caps("skip") {
|
if !m.Caps("skip") {
|
||||||
msg := m.Spawn(cli)
|
msg := m.Spawn(cli)
|
||||||
msg.Start(fmt.Sprintf("%s_%d_%s", key, msg.Optioni("level", msg.Capi("level")+1), arg[0]), "脚本文件", arg[0])
|
msg.Start(fmt.Sprintf("%s_%d_%s", key, msg.Optioni("level", msg.Capi("level")+1), arg[0]), "脚本文件", arg[0])
|
||||||
<-msg.Target().Exit
|
// <-msg.Target().Exit
|
||||||
m.Copy(msg, "result").Copy(msg, "append")
|
// m.Copy(msg, "result").Copy(msg, "append")
|
||||||
nfs := msg.Sesss("nfs")
|
// nfs := msg.Sesss("nfs")
|
||||||
nfs.Target().Close(nfs)
|
// nfs.Target().Close(nfs)
|
||||||
|
//
|
||||||
sub, _ := msg.Target().Server.(*CLI)
|
// sub, _ := msg.Target().Server.(*CLI)
|
||||||
if sub.target != msg.Target() {
|
// if sub.target != msg.Target() {
|
||||||
cli.target = sub.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) {
|
"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) {
|
"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, ""))
|
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{
|
Index: map[string]*ctx.Context{
|
||||||
"void": &ctx.Context{Name: "void",
|
"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
|
s, star = star, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Log("fucK", nil, "why %d", pos)
|
|
||||||
|
|
||||||
if pos == len(line) {
|
if pos == len(line) {
|
||||||
hash, pos, word = -1, 0, word[:0]
|
hash, pos, word = -1, 0, word[:0]
|
||||||
@ -430,10 +429,8 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
page = lex.index("npage", arg[1])
|
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]))
|
hash, rest, word := lex.scan(m, page, []byte(arg[0]))
|
||||||
m.Result(0, hash, string(rest), string(word))
|
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) {
|
"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 {
|
for {
|
||||||
buf := make([]byte, m.Confi("buffer_size"))
|
buf := make([]byte, m.Confi("buffer_size"))
|
||||||
n, e := in.Read(buf)
|
n, e := in.Read(buf)
|
||||||
if m.Assert(e); n == 0 {
|
if e != nil && e != io.EOF {
|
||||||
break
|
m.Assert(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = buf[0:n]
|
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.Put("append", m.Cap("nread"), buf)
|
||||||
m.Capi("nread", n)
|
m.Capi("nread", n)
|
||||||
m.Back(m)
|
m.Back(m)
|
||||||
|
if n == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
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) { // {{{
|
func (yac *YAC) scan(m *ctx.Message, page int, void int, line string) (string, []string) { // {{{
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hash, word := 0, []string{}
|
hash, word := 0, []string{}
|
||||||
for star, s := 0, page; s != 0 && len(line) > 0; {
|
for star, s := 0, page; s != 0 && len(line) > 0; {
|
||||||
line := m.Find("lex").Cmd("scan", line, yac.name(void)).Result(1)
|
line = m.Sesss("lex", "lex").Cmd("scan", line, yac.name(void)).Result(1)
|
||||||
lex := m.Find("lex").Cmd("scan", line, yac.name(s))
|
lex := m.Sesss("lex", "lex").Cmd("scan", line, yac.name(s))
|
||||||
|
|
||||||
if lex.Result(0) == "-1" {
|
if lex.Result(0) == "-1" { //加载数据
|
||||||
return line, word
|
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))
|
c := byte(lex.Resulti(0))
|
||||||
state := yac.mat[s][c]
|
state := yac.mat[s][c]
|
||||||
|
|
||||||
if state != nil {
|
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))
|
line, word = lex.Result(1), append(word, lex.Result(2))
|
||||||
} else {
|
// if key := m.Find("lex").Cmd("parse", line, "key"); key.Resulti(0) == 0 || len(key.Result(2)) <= len(lex.Result(2)) {
|
||||||
state = nil
|
// } else {
|
||||||
}
|
// state = nil
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if state == nil {
|
if state == nil { //嵌套语法递归解析
|
||||||
for i := 0; i < yac.Capi("ncell"); i++ {
|
for i := 0; i < yac.Capi("ncell"); i++ {
|
||||||
if x := yac.mat[s][byte(i)]; i < m.Capi("nlang") && x != nil {
|
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 l, w := yac.scan(m, i, void, line); l != line {
|
||||||
|
|
||||||
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...)
|
line, word = l, append(word, w...)
|
||||||
|
state = x
|
||||||
cli, state = c, x
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
if state == nil { //语法切换
|
||||||
}
|
|
||||||
|
|
||||||
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 = yac.Sess("lex").Cmd("parse", line, yac.name(void)).Result(1)
|
|
||||||
lex := yac.Sess("lex").Cmd("parse", line, yac.name(s))
|
|
||||||
|
|
||||||
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 {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if state == nil {
|
|
||||||
s, star = star, 0
|
s, star = star, 0
|
||||||
continue
|
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
|
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 {
|
if hash == 0 {
|
||||||
word = word[:0]
|
word = word[:0]
|
||||||
} else {
|
} else {
|
||||||
if msg := m.Spawn(cli).Cmd(yac.hand[hash], word); msg.Hand {
|
msg := m.Spawn().Add("detail", yac.hand[hash], word...)
|
||||||
m.Log("debug", nil, "%s>%d set(%d): \033[31m%v\033[0m->\033[32m%v\033[0m",
|
if m.Back(msg); msg.Hand {
|
||||||
m.Cap("label")[0:level], level, hash, word, msg.Meta["result"])
|
|
||||||
word = msg.Meta["result"]
|
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.Log("fuck", nil, "return--%s-----%v", line, word)
|
||||||
m.Capi("level", -1)
|
return line, word
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
@ -549,13 +507,18 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
m.Optioni("page", yac.page["line"])
|
m.Optioni("page", yac.page["line"])
|
||||||
m.Optioni("void", yac.page["void"])
|
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 {
|
m.Find("nfs").Call(func(nfs *ctx.Message) *ctx.Message {
|
||||||
data := nfs.Appendv(nfs.Result(0)).([]byte)
|
buf := nfs.Appendv(nfs.Result(0)).([]byte)
|
||||||
rest, word = yac.scan(m, m.Optioni("page"), m.Optioni("void"), rest+string(data))
|
data <- buf
|
||||||
return nil
|
return nil
|
||||||
}, "scan_file", arg[0], "脚本解析")
|
}, "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