diff --git a/etc/init.shy b/etc/init.shy index 2ffa6955..ecaf1234 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -1,6 +1,7 @@ +source etc/demo.shy +return ~file1 history load hi.cmd -return scan_file etc/demo.shy echo "who" ~web diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 0b9aad99..039ccc27 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -64,7 +64,7 @@ func (cli *CLI) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{ "$": []string{"cache"}, } - if len(arg) > 0 && arg[0] == "scan_file" { + if len(arg) > 0 && arg[0] == "source" { 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 { // {{{ - if len(arg) > 0 && arg[0] == "scan_file" { - yac := m.Find("yac") + if len(arg) > 0 && arg[0] == "source" { + yac := m.Sesss("yac") if yac.Cap("status") != "start" { yac.Target().Start(yac) 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", "}") } + m.Options("scan_end", false) m.Option("target", m.Target().Name) - yac = m.Find("yac") + yac = m.Sesss("yac") yac.Call(func(cmd *ctx.Message) *ctx.Message { if cmd.Detail(0) == "scan_end" { 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) if cmd.Has("return") { m.Target().Close(m.Spawn()) - cmd.Append("scan_file", false) + m.Options("scan_end", true) } return nil }, "parse", arg[1]) m.Cap("stream", yac.Target().Name) if arg[1] == "stdio" { - m.Spawn().Cmd("scan_file", "etc/init.shy") + m.Spawn().Cmd("source", "etc/init.shy") } return false } @@ -315,40 +316,6 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{ cli.Context.Exit = make(chan bool) 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 { 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...) } // }}} }}, - "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) // {{{ if !ok { 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) { m.Echo("%s", strings.Join(arg, "")) }}, - "scan_file": &ctx.Command{ - Name: "scan_file filename [async [cli_name [cli_help]]", + "source": &ctx.Command{ + Name: "source filename [async [cli_name [cli_help]]", Help: "解析脚本, filename: 文件名, cli_name: 模块名, cli_help: 模块帮助", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { 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]) - if len(arg) > 1 && arg[1] != "async" { - <-m.Target().Exit - sub := m.Target().Server.(*CLI) - cli.target = sub.target + if len(arg) > 1 && arg[1] == "async" { + return } + <-m.Target().Exit + sub := m.Target().Server.(*CLI) + cli.target = sub.target } }}, }, diff --git a/src/contexts/ctx.go b/src/contexts/ctx.go index c2b6004b..c7aa21d3 100644 --- a/src/contexts/ctx.go +++ b/src/contexts/ctx.go @@ -227,9 +227,7 @@ func (c *Context) Close(m *Message, arg ...string) bool { // {{{ delete(c.context.contexts, c.Name) c.context = nil if c.Exit != nil { - m.Log("info", nil, "before exit<-") c.Exit <- true - m.Log("info", nil, "after exit<-") } } return true @@ -3405,6 +3403,9 @@ func Start(args ...string) { Pulse.Options("terminal_color", true) 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 } diff --git a/src/contexts/lex/lex.go b/src/contexts/lex/lex.go index 9bb8d0a1..3a18c0cd 100644 --- a/src/contexts/lex/lex.go +++ b/src/contexts/lex/lex.go @@ -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 { // {{{ + lex.Message = m c.Caches = map[string]*ctx.Cache{} 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 { // {{{ - if lex.Message = m; lex.Context == Index { - Pulse = m - } - lex.Context.Master(nil) + lex.Message = m lex.Caches["ncell"] = &ctx.Cache{Name: "字符上限", Value: "128", 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.Source(): } + return false return true } // }}} -var Pulse *ctx.Message var Index = &ctx.Context{Name: "lex", Help: "词法中心", Caches: map[string]*ctx.Cache{}, Configs: map[string]*ctx.Config{}, diff --git a/src/contexts/log/log.go b/src/contexts/log/log.go index 957d46b6..57d89bf7 100644 --- a/src/contexts/log/log.go +++ b/src/contexts/log/log.go @@ -217,7 +217,7 @@ func init() { } log.module = map[string]map[string]bool{ "log": {"cmd": true}, - "lex": {"cmd": true, "debug": true}, + "lex": {"cmd": false, "debug": true}, "yac": {"cmd": true, "debug": true}, } } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 87415aad..f3028acb 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -519,7 +519,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{ } line := "" - for nfs.prompt(); bio.Scan(); nfs.prompt() { + for nfs.prompt(); !m.Options("scan_end") && bio.Scan(); nfs.prompt() { text := bio.Text() m.Capi("nread", len(text)) diff --git a/src/contexts/yac/yac.go b/src/contexts/yac/yac.go index 68671414..6f96a26a 100644 --- a/src/contexts/yac/yac.go +++ b/src/contexts/yac/yac.go @@ -94,8 +94,8 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po default: x, ok := yac.page[word[i]] if !ok { - if x = yac.Sess("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) + if x = m.Sesss("lex").Cmd("parse", word[i], yac.name(s)).Resulti(0); x == 0 { + x = m.Sesss("lex").Cmd("train", word[i], len(yac.mat[s]), yac.name(s)).Resulti(0) } } 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{} 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" { break } //解析单词 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" { break } @@ -302,28 +302,33 @@ func (yac *YAC) Start(m *ctx.Message, arg ...string) bool { // {{{ yac.Message = m if len(arg) > 0 && arg[0] == "parse" { + lex := m.Sesss("lex") + if lex.Cap("status") != "start" { + lex.Target().Start(lex) + } var out *ctx.Message data := make(chan string, 1) next := make(chan bool, 1) - m.Options("scan_end", false) defer func() { 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 } }() //加载文件 - nfs := m.Find("nfs").Call(func(buf *ctx.Message) *ctx.Message { + nfs := m.Sesss("nfs").Call(func(buf *ctx.Message) *ctx.Message { out = buf data <- buf.Detail(0) + "; " <-next return nil }, "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 { @@ -428,15 +433,15 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", yac.hand[hash] = arg[1] } - if m.Sess("lex") == nil { - lex := m.Sess("lex", "lex") - if lex.Cap("status") == "start" { - lex.Start(yac.Context.Name+"lex", "语法词法") - } else { - lex.Target().Start(lex) - } - } - + // if m.Sesss("lex") == nil { + // lex := m.Sess("lex", "lex") + // if lex.Cap("status") == "start" { + // lex.Start(yac.Context.Name+"lex", "语法词法") + // } else { + // lex.Target().Start(lex) + // } + // } + // yac.train(m, 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")))