forked from x/ContextOS
kid mod cli.source
This commit is contained in:
parent
bd5f8f3fc9
commit
ab99a138bd
@ -1,6 +1,7 @@
|
|||||||
|
source etc/demo.shy
|
||||||
|
return
|
||||||
~file1
|
~file1
|
||||||
history load hi.cmd
|
history load hi.cmd
|
||||||
return
|
|
||||||
scan_file etc/demo.shy
|
scan_file etc/demo.shy
|
||||||
echo "who"
|
echo "who"
|
||||||
~web
|
~web
|
||||||
|
@ -64,7 +64,7 @@ func (cli *CLI) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|||||||
"$": []string{"cache"},
|
"$": []string{"cache"},
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(arg) > 0 && arg[0] == "scan_file" {
|
if len(arg) > 0 && arg[0] == "source" {
|
||||||
return cli
|
return cli
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,8 +220,8 @@ func (cli *CLI) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{
|
func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||||
if len(arg) > 0 && arg[0] == "scan_file" {
|
if len(arg) > 0 && arg[0] == "source" {
|
||||||
yac := m.Find("yac")
|
yac := m.Sesss("yac")
|
||||||
if yac.Cap("status") != "start" {
|
if yac.Cap("status") != "start" {
|
||||||
yac.Target().Start(yac)
|
yac.Target().Start(yac)
|
||||||
yac.Cmd("train", "void", "void", "[\t ]+")
|
yac.Cmd("train", "void", "void", "[\t ]+")
|
||||||
@ -264,8 +264,9 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
yac.Cmd("train", "line", "line", "opt{", "mul{", "stm", "cmd", "}", "}", "mul{", ";", "\n", "#[^\n]*\n", "}")
|
yac.Cmd("train", "line", "line", "opt{", "mul{", "stm", "cmd", "}", "}", "mul{", ";", "\n", "#[^\n]*\n", "}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Options("scan_end", false)
|
||||||
m.Option("target", m.Target().Name)
|
m.Option("target", m.Target().Name)
|
||||||
yac = m.Find("yac")
|
yac = m.Sesss("yac")
|
||||||
yac.Call(func(cmd *ctx.Message) *ctx.Message {
|
yac.Call(func(cmd *ctx.Message) *ctx.Message {
|
||||||
if cmd.Detail(0) == "scan_end" {
|
if cmd.Detail(0) == "scan_end" {
|
||||||
m.Target().Close(m.Spawn())
|
m.Target().Close(m.Spawn())
|
||||||
@ -276,14 +277,14 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
m.Option("target", cli.target.Name)
|
m.Option("target", cli.target.Name)
|
||||||
if cmd.Has("return") {
|
if cmd.Has("return") {
|
||||||
m.Target().Close(m.Spawn())
|
m.Target().Close(m.Spawn())
|
||||||
cmd.Append("scan_file", false)
|
m.Options("scan_end", true)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, "parse", arg[1])
|
}, "parse", arg[1])
|
||||||
m.Cap("stream", yac.Target().Name)
|
m.Cap("stream", yac.Target().Name)
|
||||||
|
|
||||||
if arg[1] == "stdio" {
|
if arg[1] == "stdio" {
|
||||||
m.Spawn().Cmd("scan_file", "etc/init.shy")
|
m.Spawn().Cmd("source", "etc/init.shy")
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -315,40 +316,6 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
cli.Context.Exit = make(chan bool)
|
cli.Context.Exit = make(chan bool)
|
||||||
cli.Context.Master(cli.Context)
|
cli.Context.Master(cli.Context)
|
||||||
|
|
||||||
if m.Has("stdio") || len(arg) > 0 {
|
|
||||||
go func() {
|
|
||||||
cli.Caches["init.shy"] = &ctx.Cache{Name: "启动脚本", Value: "etc/init.shy", Help: "模块启动时自动运行的脚本"}
|
|
||||||
if m.Conf("yac", "yac"); len(arg) > 0 {
|
|
||||||
m.Cap("init.shy", arg[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
cli.nfs = m.Sesss("nfs", "nfs")
|
|
||||||
if m.Has("stdio") {
|
|
||||||
m.Spawn().Cmd("scan_file", m.Cap("stream", m.Cap("init.shy")))
|
|
||||||
cli.Context.Exit = make(chan bool)
|
|
||||||
m.Find("yac").Call(func(cmd *ctx.Message) *ctx.Message {
|
|
||||||
if cmd.Detail(0) == "scan_end" {
|
|
||||||
msg := m.Spawn()
|
|
||||||
cli.Exit <- true
|
|
||||||
m.Target().Close(msg)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Source(m.Target())
|
|
||||||
cmd.Target(m.Target())
|
|
||||||
cmd.Cmd()
|
|
||||||
return nil
|
|
||||||
}, "scan_file", m.Cap("stream", "stdio"))
|
|
||||||
} else {
|
|
||||||
if _, e := os.Stat(m.Cap("init.shy")); e == nil {
|
|
||||||
// m.Spawn().Cmd("scan_file", m.Cap("stream", m.Cap("init.shy")))
|
|
||||||
cli.nfs.Cmd("scan", m.Cap("stream", m.Cap("init.shy")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Deal(func(msg *ctx.Message, arg ...string) bool {
|
m.Deal(func(msg *ctx.Message, arg ...string) bool {
|
||||||
return !m.Caps("skip") || Index.Has(msg.Get("detail"), "command")
|
return !m.Caps("skip") || Index.Has(msg.Get("detail"), "command")
|
||||||
|
|
||||||
@ -827,7 +794,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Set("result", arg...)
|
m.Set("result", arg...)
|
||||||
} // }}}
|
} // }}}
|
||||||
}},
|
}},
|
||||||
"source": &ctx.Command{Name: "source file", Help: "运行脚本, file: 脚本文件名", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"source_old": &ctx.Command{Name: "source_old file", Help: "运行脚本, file: 脚本文件名", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
cli, ok := m.Source().Server.(*CLI) // {{{
|
cli, ok := m.Source().Server.(*CLI) // {{{
|
||||||
if !ok {
|
if !ok {
|
||||||
cli, ok = m.Target().Server.(*CLI)
|
cli, ok = m.Target().Server.(*CLI)
|
||||||
@ -934,17 +901,18 @@ 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{
|
"source": &ctx.Command{
|
||||||
Name: "scan_file filename [async [cli_name [cli_help]]",
|
Name: "source filename [async [cli_name [cli_help]]",
|
||||||
Help: "解析脚本, filename: 文件名, cli_name: 模块名, cli_help: 模块帮助",
|
Help: "解析脚本, filename: 文件名, cli_name: 模块名, cli_help: 模块帮助",
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) {
|
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) {
|
||||||
m.Start(m.Confx("cli_name", arg, 2), m.Confx("cli_help", arg, 3), key, arg[0])
|
m.Start(m.Confx("cli_name", arg, 2), m.Confx("cli_help", arg, 3), key, arg[0])
|
||||||
if len(arg) > 1 && arg[1] != "async" {
|
if len(arg) > 1 && arg[1] == "async" {
|
||||||
<-m.Target().Exit
|
return
|
||||||
sub := m.Target().Server.(*CLI)
|
|
||||||
cli.target = sub.target
|
|
||||||
}
|
}
|
||||||
|
<-m.Target().Exit
|
||||||
|
sub := m.Target().Server.(*CLI)
|
||||||
|
cli.target = sub.target
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
@ -227,9 +227,7 @@ func (c *Context) Close(m *Message, arg ...string) bool { // {{{
|
|||||||
delete(c.context.contexts, c.Name)
|
delete(c.context.contexts, c.Name)
|
||||||
c.context = nil
|
c.context = nil
|
||||||
if c.Exit != nil {
|
if c.Exit != nil {
|
||||||
m.Log("info", nil, "before exit<-")
|
|
||||||
c.Exit <- true
|
c.Exit <- true
|
||||||
m.Log("info", nil, "after exit<-")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -3405,6 +3403,9 @@ func Start(args ...string) {
|
|||||||
Pulse.Options("terminal_color", true)
|
Pulse.Options("terminal_color", true)
|
||||||
Pulse.Sesss("log", "log").Conf("bench.log", Pulse.Conf("bench.log"))
|
Pulse.Sesss("log", "log").Conf("bench.log", Pulse.Conf("bench.log"))
|
||||||
|
|
||||||
cli := Pulse.Find("cli").Cmd("scan_file", "stdio", "async")
|
Pulse.Sesss("nfs", "nfs")
|
||||||
|
Pulse.Sesss("yac", "yac")
|
||||||
|
Pulse.Sesss("lex", "lex")
|
||||||
|
cli := Pulse.Find("cli").Cmd("source", "stdio", "async")
|
||||||
<-cli.target.Exit
|
<-cli.target.Exit
|
||||||
}
|
}
|
||||||
|
@ -315,6 +315,7 @@ func (lex *LEX) scan(m *ctx.Message, page int, line []byte) (hash int, rest []by
|
|||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
func (lex *LEX) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{
|
func (lex *LEX) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{
|
||||||
|
lex.Message = m
|
||||||
c.Caches = map[string]*ctx.Cache{}
|
c.Caches = map[string]*ctx.Cache{}
|
||||||
c.Configs = map[string]*ctx.Config{}
|
c.Configs = map[string]*ctx.Config{}
|
||||||
|
|
||||||
@ -325,10 +326,7 @@ func (lex *LEX) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (lex *LEX) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
func (lex *LEX) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
||||||
if lex.Message = m; lex.Context == Index {
|
lex.Message = m
|
||||||
Pulse = m
|
|
||||||
}
|
|
||||||
lex.Context.Master(nil)
|
|
||||||
|
|
||||||
lex.Caches["ncell"] = &ctx.Cache{Name: "字符上限", Value: "128", Help: "字符集合的最大数量"}
|
lex.Caches["ncell"] = &ctx.Cache{Name: "字符上限", Value: "128", Help: "字符集合的最大数量"}
|
||||||
lex.Caches["nlang"] = &ctx.Cache{Name: "词法上限", Value: "32", Help: "词法集合的最大数量"}
|
lex.Caches["nlang"] = &ctx.Cache{Name: "词法上限", Value: "32", Help: "词法集合的最大数量"}
|
||||||
@ -380,12 +378,12 @@ func (lex *LEX) Close(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
case m.Target():
|
case m.Target():
|
||||||
case m.Source():
|
case m.Source():
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
var Pulse *ctx.Message
|
|
||||||
var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
||||||
Caches: map[string]*ctx.Cache{},
|
Caches: map[string]*ctx.Cache{},
|
||||||
Configs: map[string]*ctx.Config{},
|
Configs: map[string]*ctx.Config{},
|
||||||
|
@ -217,7 +217,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
log.module = map[string]map[string]bool{
|
log.module = map[string]map[string]bool{
|
||||||
"log": {"cmd": true},
|
"log": {"cmd": true},
|
||||||
"lex": {"cmd": true, "debug": true},
|
"lex": {"cmd": false, "debug": true},
|
||||||
"yac": {"cmd": true, "debug": true},
|
"yac": {"cmd": true, "debug": true},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,7 +519,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
line := ""
|
line := ""
|
||||||
for nfs.prompt(); bio.Scan(); nfs.prompt() {
|
for nfs.prompt(); !m.Options("scan_end") && bio.Scan(); nfs.prompt() {
|
||||||
text := bio.Text()
|
text := bio.Text()
|
||||||
m.Capi("nread", len(text))
|
m.Capi("nread", len(text))
|
||||||
|
|
||||||
|
@ -94,8 +94,8 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
default:
|
default:
|
||||||
x, ok := yac.page[word[i]]
|
x, ok := yac.page[word[i]]
|
||||||
if !ok {
|
if !ok {
|
||||||
if x = yac.Sess("lex").Cmd("parse", word[i], yac.name(s)).Resulti(0); x == 0 {
|
if x = m.Sesss("lex").Cmd("parse", word[i], yac.name(s)).Resulti(0); x == 0 {
|
||||||
x = yac.Sess("lex").Cmd("train", word[i], len(yac.mat[s]), yac.name(s)).Resulti(0)
|
x = m.Sesss("lex").Cmd("train", word[i], len(yac.mat[s]), yac.name(s)).Resulti(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c := byte(x)
|
c := byte(x)
|
||||||
@ -191,14 +191,14 @@ func (yac *YAC) parse(m *ctx.Message, page int, void int, line string, level int
|
|||||||
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; {
|
||||||
//解析空白
|
//解析空白
|
||||||
lex := m.Sesss("lex", "lex").Cmd("scan", line, yac.name(void))
|
lex := m.Sesss("lex").Cmd("scan", line, yac.name(void))
|
||||||
if lex.Result(0) == "-1" {
|
if lex.Result(0) == "-1" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
//解析单词
|
//解析单词
|
||||||
line = lex.Result(1)
|
line = lex.Result(1)
|
||||||
lex = m.Sesss("lex", "lex").Cmd("scan", line, yac.name(s))
|
lex = m.Sesss("lex").Cmd("scan", line, yac.name(s))
|
||||||
if lex.Result(0) == "-1" {
|
if lex.Result(0) == "-1" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -302,28 +302,33 @@ func (yac *YAC) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
yac.Message = m
|
yac.Message = m
|
||||||
|
|
||||||
if len(arg) > 0 && arg[0] == "parse" {
|
if len(arg) > 0 && arg[0] == "parse" {
|
||||||
|
lex := m.Sesss("lex")
|
||||||
|
if lex.Cap("status") != "start" {
|
||||||
|
lex.Target().Start(lex)
|
||||||
|
}
|
||||||
|
|
||||||
var out *ctx.Message
|
var out *ctx.Message
|
||||||
data := make(chan string, 1)
|
data := make(chan string, 1)
|
||||||
next := make(chan bool, 1)
|
next := make(chan bool, 1)
|
||||||
|
|
||||||
m.Options("scan_end", false)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
m.Option("scan_end", true)
|
m.Log("fuck", nil, "why %v", e)
|
||||||
|
// m.Target().Close(m.Spawn())
|
||||||
|
// m.Option("scan_end", true)
|
||||||
next <- true
|
next <- true
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//加载文件
|
//加载文件
|
||||||
nfs := m.Find("nfs").Call(func(buf *ctx.Message) *ctx.Message {
|
nfs := m.Sesss("nfs").Call(func(buf *ctx.Message) *ctx.Message {
|
||||||
out = buf
|
out = buf
|
||||||
data <- buf.Detail(0) + "; "
|
data <- buf.Detail(0) + "; "
|
||||||
<-next
|
<-next
|
||||||
return nil
|
return nil
|
||||||
}, "scan", arg[1], "", "扫描文件")
|
}, "scan", arg[1], "", "扫描文件")
|
||||||
|
|
||||||
m.Find("log").Cmd("silent", yac.Context.Name, "debug", true)
|
// m.Find("log").Cmd("silent", yac.Context.Name, "debug", true)
|
||||||
|
|
||||||
//解析循环
|
//解析循环
|
||||||
for m.Cap("stream", nfs.Target().Name); !m.Options("scan_end"); next <- true {
|
for m.Cap("stream", nfs.Target().Name); !m.Options("scan_end"); next <- true {
|
||||||
@ -428,15 +433,15 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
yac.hand[hash] = arg[1]
|
yac.hand[hash] = arg[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Sess("lex") == nil {
|
// if m.Sesss("lex") == nil {
|
||||||
lex := m.Sess("lex", "lex")
|
// lex := m.Sess("lex", "lex")
|
||||||
if lex.Cap("status") == "start" {
|
// if lex.Cap("status") == "start" {
|
||||||
lex.Start(yac.Context.Name+"lex", "语法词法")
|
// lex.Start(yac.Context.Name+"lex", "语法词法")
|
||||||
} else {
|
// } else {
|
||||||
lex.Target().Start(lex)
|
// lex.Target().Start(lex)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
yac.train(m, page, hash, arg[2:])
|
yac.train(m, page, hash, arg[2:])
|
||||||
yac.seed = append(yac.seed, &Seed{page, hash, arg[2:]})
|
yac.seed = append(yac.seed, &Seed{page, hash, arg[2:]})
|
||||||
yac.Cap("stream", fmt.Sprintf("%d,%s,%s", yac.Capi("nseed", 1), yac.Cap("npage"), yac.Cap("nhash")))
|
yac.Cap("stream", fmt.Sprintf("%d,%s,%s", yac.Capi("nseed", 1), yac.Cap("npage"), yac.Cap("nhash")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user