mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
mac opt yac
This commit is contained in:
parent
dacd56cc9a
commit
5b11a6aa61
@ -8,8 +8,6 @@
|
|||||||
"加载插件"{{{
|
"加载插件"{{{
|
||||||
call plug#begin()
|
call plug#begin()
|
||||||
Plug 'vim-scripts/tComment'
|
Plug 'vim-scripts/tComment'
|
||||||
Plug 'gcmt/taboo.vim'
|
|
||||||
Plug 'vim-scripts/tComment'
|
|
||||||
Plug 'tpope/vim-fugitive'
|
Plug 'tpope/vim-fugitive'
|
||||||
Plug 'airblade/vim-gitgutter'
|
Plug 'airblade/vim-gitgutter'
|
||||||
Plug 'vim-airline/vim-airline'
|
Plug 'vim-airline/vim-airline'
|
||||||
@ -17,6 +15,9 @@ Plug 'vim-airline/vim-airline-themes'
|
|||||||
Plug 'ntpeters/vim-better-whitespace'
|
Plug 'ntpeters/vim-better-whitespace'
|
||||||
Plug 'easymotion/vim-easymotion'
|
Plug 'easymotion/vim-easymotion'
|
||||||
|
|
||||||
|
Plug 'gcmt/taboo.vim'
|
||||||
|
set sessionoptions+=tabpages,globals
|
||||||
|
|
||||||
Plug 'vim-scripts/taglist.vim'
|
Plug 'vim-scripts/taglist.vim'
|
||||||
let g:Tlist_WinWidth=45
|
let g:Tlist_WinWidth=45
|
||||||
let g:Tlist_Exit_OnlyWindow=1
|
let g:Tlist_Exit_OnlyWindow=1
|
||||||
|
@ -95,14 +95,14 @@ export EDITOR=vim
|
|||||||
alias RR="source ~/.zshrc"
|
alias RR="source ~/.zshrc"
|
||||||
|
|
||||||
alias t='tmux'
|
alias t='tmux'
|
||||||
alias v='vim'
|
alias d='docker'
|
||||||
alias g='git'
|
alias g='git'
|
||||||
|
alias v='vim'
|
||||||
|
|
||||||
bindkey -e
|
bindkey -e
|
||||||
bindkey jk accept-line
|
bindkey jk accept-line
|
||||||
bindkey "^N" down-line-or-beginning-search
|
bindkey "^N" down-line-or-beginning-search
|
||||||
bindkey "^P" up-line-or-beginning-search
|
bindkey "^P" up-line-or-beginning-search
|
||||||
|
|
||||||
bindkey -M vicmd j down-line-or-beginning-search
|
bindkey -M vicmd j down-line-or-beginning-search
|
||||||
bindkey -M vicmd k up-line-or-beginning-search
|
bindkey -M vicmd k up-line-or-beginning-search
|
||||||
|
|
||||||
|
@ -841,7 +841,21 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Add("append", "strings", bs[2][1:len(bs[2])-1])
|
m.Add("append", "strings", bs[2][1:len(bs[2])-1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Echo(m.Append("strings"))
|
|
||||||
|
if m.Option("index") == "" {
|
||||||
|
m.Option("index", 0)
|
||||||
|
}
|
||||||
|
m.Echo(m.Spawn().Cmd("system", "tmux", "show-buffer", "-b", m.Optioni("index")).Result(0))
|
||||||
|
}},
|
||||||
|
"parse": &ctx.Command{Name: "parse arg...", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
||||||
|
switch msg.Cmd().Detail(0) {
|
||||||
|
case "cmd":
|
||||||
|
m.Set("append").Copy(msg, "append").Set("result").Copy(msg, "result")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, "parse", "line", "void", arg)
|
||||||
|
m.Option("ps_target", m.Cap("ps_target"))
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Index: map[string]*ctx.Context{
|
Index: map[string]*ctx.Context{
|
||||||
|
@ -2367,7 +2367,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
m.Echo("%d", m.Spawn().code)
|
m.Echo("%d", m.Spawn().code)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
msg := m.Sess("cli", false)
|
msg := m.Search(m.Cap("ps_target"))[0]
|
||||||
|
msg = msg.target.message
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
if code, e := strconv.Atoi(arg[0]); e == nil {
|
if code, e := strconv.Atoi(arg[0]); e == nil {
|
||||||
if msg = m.root.Tree(code); msg != nil {
|
if msg = m.root.Tree(code); msg != nil {
|
||||||
|
@ -30,18 +30,17 @@ type LEX struct {
|
|||||||
state map[State]*State
|
state map[State]*State
|
||||||
char map[byte][]byte
|
char map[byte][]byte
|
||||||
|
|
||||||
*ctx.Message
|
|
||||||
*ctx.Context
|
*ctx.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lex *LEX) index(hash string, h string) int {
|
func (lex *LEX) index(m *ctx.Message, hash string, h string) int {
|
||||||
which := lex.page
|
which := lex.page
|
||||||
if hash == "nhash" {
|
if hash == "nhash" {
|
||||||
which = lex.hash
|
which = lex.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
if x, e := strconv.Atoi(h); e == nil {
|
if x, e := strconv.Atoi(h); e == nil {
|
||||||
lex.Assert(hash != "npage" || x < lex.Capi("npage"))
|
m.Assert(hash != "npage" || x < m.Capi("npage"))
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +48,8 @@ func (lex *LEX) index(hash string, h string) int {
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
which[h] = lex.Capi(hash, 1)
|
which[h] = m.Capi(hash, 1)
|
||||||
lex.Assert(hash != "npage" || lex.Capi("npage") < lex.Capi("nlang"))
|
m.Assert(hash != "npage" || m.Capi("npage") < m.Capi("nlang"))
|
||||||
return which[h]
|
return which[h]
|
||||||
}
|
}
|
||||||
func (lex *LEX) charset(c byte) []byte {
|
func (lex *LEX) charset(c byte) []byte {
|
||||||
@ -59,12 +58,12 @@ func (lex *LEX) charset(c byte) []byte {
|
|||||||
}
|
}
|
||||||
return []byte{c}
|
return []byte{c}
|
||||||
}
|
}
|
||||||
func (lex *LEX) train(page int, hash int, seed []byte) int {
|
func (lex *LEX) train(m *ctx.Message, page int, hash int, seed []byte) int {
|
||||||
|
|
||||||
ss := []int{page}
|
ss := []int{page}
|
||||||
cn := make([]bool, lex.Capi("ncell"))
|
cn := make([]bool, m.Capi("ncell"))
|
||||||
cc := make([]byte, 0, lex.Capi("ncell"))
|
cc := make([]byte, 0, m.Capi("ncell"))
|
||||||
sn := make([]bool, lex.Capi("nline"))
|
sn := make([]bool, m.Capi("nline"))
|
||||||
|
|
||||||
points := []*Point{}
|
points := []*Point{}
|
||||||
|
|
||||||
@ -122,8 +121,8 @@ func (lex *LEX) train(page int, hash int, seed []byte) int {
|
|||||||
cc = append(cc, seed[p])
|
cc = append(cc, seed[p])
|
||||||
}
|
}
|
||||||
|
|
||||||
lex.Log("debug", "page: \033[31m%d %v\033[0m", len(ss), ss)
|
m.Log("debug", "page: \033[31m%d %v\033[0m", len(ss), ss)
|
||||||
lex.Log("debug", "cell: \033[32m%d %v\033[0m", len(cc), cc)
|
m.Log("debug", "cell: \033[32m%d %v\033[0m", len(cc), cc)
|
||||||
|
|
||||||
flag := '\000'
|
flag := '\000'
|
||||||
if p+1 < len(seed) {
|
if p+1 < len(seed) {
|
||||||
@ -142,9 +141,9 @@ func (lex *LEX) train(page int, hash int, seed []byte) int {
|
|||||||
if lex.mat[s][c] != nil {
|
if lex.mat[s][c] != nil {
|
||||||
*state = *lex.mat[s][c]
|
*state = *lex.mat[s][c]
|
||||||
} else {
|
} else {
|
||||||
lex.Capi("nnode", 1)
|
m.Capi("nnode", 1)
|
||||||
}
|
}
|
||||||
lex.Log("debug", "GET(%d,%d): %v", s, c, state)
|
m.Log("debug", "GET(%d,%d): %v", s, c, state)
|
||||||
|
|
||||||
switch flag {
|
switch flag {
|
||||||
case '+':
|
case '+':
|
||||||
@ -157,9 +156,9 @@ func (lex *LEX) train(page int, hash int, seed []byte) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if state.next == 0 {
|
if state.next == 0 {
|
||||||
if line == 0 || !lex.Confs("compact") {
|
if line == 0 || !m.Confs("compact") {
|
||||||
lex.mat = append(lex.mat, make(map[byte]*State))
|
lex.mat = append(lex.mat, make(map[byte]*State))
|
||||||
line = lex.Capi("nline", 1) - 1
|
line = m.Capi("nline", 1) - 1
|
||||||
sn = append(sn, false)
|
sn = append(sn, false)
|
||||||
}
|
}
|
||||||
state.next = line
|
state.next = line
|
||||||
@ -168,7 +167,7 @@ func (lex *LEX) train(page int, hash int, seed []byte) int {
|
|||||||
|
|
||||||
lex.mat[s][c] = state
|
lex.mat[s][c] = state
|
||||||
points = append(points, &Point{s, c})
|
points = append(points, &Point{s, c})
|
||||||
lex.Log("debug", "SET(%d,%d): %v(%s,%s)", s, c, state, lex.Cap("nnode"), lex.Cap("nreal"))
|
m.Log("debug", "SET(%d,%d): %v(%s,%s)", s, c, state, m.Cap("nnode"), m.Cap("nreal"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,12 +180,12 @@ func (lex *LEX) train(page int, hash int, seed []byte) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
if s < lex.Capi("nlang") || s >= len(lex.mat) {
|
if s < m.Capi("nlang") || s >= len(lex.mat) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(lex.mat[s]) == 0 {
|
if len(lex.mat[s]) == 0 {
|
||||||
lex.Log("debug", "DEL: %d-%d", lex.Capi("nline")-1, lex.Capi("nline", 0, s))
|
m.Log("debug", "DEL: %d-%d", m.Capi("nline")-1, m.Capi("nline", 0, s))
|
||||||
lex.mat = lex.mat[:s]
|
lex.mat = lex.mat[:s]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,17 +196,17 @@ func (lex *LEX) train(page int, hash int, seed []byte) int {
|
|||||||
*state = *lex.mat[p.s][p.c]
|
*state = *lex.mat[p.s][p.c]
|
||||||
|
|
||||||
if state.next == s {
|
if state.next == s {
|
||||||
lex.Log("debug", "GET(%d, %d): %v", p.s, p.c, state)
|
m.Log("debug", "GET(%d, %d): %v", p.s, p.c, state)
|
||||||
if state.hash = hash; state.next >= len(lex.mat) {
|
if state.hash = hash; state.next >= len(lex.mat) {
|
||||||
state.next = 0
|
state.next = 0
|
||||||
}
|
}
|
||||||
lex.mat[p.s][p.c] = state
|
lex.mat[p.s][p.c] = state
|
||||||
lex.Log("debug", "SET(%d, %d): %v", p.s, p.c, state)
|
m.Log("debug", "SET(%d, %d): %v", p.s, p.c, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
if x, ok := lex.state[*state]; !ok {
|
if x, ok := lex.state[*state]; !ok {
|
||||||
lex.state[*state] = lex.mat[p.s][p.c]
|
lex.state[*state] = lex.mat[p.s][p.c]
|
||||||
lex.Capi("nreal", 1)
|
m.Capi("nreal", 1)
|
||||||
} else {
|
} else {
|
||||||
lex.mat[p.s][p.c] = x
|
lex.mat[p.s][p.c] = x
|
||||||
}
|
}
|
||||||
@ -232,7 +231,7 @@ func (lex *LEX) parse(m *ctx.Message, page int, line []byte) (hash int, rest []b
|
|||||||
}
|
}
|
||||||
|
|
||||||
state := lex.mat[s][c]
|
state := lex.mat[s][c]
|
||||||
lex.Log("debug", "(%d,%d): %v", s, c, state)
|
m.Log("debug", "(%d,%d): %v", s, c, state)
|
||||||
if state == nil {
|
if state == nil {
|
||||||
s, star, pos = star, 0, pos-1
|
s, star, pos = star, 0, pos-1
|
||||||
continue
|
continue
|
||||||
@ -259,8 +258,8 @@ func (lex *LEX) parse(m *ctx.Message, page int, line []byte) (hash int, rest []b
|
|||||||
rest = line[pos:]
|
rest = line[pos:]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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{}
|
||||||
|
|
||||||
@ -269,8 +268,6 @@ func (lex *LEX) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
func (lex *LEX) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
func (lex *LEX) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||||
lex.Message = m
|
|
||||||
|
|
||||||
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: "64", Help: "词法集合的最大数量"}
|
lex.Caches["nlang"] = &ctx.Cache{Name: "词法上限", Value: "64", Help: "词法集合的最大数量"}
|
||||||
|
|
||||||
@ -285,16 +282,16 @@ func (lex *LEX) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
|||||||
lex.Configs["compact"] = &ctx.Config{Name: "紧凑模式", Value: "true", Help: "词法状态的共用"}
|
lex.Configs["compact"] = &ctx.Config{Name: "紧凑模式", Value: "true", Help: "词法状态的共用"}
|
||||||
|
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
if _, e := strconv.Atoi(arg[0]); lex.Assert(e) {
|
if _, e := strconv.Atoi(arg[0]); m.Assert(e) {
|
||||||
lex.Cap("nlang", arg[0])
|
m.Cap("nlang", arg[0])
|
||||||
lex.Cap("nline", arg[0])
|
m.Cap("nline", arg[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lex.page = map[string]int{"nil": 0}
|
lex.page = map[string]int{"nil": 0}
|
||||||
lex.hash = map[string]int{"nil": 0}
|
lex.hash = map[string]int{"nil": 0}
|
||||||
|
|
||||||
lex.mat = make([]map[byte]*State, lex.Capi("nlang"))
|
lex.mat = make([]map[byte]*State, m.Capi("nlang"))
|
||||||
lex.state = make(map[State]*State)
|
lex.state = make(map[State]*State)
|
||||||
|
|
||||||
lex.char = map[byte][]byte{
|
lex.char = map[byte][]byte{
|
||||||
@ -309,7 +306,6 @@ func (lex *LEX) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
|||||||
return lex
|
return lex
|
||||||
}
|
}
|
||||||
func (lex *LEX) Start(m *ctx.Message, arg ...string) bool {
|
func (lex *LEX) Start(m *ctx.Message, arg ...string) bool {
|
||||||
lex.Message = m
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (lex *LEX) Close(m *ctx.Message, arg ...string) bool {
|
func (lex *LEX) Close(m *ctx.Message, arg ...string) bool {
|
||||||
@ -324,7 +320,10 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
Caches: map[string]*ctx.Cache{
|
Caches: map[string]*ctx.Cache{
|
||||||
"nmat": &ctx.Cache{Name: "nmat", Value: "0", Help: "nmat"},
|
"nmat": &ctx.Cache{Name: "nmat", Value: "0", Help: "nmat"},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ctx.Config{},
|
Configs: map[string]*ctx.Config{
|
||||||
|
"npage": &ctx.Config{Name: "npage", Value: "1", Help: "npage"},
|
||||||
|
"nhash": &ctx.Config{Name: "nhash", Value: "1", Help: "npage"},
|
||||||
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"spawn": &ctx.Command{Name: "spawn", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"spawn": &ctx.Command{Name: "spawn", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if _, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if _, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
@ -333,37 +332,34 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
}},
|
}},
|
||||||
"train": &ctx.Command{Name: "train seed [hash [page]", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"train": &ctx.Command{Name: "train seed [hash [page]", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
page, hash := 1, 1
|
page := lex.index(m, "npage", m.Confx("npage", arg, 2))
|
||||||
if len(arg) > 2 {
|
hash := lex.index(m, "nhash", m.Confx("nhash", arg, 1))
|
||||||
page = lex.index("npage", arg[2])
|
|
||||||
m.Assert(page < m.Capi("nlang"), "词法集合过多")
|
|
||||||
}
|
|
||||||
if len(arg) > 1 {
|
|
||||||
hash = lex.index("nhash", arg[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
if lex.mat[page] == nil {
|
if lex.mat[page] == nil {
|
||||||
lex.mat[page] = map[byte]*State{}
|
lex.mat[page] = map[byte]*State{}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Result(0, lex.train(page, hash, []byte(arg[0])))
|
m.Result(0, lex.train(m, page, hash, []byte(arg[0])))
|
||||||
lex.seed = append(lex.seed, &Seed{page, hash, arg[0]})
|
lex.seed = append(lex.seed, &Seed{page, hash, arg[0]})
|
||||||
lex.Cap("stream", fmt.Sprintf("%d,%s,%s", lex.Capi("nseed", 1), lex.Cap("npage"), lex.Cap("nhash")))
|
m.Cap("stream", fmt.Sprintf("%d,%s,%s", m.Capi("nseed", 1), m.Cap("npage"), m.Cap("nhash")))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"parse": &ctx.Command{Name: "parse line [page]", Help: "解析单词", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"parse": &ctx.Command{Name: "parse line [page]", Help: "解析单词", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
page := 1
|
page := lex.index(m, "npage", m.Confx("npage", arg, 1))
|
||||||
if len(arg) > 1 {
|
|
||||||
page = lex.index("npage", arg[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
hash, rest, word := lex.parse(m, page, []byte(arg[0]))
|
hash, rest, word := lex.parse(m, page, []byte(arg[0]))
|
||||||
m.Result(0, hash, string(rest), string(word))
|
m.Result(0, hash, string(rest), string(word))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"show": &ctx.Command{Name: "show info", Help: "查看信息", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"show": &ctx.Command{Name: "show seed|page|hash|mat", Help: "查看信息", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Append("seed", len(lex.seed))
|
||||||
|
m.Append("page", len(lex.page))
|
||||||
|
m.Append("hash", len(lex.hash))
|
||||||
|
m.Append("node", len(lex.state))
|
||||||
|
m.Table()
|
||||||
|
return
|
||||||
|
}
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "seed":
|
case "seed":
|
||||||
for _, v := range lex.seed {
|
for _, v := range lex.seed {
|
||||||
@ -391,7 +387,6 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
if s == nil {
|
if s == nil {
|
||||||
m.Add("append", fmt.Sprintf("%c", j), "")
|
m.Add("append", fmt.Sprintf("%c", j), "")
|
||||||
} else {
|
} else {
|
||||||
// m.Add("append", fmt.Sprintf("%c", j), fmt.Sprintf("(%t,%d,%d)", s.star, s.next, s.hash))
|
|
||||||
star := 0
|
star := 0
|
||||||
if s.star {
|
if s.star {
|
||||||
star = 1
|
star = 1
|
||||||
@ -406,7 +401,11 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
for i := 0; i < ncol-1; i++ {
|
for i := 0; i < ncol-1; i++ {
|
||||||
for j := i + 1; j < ncol; j++ {
|
for j := i + 1; j < ncol; j++ {
|
||||||
same := true
|
same := true
|
||||||
|
void := true
|
||||||
for n := 0; n < nrow; n++ {
|
for n := 0; n < nrow; n++ {
|
||||||
|
if m.Meta[m.Meta["append"][i]][n] != "" {
|
||||||
|
void = false
|
||||||
|
}
|
||||||
if m.Meta[m.Meta["append"][i]][n] != m.Meta[m.Meta["append"][j]][n] {
|
if m.Meta[m.Meta["append"][i]][n] != m.Meta[m.Meta["append"][j]][n] {
|
||||||
same = false
|
same = false
|
||||||
break
|
break
|
||||||
@ -414,9 +413,11 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
if same {
|
if same {
|
||||||
key = m.Meta["append"][i] + m.Meta["append"][j]
|
if !void {
|
||||||
m.Meta[key] = m.Meta[m.Meta["append"][i]]
|
key = m.Meta["append"][i] + m.Meta["append"][j]
|
||||||
m.Meta["append"][i] = key
|
m.Meta[key] = m.Meta[m.Meta["append"][i]]
|
||||||
|
m.Meta["append"][i] = key
|
||||||
|
}
|
||||||
for k := j; k < ncol-1; k++ {
|
for k := j; k < ncol-1; k++ {
|
||||||
m.Meta["append"][k] = m.Meta["append"][k+1]
|
m.Meta["append"][k] = m.Meta["append"][k+1]
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package log // {{{
|
package log
|
||||||
// }}}
|
|
||||||
import ( // {{{
|
import (
|
||||||
"contexts/ctx"
|
"contexts/ctx"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -8,34 +8,26 @@ import ( // {{{
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// }}}
|
|
||||||
|
|
||||||
type LOG struct {
|
type LOG struct {
|
||||||
nfs *ctx.Message
|
nfs *ctx.Message
|
||||||
out *os.File
|
out *os.File
|
||||||
|
|
||||||
*ctx.Context
|
*ctx.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (log *LOG) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{
|
func (log *LOG) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server {
|
||||||
c.Caches = map[string]*ctx.Cache{}
|
c.Caches = map[string]*ctx.Cache{}
|
||||||
c.Configs = map[string]*ctx.Config{}
|
c.Configs = map[string]*ctx.Config{}
|
||||||
|
|
||||||
s := new(LOG)
|
s := new(LOG)
|
||||||
s.Context = c
|
s.Context = c
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||||
// }}}
|
|
||||||
func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|
||||||
log.Configs["flag_color"] = &ctx.Config{Name: "flag_color", Value: "true", Help: "模块日志输出颜色"}
|
log.Configs["flag_color"] = &ctx.Config{Name: "flag_color", Value: "true", Help: "模块日志输出颜色"}
|
||||||
log.Configs["flag_time"] = &ctx.Config{Name: "flag_time", Value: "2006/01/02 15:04:05 ", Help: "模块日志输出颜色"}
|
log.Configs["flag_time"] = &ctx.Config{Name: "flag_time", Value: "2006/01/02 15:04:05 ", Help: "模块日志输出颜色"}
|
||||||
log.Configs["bench.log"] = &ctx.Config{Name: "bench.log", Value: "var/bench.log", Help: "模块日志输出的文件"}
|
log.Configs["bench.log"] = &ctx.Config{Name: "bench.log", Value: "var/bench.log", Help: "模块日志输出的文件"}
|
||||||
return log
|
return log
|
||||||
}
|
}
|
||||||
|
func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
|
||||||
// }}}
|
|
||||||
func (log *LOG) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|
||||||
if f, e := os.Stat(m.Confx("bench.log", arg, 0)); e == nil && !f.IsDir() {
|
if f, e := os.Stat(m.Confx("bench.log", arg, 0)); e == nil && !f.IsDir() {
|
||||||
log.nfs = m.Sess("nfs").Cmd("append", m.Confx("bench.log", arg, 0), "", "日志文件")
|
log.nfs = m.Sess("nfs").Cmd("append", m.Confx("bench.log", arg, 0), "", "日志文件")
|
||||||
log.out = log.nfs.Optionv("out").(*os.File)
|
log.out = log.nfs.Optionv("out").(*os.File)
|
||||||
@ -43,9 +35,7 @@ func (log *LOG) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
func (log *LOG) Close(m *ctx.Message, arg ...string) bool {
|
||||||
// }}}
|
|
||||||
func (log *LOG) Close(m *ctx.Message, arg ...string) bool { // {{{
|
|
||||||
switch log.Context {
|
switch log.Context {
|
||||||
case m.Target():
|
case m.Target():
|
||||||
case m.Source():
|
case m.Source():
|
||||||
@ -53,8 +43,6 @@ func (log *LOG) Close(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
|
|
||||||
var Pulse *ctx.Message
|
var Pulse *ctx.Message
|
||||||
var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||||
Caches: map[string]*ctx.Cache{
|
Caches: map[string]*ctx.Cache{
|
||||||
@ -63,9 +51,10 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
|||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"silent": &ctx.Config{Name: "silent", Value: map[string]interface{}{"cb": true, "find": true}, Help: "日志屏蔽类型"},
|
"silent": &ctx.Config{Name: "silent", Value: map[string]interface{}{"cb": true, "find": true}, Help: "日志屏蔽类型"},
|
||||||
"module": &ctx.Config{Name: "module", Value: map[string]interface{}{
|
"module": &ctx.Config{Name: "module", Value: map[string]interface{}{
|
||||||
"log": map[string]interface{}{"cmd": true},
|
"log": map[string]interface{}{"cmd": true},
|
||||||
"lex": map[string]interface{}{"cmd": true, "debug": true},
|
"lex": map[string]interface{}{"cmd": true, "debug": true},
|
||||||
"yac": map[string]interface{}{"cmd": true, "debug": true},
|
"yac": map[string]interface{}{"cmd": true, "debug": true},
|
||||||
|
"matrix1": map[string]interface{}{"cmd": true, "debug": true},
|
||||||
}, Help: "日志屏蔽模块"},
|
}, Help: "日志屏蔽模块"},
|
||||||
"color": &ctx.Config{Name: "color", Value: map[string]interface{}{
|
"color": &ctx.Config{Name: "color", Value: map[string]interface{}{
|
||||||
"debug": 0, "error": 31, "check": 31,
|
"debug": 0, "error": 31, "check": 31,
|
||||||
@ -79,11 +68,10 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
|||||||
"open": &ctx.Command{Name: "open file", Help: "打开日志文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"open": &ctx.Command{Name: "open file", Help: "打开日志文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
}},
|
}},
|
||||||
"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) && log.out != nil { // {{{
|
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) && log.out != nil {
|
||||||
if m.Confs("silent", arg[0]) {
|
if m.Confs("silent", arg[0]) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, ok := m.Optionv("msg").(*ctx.Message)
|
msg, ok := m.Optionv("msg").(*ctx.Message)
|
||||||
if !ok {
|
if !ok {
|
||||||
msg = m
|
msg = m
|
||||||
@ -91,22 +79,22 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
|||||||
if m.Confs("module", fmt.Sprintf("%s.%s", msg.Target().Name, arg[0])) {
|
if m.Confs("module", fmt.Sprintf("%s.%s", msg.Target().Name, arg[0])) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
color := 0
|
color := 0
|
||||||
if m.Confs("flag_color") && m.Confs("color", arg[0]) {
|
if m.Confs("flag_color") && m.Confs("color", arg[0]) {
|
||||||
color = m.Confi("color", arg[0])
|
color = m.Confi("color", arg[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
date := time.Now().Format(m.Conf("flag_time"))
|
date := time.Now().Format(m.Conf("flag_time"))
|
||||||
action := fmt.Sprintf("%d %s(%s->%s)", msg.Code(), arg[0], msg.Source().Name, msg.Target().Name)
|
action := fmt.Sprintf("%d %s(%s->%s)", msg.Code(), arg[0], msg.Source().Name, msg.Target().Name)
|
||||||
cmd := strings.Join(arg[1:], "")
|
cmd := strings.Join(arg[1:], "")
|
||||||
|
|
||||||
if color > 0 {
|
if color > 0 {
|
||||||
log.out.WriteString(fmt.Sprintf("%s\033[%dm%s %s\033[0m\n", date, color, action, cmd))
|
log.out.WriteString(fmt.Sprintf("%s\033[%dm%s %s\033[0m\n", date, color, action, cmd))
|
||||||
} else {
|
} else {
|
||||||
log.out.WriteString(fmt.Sprintf("%s%s %s\n", date, action, cmd))
|
log.out.WriteString(fmt.Sprintf("%s%s %s\n", date, action, cmd))
|
||||||
}
|
}
|
||||||
} // }}}
|
}
|
||||||
|
}},
|
||||||
|
"pwd": &ctx.Command{Name: "pwd", Help: "打开日志文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
m.Echo("nice")
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -288,60 +288,45 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"display_result": "",
|
"display_result": "",
|
||||||
"result_reload": "10",
|
"result_reload": "10",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "tail", "help": "tail", "template": "tail",
|
||||||
"name": "tail", "help": "tail", "template": "tail",
|
"context": "", "command": "", "arguments": []interface{}{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"index": []interface{}{
|
"index": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "head", "help": "head", "template": "head",
|
||||||
"name": "head", "help": "head", "template": "head",
|
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
"context": "", "command": "", "arguments": []interface{}{},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "clipbaord", "help": "clipbaord", "template": "clipboard",
|
||||||
"name": "clipbaord", "help": "clipbaord", "template": "clipboard",
|
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
"context": "", "command": "", "arguments": []interface{}{},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "buffer", "help": "buffer", "template": "componet",
|
||||||
"name": "matrix", "help": "matrix", "template": "componet",
|
|
||||||
"context": "lex", "command": "show", "arguments": []interface{}{"@info"},
|
|
||||||
"inputs": []interface{}{
|
|
||||||
map[string]interface{}{
|
|
||||||
"type": "choice", "name": "info",
|
|
||||||
"label": "info", "value": "seed",
|
|
||||||
"choice": []interface{}{
|
|
||||||
map[string]interface{}{
|
|
||||||
"name": "seed", "value": "seed",
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"name": "page", "value": "page",
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"name": "hash", "value": "hash",
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"name": "mat", "value": "mat",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"display_result": "",
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"name": "message", "help": "message", "template": "componet",
|
|
||||||
"context": "cli", "command": "buffer", "arguments": []interface{}{},
|
"context": "cli", "command": "buffer", "arguments": []interface{}{},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"type": "text", "name": "limit",
|
"type": "text", "name": "limit",
|
||||||
"label": "limit", "value": "3",
|
"label": "limit", "value": "3",
|
||||||
},
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"type": "text", "name": "index",
|
||||||
|
"label": "index", "value": "0",
|
||||||
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"type": "button", "name": "refresh",
|
"type": "button", "name": "refresh",
|
||||||
"label": "refresh", "value": "refresh",
|
"label": "refresh", "value": "refresh",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "command", "help": "command", "template": "componet",
|
||||||
"name": "time", "help": "time", "template": "componet",
|
"context": "cli.shell1", "command": "parse", "arguments": []interface{}{"@cmd"},
|
||||||
|
"inputs": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"type": "text", "name": "cmd",
|
||||||
|
"label": "cmd", "value": "",
|
||||||
|
"class": "cmd", "clipstack": "clistack",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]interface{}{"name": "time", "help": "time", "template": "componet",
|
||||||
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
@ -358,8 +343,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "json", "help": "json", "template": "componet",
|
||||||
"name": "json", "help": "json", "template": "componet",
|
|
||||||
"context": "nfs", "command": "json",
|
"context": "nfs", "command": "json",
|
||||||
"arguments": []interface{}{"@string"},
|
"arguments": []interface{}{"@string"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
@ -373,8 +357,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "dir", "help": "dir", "template": "componet",
|
||||||
"name": "dir", "help": "dir", "template": "componet",
|
|
||||||
"context": "nfs", "command": "dir",
|
"context": "nfs", "command": "dir",
|
||||||
"arguments": []interface{}{"@dir",
|
"arguments": []interface{}{"@dir",
|
||||||
"dir_deep", "no",
|
"dir_deep", "no",
|
||||||
@ -426,7 +409,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"type": "choice", "name": "sort_order",
|
"type": "choice", "name": "sort_order",
|
||||||
"label": "sort_order", "value": "time",
|
"label": "sort_order", "value": "time_r",
|
||||||
"choice": []interface{}{
|
"choice": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"name": "str", "value": "str",
|
"name": "str", "value": "str",
|
||||||
@ -458,8 +441,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "web_site", "help": "web_site", "template": "componet",
|
||||||
"name": "web_site", "help": "web_site", "template": "componet",
|
|
||||||
"context": "web", "command": "config",
|
"context": "web", "command": "config",
|
||||||
"arguments": []interface{}{
|
"arguments": []interface{}{
|
||||||
"web_site",
|
"web_site",
|
||||||
@ -467,8 +449,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
"display_result": "",
|
"display_result": "",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{"name": "tail", "help": "tail", "template": "tail",
|
||||||
"name": "tail", "help": "tail", "template": "tail",
|
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
"context": "", "command": "", "arguments": []interface{}{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package yac // {{{
|
package yac
|
||||||
// }}}
|
|
||||||
import ( // {{{
|
import (
|
||||||
"contexts/ctx"
|
"contexts/ctx"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// }}}
|
|
||||||
|
|
||||||
type Seed struct {
|
type Seed struct {
|
||||||
page int
|
page int
|
||||||
hash int
|
hash int
|
||||||
@ -22,10 +21,8 @@ type Point struct {
|
|||||||
s int
|
s int
|
||||||
c byte
|
c byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type YAC struct {
|
type YAC struct {
|
||||||
seed []*Seed
|
seed []*Seed
|
||||||
|
|
||||||
page map[string]int
|
page map[string]int
|
||||||
word map[int]string
|
word map[int]string
|
||||||
hash map[string]int
|
hash map[string]int
|
||||||
@ -38,21 +35,16 @@ type YAC struct {
|
|||||||
*ctx.Context
|
*ctx.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (yac *YAC) name(page int) string { // {{{
|
func (yac *YAC) name(page int) string {
|
||||||
if name, ok := yac.word[page]; ok {
|
if name, ok := yac.word[page]; ok {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("yac%d", page)
|
return fmt.Sprintf("yac%d", page)
|
||||||
}
|
}
|
||||||
|
func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Point, []*Point) {
|
||||||
// }}}
|
|
||||||
func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Point, []*Point) { // {{{
|
|
||||||
|
|
||||||
ss := []int{page}
|
ss := []int{page}
|
||||||
sn := make([]bool, m.Capi("nline"))
|
sn := make([]bool, m.Capi("nline"))
|
||||||
|
points, ends := []*Point{}, []*Point{}
|
||||||
points := []*Point{}
|
|
||||||
ends := []*Point{}
|
|
||||||
|
|
||||||
for i, n, mul := 0, 1, false; i < len(word); i += n {
|
for i, n, mul := 0, 1, false; i < len(word); i += n {
|
||||||
if !mul {
|
if !mul {
|
||||||
@ -68,6 +60,7 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
sn[s] = true
|
sn[s] = true
|
||||||
num, point, end := yac.train(m, s, 0, word[i+1:])
|
num, point, end := yac.train(m, s, 0, word[i+1:])
|
||||||
n, points = num, append(points, point...)
|
n, points = num, append(points, point...)
|
||||||
|
|
||||||
for _, x := range end {
|
for _, x := range end {
|
||||||
state := &State{}
|
state := &State{}
|
||||||
*state = *yac.mat[x.s][x.c]
|
*state = *yac.mat[x.s][x.c]
|
||||||
@ -75,8 +68,8 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
sn = append(sn, false)
|
sn = append(sn, false)
|
||||||
}
|
}
|
||||||
sn[state.next] = true
|
sn[state.next] = true
|
||||||
points = append(points, x)
|
|
||||||
|
|
||||||
|
points = append(points, x)
|
||||||
if word[i] == "rep{" {
|
if word[i] == "rep{" {
|
||||||
state.star = s
|
state.star = s
|
||||||
yac.mat[x.s][x.c] = state
|
yac.mat[x.s][x.c] = state
|
||||||
@ -95,12 +88,12 @@ 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 = m.Sess("lex").Cmd("parse", word[i], yac.name(s)).Resulti(0); x == 0 {
|
if x = yac.lex.Spawn().Cmd("parse", word[i], yac.name(s)).Resulti(0); x == 0 {
|
||||||
x = m.Sess("lex").Cmd("train", word[i], len(yac.mat[s]), yac.name(s)).Resulti(0)
|
x = yac.lex.Spawn().Cmd("train", word[i], len(yac.mat[s]), yac.name(s)).Resulti(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c := byte(x)
|
|
||||||
|
|
||||||
|
c := byte(x)
|
||||||
state := &State{}
|
state := &State{}
|
||||||
if yac.mat[s][c] != nil {
|
if yac.mat[s][c] != nil {
|
||||||
*state = *yac.mat[s][c]
|
*state = *yac.mat[s][c]
|
||||||
@ -108,7 +101,6 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
m.Capi("nnode", 1)
|
m.Capi("nnode", 1)
|
||||||
}
|
}
|
||||||
m.Log("debug", "GET(%d, %d): %v \033[31m(%s)\033[0m", s, c, state, word[i])
|
m.Log("debug", "GET(%d, %d): %v \033[31m(%s)\033[0m", s, c, state, word[i])
|
||||||
|
|
||||||
if state.next == 0 {
|
if state.next == 0 {
|
||||||
state.next = m.Capi("nline", 1) - 1
|
state.next = m.Capi("nline", 1) - 1
|
||||||
yac.mat = append(yac.mat, map[byte]*State{})
|
yac.mat = append(yac.mat, map[byte]*State{})
|
||||||
@ -119,13 +111,11 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
}
|
}
|
||||||
sn[state.next] = true
|
sn[state.next] = true
|
||||||
yac.mat[s][c] = state
|
yac.mat[s][c] = state
|
||||||
|
|
||||||
ends = append(ends, &Point{s, c})
|
ends = append(ends, &Point{s, c})
|
||||||
points = append(points, &Point{s, c})
|
points = append(points, &Point{s, c})
|
||||||
m.Log("debug", "SET(%d, %d): %v", s, c, state)
|
m.Log("debug", "SET(%d, %d): %v", s, c, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next:
|
next:
|
||||||
if !mul {
|
if !mul {
|
||||||
ss = ss[:0]
|
ss = ss[:0]
|
||||||
@ -136,12 +126,10 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
if s < m.Capi("nlang") || s >= len(yac.mat) {
|
if s < m.Capi("nlang") || s >= len(yac.mat) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
void := true
|
void := true
|
||||||
for _, x := range yac.mat[s] {
|
for _, x := range yac.mat[s] {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
@ -149,18 +137,15 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if void {
|
if void {
|
||||||
m.Log("debug", "DEL: %d-%d", m.Capi("nline")-1, m.Capi("nline", 0, s))
|
m.Log("debug", "DEL: %d-%d", m.Capi("nline")-1, m.Capi("nline", 0, s))
|
||||||
yac.mat = yac.mat[:s]
|
yac.mat = yac.mat[:s]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
for _, p := range points {
|
for _, p := range points {
|
||||||
state := &State{}
|
state := &State{}
|
||||||
*state = *yac.mat[p.s][p.c]
|
*state = *yac.mat[p.s][p.c]
|
||||||
|
|
||||||
if state.next == s {
|
if state.next == s {
|
||||||
m.Log("debug", "GET(%d, %d): %v", p.s, p.c, state)
|
m.Log("debug", "GET(%d, %d): %v", p.s, p.c, state)
|
||||||
if state.next >= len(yac.mat) {
|
if state.next >= len(yac.mat) {
|
||||||
@ -172,7 +157,6 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
yac.mat[p.s][p.c] = state
|
yac.mat[p.s][p.c] = state
|
||||||
m.Log("debug", "SET(%d, %d): %v", p.s, p.c, state)
|
m.Log("debug", "SET(%d, %d): %v", p.s, p.c, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
if x, ok := yac.state[*state]; !ok {
|
if x, ok := yac.state[*state]; !ok {
|
||||||
yac.state[*state] = yac.mat[p.s][p.c]
|
yac.state[*state] = yac.mat[p.s][p.c]
|
||||||
m.Capi("nreal", 1)
|
m.Capi("nreal", 1)
|
||||||
@ -181,47 +165,37 @@ func (yac *YAC) train(m *ctx.Message, page, hash int, word []string) (int, []*Po
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(word), points, ends
|
return len(word), points, ends
|
||||||
}
|
}
|
||||||
|
func (yac *YAC) parse(m *ctx.Message, out *ctx.Message, page int, void int, line string, level int) (string, []string, int) {
|
||||||
// }}}
|
|
||||||
func (yac *YAC) parse(m *ctx.Message, out *ctx.Message, page int, void int, line string, level int) (string, []string, int) { // {{{
|
|
||||||
if m.Confs("debug") {
|
if m.Confs("debug") {
|
||||||
m.Log("debug", "%s\\%d %s(%d): %s", m.Conf("label")[0:level], level, yac.name(page), page, line)
|
m.Log("debug", "%s\\%d %s(%d): %s", m.Conf("label")[0:level], level, yac.name(page), page, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn := !m.Confs("compact_lex")
|
|
||||||
|
|
||||||
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.Sess("lex", spawn)
|
lex := yac.lex.Spawn()
|
||||||
if lex.Cmd("parse", line, yac.name(void)); lex.Result(0) == "-1" {
|
if lex.Cmd("parse", line, yac.name(void)); lex.Result(0) == "-1" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
//解析单词
|
//解析单词
|
||||||
line = lex.Result(1)
|
line = lex.Result(1)
|
||||||
lex = m.Sess("lex", spawn)
|
lex = yac.lex.Spawn()
|
||||||
if lex.Cmd("parse", line, yac.name(s)); lex.Result(0) == "-1" {
|
if lex.Cmd("parse", line, yac.name(s)); lex.Result(0) == "-1" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
//解析状态
|
//解析状态
|
||||||
result := append([]string{}, lex.Meta["result"]...)
|
result := append([]string{}, lex.Meta["result"]...)
|
||||||
i, _ := strconv.Atoi(result[0])
|
i, _ := strconv.Atoi(result[0])
|
||||||
c := byte(i)
|
c := byte(i)
|
||||||
state := yac.mat[s][c]
|
state := yac.mat[s][c]
|
||||||
|
|
||||||
if state != nil { //全局语法检查
|
if state != nil { //全局语法检查
|
||||||
if key := m.Sess("lex", spawn).Cmd("parse", line, "key"); key.Resulti(0) == 0 || len(key.Result(2)) <= len(result[2]) {
|
if key := yac.lex.Spawn().Cmd("parse", line, "key"); key.Resulti(0) == 0 || len(key.Result(2)) <= len(result[2]) {
|
||||||
line, word = result[1], append(word, result[2])
|
line, word = result[1], append(word, result[2])
|
||||||
} else {
|
} else {
|
||||||
state = nil
|
state = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if state == nil { //嵌套语法递归解析
|
if state == nil { //嵌套语法递归解析
|
||||||
for i := 0; i < m.Capi("ncell"); i++ {
|
for i := 0; i < m.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 {
|
||||||
@ -233,17 +207,14 @@ func (yac *YAC) parse(m *ctx.Message, out *ctx.Message, page int, void int, line
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if state == nil { //语法切换
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if hash == 0 {
|
if hash == 0 {
|
||||||
word = word[:0]
|
word = word[:0]
|
||||||
} else if out != nil { //执行命令
|
} else if out != nil { //执行命令
|
||||||
@ -253,20 +224,15 @@ func (yac *YAC) parse(m *ctx.Message, out *ctx.Message, page int, void int, line
|
|||||||
word = msg.Meta["result"]
|
word = msg.Meta["result"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Confs("debug") {
|
if m.Confs("debug") {
|
||||||
m.Log("debug", "%s/%d %s(%d): %v", m.Conf("label")[0:level], level, yac.name(page), page, word)
|
m.Log("debug", "%s/%d %s(%d): %v", m.Conf("label")[0:level], level, yac.name(page), page, word)
|
||||||
}
|
}
|
||||||
|
|
||||||
return line, word, hash
|
return line, word, hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
func (yac *YAC) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server {
|
||||||
|
|
||||||
func (yac *YAC) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{
|
|
||||||
c.Caches = map[string]*ctx.Cache{}
|
c.Caches = map[string]*ctx.Cache{}
|
||||||
c.Configs = map[string]*ctx.Config{}
|
c.Configs = map[string]*ctx.Config{}
|
||||||
|
|
||||||
if len(arg) > 0 && arg[0] == "scan" {
|
if len(arg) > 0 && arg[0] == "scan" {
|
||||||
return yac
|
return yac
|
||||||
}
|
}
|
||||||
@ -275,9 +241,7 @@ func (yac *YAC) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
|||||||
s.Context = c
|
s.Context = c
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
func (yac *YAC) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||||
// }}}
|
|
||||||
func (yac *YAC) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|
||||||
if len(arg) > 0 && arg[0] == "scan" {
|
if len(arg) > 0 && arg[0] == "scan" {
|
||||||
return yac
|
return yac
|
||||||
}
|
}
|
||||||
@ -287,7 +251,6 @@ func (yac *YAC) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|||||||
yac.Caches["nline"] = &ctx.Cache{Name: "状态数量", Value: m.Confx("nlang", arg, 1), Help: "状态机状态的数量"}
|
yac.Caches["nline"] = &ctx.Cache{Name: "状态数量", Value: m.Confx("nlang", arg, 1), Help: "状态机状态的数量"}
|
||||||
yac.Caches["nnode"] = &ctx.Cache{Name: "节点数量", Value: "0", Help: "状态机连接的逻辑数量"}
|
yac.Caches["nnode"] = &ctx.Cache{Name: "节点数量", Value: "0", Help: "状态机连接的逻辑数量"}
|
||||||
yac.Caches["nreal"] = &ctx.Cache{Name: "实点数量", Value: "0", Help: "状态机连接的存储数量"}
|
yac.Caches["nreal"] = &ctx.Cache{Name: "实点数量", Value: "0", Help: "状态机连接的存储数量"}
|
||||||
|
|
||||||
yac.Caches["nseed"] = &ctx.Cache{Name: "种子数量", Value: "0", Help: "语法模板的数量"}
|
yac.Caches["nseed"] = &ctx.Cache{Name: "种子数量", Value: "0", Help: "语法模板的数量"}
|
||||||
yac.Caches["npage"] = &ctx.Cache{Name: "集合数量", Value: "0", Help: "语法集合的数量"}
|
yac.Caches["npage"] = &ctx.Cache{Name: "集合数量", Value: "0", Help: "语法集合的数量"}
|
||||||
yac.Caches["nhash"] = &ctx.Cache{Name: "类型数量", Value: "0", Help: "语句类型的数量"}
|
yac.Caches["nhash"] = &ctx.Cache{Name: "类型数量", Value: "0", Help: "语句类型的数量"}
|
||||||
@ -299,22 +262,13 @@ func (yac *YAC) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|||||||
|
|
||||||
yac.mat = make([]map[byte]*State, m.Capi("nlang"))
|
yac.mat = make([]map[byte]*State, m.Capi("nlang"))
|
||||||
yac.state = map[State]*State{}
|
yac.state = map[State]*State{}
|
||||||
|
|
||||||
return yac
|
return yac
|
||||||
}
|
}
|
||||||
|
func (yac *YAC) Start(m *ctx.Message, arg ...string) (close bool) {
|
||||||
// }}}
|
|
||||||
func (yac *YAC) Start(m *ctx.Message, arg ...string) (close bool) { // {{{
|
|
||||||
if len(arg) > 0 && arg[0] == "scan" {
|
if len(arg) > 0 && arg[0] == "scan" {
|
||||||
lex := m.Sess("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)
|
||||||
|
|
||||||
close = true
|
close = true
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
@ -322,7 +276,6 @@ func (yac *YAC) Start(m *ctx.Message, arg ...string) (close bool) { // {{{
|
|||||||
next <- true
|
next <- true
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//加载文件
|
//加载文件
|
||||||
nfs := m.Sess("nfs").Call(func(buf *ctx.Message) *ctx.Message {
|
nfs := m.Sess("nfs").Call(func(buf *ctx.Message) *ctx.Message {
|
||||||
out = buf
|
out = buf
|
||||||
@ -330,9 +283,7 @@ func (yac *YAC) Start(m *ctx.Message, arg ...string) (close bool) { // {{{
|
|||||||
<-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 {
|
||||||
line := <-data
|
line := <-data
|
||||||
@ -340,7 +291,6 @@ func (yac *YAC) Start(m *ctx.Message, arg ...string) (close bool) { // {{{
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, word, _ := yac.parse(m, out, m.Optioni("page"), m.Optioni("void"), line, 1)
|
_, word, _ := yac.parse(m, out, m.Optioni("page"), m.Optioni("void"), line, 1)
|
||||||
|
|
||||||
if len(word) > 0 {
|
if len(word) > 0 {
|
||||||
word = word[:len(word)-1]
|
word = word[:len(word)-1]
|
||||||
if last := len(word) - 1; last >= 0 && len(word[last]) > 0 && word[last][len(word[last])-1] != '\n' {
|
if last := len(word) - 1; last >= 0 && len(word[last]) > 0 && word[last][len(word[last])-1] != '\n' {
|
||||||
@ -351,12 +301,9 @@ func (yac *YAC) Start(m *ctx.Message, arg ...string) (close bool) { // {{{
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
func (yac *YAC) Close(m *ctx.Message, arg ...string) bool {
|
||||||
// }}}
|
|
||||||
func (yac *YAC) Close(m *ctx.Message, arg ...string) bool { // {{{
|
|
||||||
switch yac.Context {
|
switch yac.Context {
|
||||||
case m.Target():
|
case m.Target():
|
||||||
case m.Source():
|
case m.Source():
|
||||||
@ -364,8 +311,6 @@ func (yac *YAC) Close(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
|
|
||||||
var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
||||||
Caches: map[string]*ctx.Cache{
|
Caches: map[string]*ctx.Cache{
|
||||||
"nparse": &ctx.Cache{Name: "nparse", Value: "0", Help: "解析器数量"},
|
"nparse": &ctx.Cache{Name: "nparse", Value: "0", Help: "解析器数量"},
|
||||||
@ -376,72 +321,17 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
"ncell": &ctx.Config{Name: "词法上限", Value: "128", Help: "词法集合的最大数量"},
|
"ncell": &ctx.Config{Name: "词法上限", Value: "128", Help: "词法集合的最大数量"},
|
||||||
"nlang": &ctx.Config{Name: "语法上限", Value: "32", Help: "语法集合的最大数量"},
|
"nlang": &ctx.Config{Name: "语法上限", Value: "32", Help: "语法集合的最大数量"},
|
||||||
"label": &ctx.Config{Name: "嵌套标记", Value: "####################", Help: "嵌套层级日志的标记"},
|
"label": &ctx.Config{Name: "嵌套标记", Value: "####################", Help: "嵌套层级日志的标记"},
|
||||||
"yac_name": &ctx.Config{Name: "yac_name", Value: "parse", Help: "模块名", Hand: func(m *ctx.Message, x *ctx.Config, arg ...string) string {
|
|
||||||
if len(arg) > 0 { // {{{
|
|
||||||
return arg[0]
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s%d", x.Value, m.Capi("nparse", 1))
|
|
||||||
// }}}
|
|
||||||
}},
|
|
||||||
"yac_help": &ctx.Config{Name: "yac_help", Value: "解析模块", Help: "模块帮助"},
|
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"init": &ctx.Command{Name: "init [ncell [nlang]]", Help: "初始化语法矩阵", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
|
||||||
if _, ok := m.Target().Server.(*YAC); m.Assert(ok) { // {{{
|
|
||||||
s := new(YAC)
|
|
||||||
s.Context = m.Target()
|
|
||||||
m.Target().Server = s
|
|
||||||
m.Target().Begin(m, arg...)
|
|
||||||
}
|
|
||||||
// }}}
|
|
||||||
}},
|
|
||||||
"info": &ctx.Command{Name: "info", Help: "查看语法矩阵", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
|
||||||
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) { // {{{
|
|
||||||
if len(arg) == 0 {
|
|
||||||
for i, v := range yac.seed {
|
|
||||||
m.Echo("seed: %d %v\n", i, v)
|
|
||||||
}
|
|
||||||
for i, v := range yac.page {
|
|
||||||
m.Echo("page: %s %d\n", i, v)
|
|
||||||
}
|
|
||||||
for i, v := range yac.hash {
|
|
||||||
m.Echo("hash: %s %d\n", i, v)
|
|
||||||
}
|
|
||||||
for i, v := range yac.state {
|
|
||||||
m.Echo("node: %v %v\n", i, v)
|
|
||||||
}
|
|
||||||
for i, v := range yac.mat {
|
|
||||||
for k, v := range v {
|
|
||||||
if v != nil {
|
|
||||||
m.Echo("node: %s(%d,%d): %v\n", yac.name(i), i, k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
line := yac.mat[yac.page[arg[0]]]
|
|
||||||
if i, e := strconv.Atoi(arg[0]); e == nil {
|
|
||||||
line = yac.mat[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < len(line); i++ {
|
|
||||||
if v, ok := line[byte(i)]; ok && v != nil {
|
|
||||||
m.Echo("(%s, %d): %v\n", arg[0], i, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// }}}
|
|
||||||
}},
|
|
||||||
"train": &ctx.Command{Name: "train page hash word...", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"train": &ctx.Command{Name: "train page hash word...", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) { // {{{
|
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) {
|
||||||
page, ok := yac.page[arg[0]]
|
page, ok := yac.page[arg[0]]
|
||||||
if !ok {
|
if !ok {
|
||||||
page = m.Capi("npage", 1)
|
page = m.Capi("npage", 1)
|
||||||
yac.page[arg[0]] = page
|
yac.page[arg[0]] = page
|
||||||
yac.word[page] = arg[0]
|
yac.word[page] = arg[0]
|
||||||
|
|
||||||
m.Assert(page < m.Capi("nlang"), "语法集合过多")
|
m.Assert(page < m.Capi("nlang"), "语法集合过多")
|
||||||
|
|
||||||
yac.mat[page] = map[byte]*State{}
|
yac.mat[page] = map[byte]*State{}
|
||||||
for i := 0; i < m.Capi("nlang"); i++ {
|
for i := 0; i < m.Capi("nlang"); i++ {
|
||||||
yac.mat[page][byte(i)] = nil
|
yac.mat[page][byte(i)] = nil
|
||||||
@ -455,46 +345,113 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
yac.hand[hash] = arg[1]
|
yac.hand[hash] = arg[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// if m.Sess("lex") == nil {
|
if yac.lex == nil {
|
||||||
// lex := m.Sess("lex", "lex")
|
yac.lex = m.Sess("lex", "lex").Cmd("spawn")
|
||||||
// if lex.Cap("status") == "start" {
|
}
|
||||||
// lex.Start(yac.Context.Name+"lex", "语法词法")
|
|
||||||
// } else {
|
|
||||||
// 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:]})
|
||||||
m.Cap("stream", fmt.Sprintf("%d,%s,%s", m.Capi("nseed", 1), m.Cap("npage"), m.Cap("nhash")))
|
m.Cap("stream", fmt.Sprintf("%d,%s,%s", m.Capi("nseed", 1), m.Cap("npage"), m.Cap("nhash")))
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
}},
|
}},
|
||||||
"parse": &ctx.Command{Name: "parse page hash word...", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"parse": &ctx.Command{Name: "parse page void word...", Help: "解析语句, page: 初始语法, void: 空白语法, word: 解析语句", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) { // {{{
|
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) {
|
||||||
m.Optioni("page", yac.page[arg[0]])
|
str, word, hash := yac.parse(m, m, m.Optioni("page", yac.page[arg[0]]), m.Optioni("void", yac.page[arg[1]]), arg[2], 1)
|
||||||
m.Optioni("void", yac.page[arg[1]])
|
|
||||||
|
|
||||||
str, word, hash := yac.parse(m, nil, m.Optioni("page"), m.Optioni("void"), arg[2], 1)
|
|
||||||
m.Result(str, yac.hand[hash], word)
|
m.Result(str, yac.hand[hash], word)
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
}},
|
}},
|
||||||
"scan": &ctx.Command{
|
"scan": &ctx.Command{Name: "scan filename", Help: "解析文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
Name: "scan filename [yac_name [help]] [line line] [void void]",
|
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) {
|
||||||
Help: "解析文件, filename: yac_name:模块名, yac_help:模块帮助, 文件名, line: 默认语法, void: 默认空白",
|
m.Optioni("page", yac.page["line"])
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
m.Optioni("void", yac.page["void"])
|
||||||
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) { // {{{
|
if len(arg) > 0 {
|
||||||
m.Optioni("page", yac.page["line"])
|
m.Start(fmt.Sprintf("parse%d", m.Capi("nparse", 1)), "parse", key, arg[0])
|
||||||
m.Optioni("void", yac.page["void"])
|
} else {
|
||||||
if len(arg) > 0 {
|
m.Start(fmt.Sprintf("parse%d", m.Capi("nparse", 1)), "parse")
|
||||||
m.Start(m.Confx("yac_name", arg, 1), m.Confx("yac_help", arg, 2), key, arg[0])
|
|
||||||
} else {
|
|
||||||
m.Start(m.Confx("yac_name", arg, 1), m.Confx("yac_help", arg, 2))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// }}}
|
}
|
||||||
}},
|
}},
|
||||||
|
"show": &ctx.Command{Name: "show seed|page|hash|mat", Help: "查看信息", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Append("seed", len(yac.seed))
|
||||||
|
m.Append("page", len(yac.page))
|
||||||
|
m.Append("hash", len(yac.hash))
|
||||||
|
m.Append("node", len(yac.state))
|
||||||
|
m.Table()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "seed":
|
||||||
|
for _, v := range yac.seed {
|
||||||
|
m.Add("append", "page", fmt.Sprintf("%d", v.page))
|
||||||
|
m.Add("append", "hash", fmt.Sprintf("%d", v.hash))
|
||||||
|
m.Add("append", "word", fmt.Sprintf("%s", strings.Replace(strings.Replace(strings.Join(v.word, " "), "\n", "\\n", -1), "\t", "\\t", -1)))
|
||||||
|
}
|
||||||
|
m.Table()
|
||||||
|
case "page":
|
||||||
|
for k, v := range yac.page {
|
||||||
|
m.Add("append", "page", k)
|
||||||
|
m.Add("append", "code", fmt.Sprintf("%d", v))
|
||||||
|
}
|
||||||
|
m.Sort("code", "int").Table()
|
||||||
|
case "hash":
|
||||||
|
for k, v := range yac.hash {
|
||||||
|
m.Add("append", "hash", k)
|
||||||
|
m.Add("append", "code", fmt.Sprintf("%d", v))
|
||||||
|
m.Add("append", "hand", yac.hand[v])
|
||||||
|
}
|
||||||
|
m.Sort("code", "int").Table()
|
||||||
|
case "mat":
|
||||||
|
for _, v := range yac.mat {
|
||||||
|
for j := byte(0); j < byte(m.Capi("ncell")); j++ {
|
||||||
|
s := v[j]
|
||||||
|
if s == nil {
|
||||||
|
m.Add("append", fmt.Sprintf("%d", j), "")
|
||||||
|
} else {
|
||||||
|
m.Add("append", fmt.Sprintf("%d", j), fmt.Sprintf("%d,%d,%d", s.star, s.next, s.hash))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ncol := len(m.Meta["append"])
|
||||||
|
nrow := len(m.Meta[m.Meta["append"][0]])
|
||||||
|
for i := 0; i < ncol-1; i++ {
|
||||||
|
for j := i + 1; j < ncol; j++ {
|
||||||
|
same := true
|
||||||
|
void := true
|
||||||
|
for n := 0; n < nrow; n++ {
|
||||||
|
if m.Meta[m.Meta["append"][i]][n] != "" {
|
||||||
|
void = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.Meta[m.Meta["append"][i]][n] != m.Meta[m.Meta["append"][j]][n] {
|
||||||
|
same = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if same {
|
||||||
|
if !void {
|
||||||
|
key = m.Meta["append"][i] + "," + m.Meta["append"][j]
|
||||||
|
m.Meta[key] = m.Meta[m.Meta["append"][i]]
|
||||||
|
m.Meta["append"][i] = key
|
||||||
|
}
|
||||||
|
|
||||||
|
for k := j; k < ncol-1; k++ {
|
||||||
|
m.Meta["append"][k] = m.Meta["append"][k+1]
|
||||||
|
}
|
||||||
|
ncol--
|
||||||
|
j--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Meta["append"] = m.Meta["append"][:ncol]
|
||||||
|
m.Table()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,14 @@ function insert_before(self, element, html) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function copy_to_clipboard(text) {
|
function copy_to_clipboard(text) {
|
||||||
var clipboard = document.querySelector("#clipboard")
|
var clipboard = document.querySelector(".clipboard")
|
||||||
clipboard.value = text
|
clipboard.value = text
|
||||||
clipboard.select()
|
clipboard.select()
|
||||||
document.execCommand("copy")
|
document.execCommand("copy")
|
||||||
clipboard.blur()
|
clipboard.blur()
|
||||||
|
|
||||||
var clipstack = document.querySelector("#clipstack")
|
var clipstack = document.querySelector("#clipstack")
|
||||||
insert_child(clipstack, "option").value = clipboard.value
|
insert_child(clipstack, "option").value = text
|
||||||
clipstack.childElementCount > 3 && clipstack.removeChild(clipstack.lastElementChild)
|
clipstack.childElementCount > 3 && clipstack.removeChild(clipstack.lastElementChild)
|
||||||
}
|
}
|
||||||
function send_command(form, cb) {
|
function send_command(form, cb) {
|
||||||
@ -78,10 +78,13 @@ function check_argument(form, target) {
|
|||||||
}
|
}
|
||||||
function onaction(event, action) {
|
function onaction(event, action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "submit":
|
||||||
|
return false
|
||||||
|
break
|
||||||
case "click":
|
case "click":
|
||||||
if (event.target.nodeName == "INPUT") {
|
if (event.target.nodeName == "INPUT") {
|
||||||
if (event.altKey) {
|
if (event.altKey) {
|
||||||
var board = document.querySelector("#clipboard")
|
var board = document.querySelector(".clipboard")
|
||||||
event.target.value = board.value
|
event.target.value = board.value
|
||||||
check_argument(event.target.form, event.target)
|
check_argument(event.target.form, event.target)
|
||||||
}
|
}
|
||||||
@ -93,15 +96,94 @@ function onaction(event, action) {
|
|||||||
case "input":
|
case "input":
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "Enter":
|
case "Enter":
|
||||||
|
var history = JSON.parse(event.target.dataset["history"] || "[]")
|
||||||
|
if (history.length == 0 || event.target.value != history[history.length-1]) {
|
||||||
|
history.push(event.target.value)
|
||||||
|
var clistack = document.querySelector("#clistack")
|
||||||
|
insert_child(clistack, "option").value = event.target.value
|
||||||
|
}
|
||||||
check_argument(event.target.form, event.target)
|
check_argument(event.target.form, event.target)
|
||||||
|
event.target.dataset["history"] = JSON.stringify(history)
|
||||||
|
event.target.dataset["history_last"] = history.length-1
|
||||||
|
console.log(history.length)
|
||||||
break
|
break
|
||||||
case "Escape":
|
case "Escape":
|
||||||
event.target.value = ""
|
if (event.target.value) {
|
||||||
event.target.blur()
|
event.target.value = ""
|
||||||
|
} else {
|
||||||
|
event.target.blur()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
case "w":
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
var value = event.target.value
|
||||||
|
var space = value.length > 0 && value[value.length-1] == ' '
|
||||||
|
for (var i = value.length-1; i > -1; i--) {
|
||||||
|
if (space) {
|
||||||
|
if (value[i] != ' ') {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value[i] == ' ') {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.target.value = value.substr(0, i+1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "u":
|
||||||
|
if (event.ctrlKey && event.key == "u") {
|
||||||
|
event.target.value = ""
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "p":
|
||||||
|
if (event.ctrlKey && event.key == "p") {
|
||||||
|
var history = JSON.parse(event.target.dataset["history"] || "[]")
|
||||||
|
var last = event.target.dataset["history_last"]
|
||||||
|
console.log(last)
|
||||||
|
event.target.value = history[last--]
|
||||||
|
event.target.dataset["history_last"] = (last + history.length) % history.length
|
||||||
|
return false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "n":
|
||||||
|
if (event.ctrlKey && event.key == "n") {
|
||||||
|
var history = JSON.parse(event.target.dataset["history"] || "[]")
|
||||||
|
var last = event.target.dataset["history_last"]
|
||||||
|
last = (last +1) % history.length
|
||||||
|
console.log(last)
|
||||||
|
event.target.value = history[last]
|
||||||
|
event.target.dataset["history_last"] = last
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "j":
|
||||||
|
if (event.ctrlKey && event.key == "j") {
|
||||||
|
var history = JSON.parse(event.target.dataset["history"] || "[]")
|
||||||
|
if (history.length == 0 || event.target.value != history[history.length-1]) {
|
||||||
|
history.push(event.target.value)
|
||||||
|
var clistack = document.querySelector("#clistack")
|
||||||
|
insert_child(clistack, "option").value = event.target.value
|
||||||
|
}
|
||||||
|
check_argument(event.target.form, event.target)
|
||||||
|
event.target.dataset["history"] = JSON.stringify(history)
|
||||||
|
event.target.dataset["history_last"] = history.length-1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
console.log(event)
|
||||||
|
if (event.target.dataset["last_char"] == "j" && event.key == "k") {
|
||||||
|
if (event.target.value) {
|
||||||
|
event.target.value = ""
|
||||||
|
} else {
|
||||||
|
event.target.blur()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.target.dataset["last_char"] = event.key
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "keymap":
|
case "keymap":
|
||||||
|
break
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "g":
|
case "g":
|
||||||
document.querySelectorAll("form.option label.keymap").forEach(function(item) {
|
document.querySelectorAll("form.option label.keymap").forEach(function(item) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=0.7">
|
||||||
<title>{{option .Meta "page_title"}}</title>
|
<title>{{option .Meta "page_title"}}</title>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
@ -34,15 +34,32 @@
|
|||||||
form.option label.keymap.show {
|
form.option label.keymap.show {
|
||||||
display:inline;
|
display:inline;
|
||||||
}
|
}
|
||||||
|
form.option input {
|
||||||
|
margin-right:10px;
|
||||||
|
}
|
||||||
|
form.option input.cmd {
|
||||||
|
padding-left:10px;
|
||||||
|
color:white;
|
||||||
|
background-color:#272822;
|
||||||
|
width:600px;
|
||||||
|
}
|
||||||
|
form.option select {
|
||||||
|
margin-right:10px;
|
||||||
|
}
|
||||||
|
table.append {
|
||||||
|
font-size:14px;
|
||||||
|
}
|
||||||
table.append th {
|
table.append th {
|
||||||
cursor:pointer;
|
font-family:monospace;
|
||||||
background-color:lightgreen;
|
background-color:lightgreen;
|
||||||
|
cursor:pointer;
|
||||||
}
|
}
|
||||||
table.append th.order {
|
table.append th.order {
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
background-color:red;
|
background-color:red;
|
||||||
}
|
}
|
||||||
table.append td {
|
table.append td {
|
||||||
|
font-family:monospace;
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
padding-right: 20px;
|
padding-right: 20px;
|
||||||
}
|
}
|
||||||
@ -55,6 +72,9 @@
|
|||||||
border-left:solid 4px green;
|
border-left:solid 4px green;
|
||||||
overflow:scroll;
|
overflow:scroll;
|
||||||
}
|
}
|
||||||
|
code.result pre.clipboard {
|
||||||
|
height:2em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
@ -71,21 +91,13 @@
|
|||||||
{{define "clipboard"}}
|
{{define "clipboard"}}
|
||||||
<fieldset><legend>clipboard</legend>
|
<fieldset><legend>clipboard</legend>
|
||||||
<datalist id="clipstack"></datalist>
|
<datalist id="clipstack"></datalist>
|
||||||
<input id="clipboard">
|
<datalist id="clistack"></datalist>
|
||||||
</fieldset>
|
<input class="clipboard">
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "upload"}}
|
|
||||||
<fieldset><legend>clipboard</legend>
|
|
||||||
<form
|
|
||||||
>
|
|
||||||
<file></file>
|
|
||||||
</form>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "componet"}}
|
{{define "componet"}}
|
||||||
<fieldset><legend title="{{option .Meta "help"}}">{{option .Meta "help"}}({{option .Meta "command"}}.{{option .Meta "context"}})</legend>
|
<fieldset><legend title="{{option .Meta "help"}}">{{option .Meta "help"}}({{option .Meta "context"}}.{{option .Meta "command"}})</legend>
|
||||||
{{$form_type := option . "form_type"|meta}}
|
{{$form_type := option . "form_type"|meta}}
|
||||||
<form class="option {{option .Meta "name"}}"
|
<form class="option {{option .Meta "name"}}"
|
||||||
data-last_componet_group="{{option . "last_componet_group"|meta}}"
|
data-last_componet_group="{{option . "last_componet_group"|meta}}"
|
||||||
@ -104,7 +116,7 @@
|
|||||||
<div>
|
<div>
|
||||||
{{$type := index $input "type"}}
|
{{$type := index $input "type"}}
|
||||||
{{if eq $type "button"}}
|
{{if eq $type "button"}}
|
||||||
<button onclick="return onaction(event, 'command')">{{index $input "value"}}</button>
|
<input type="button" onclick="return onaction(event, 'command')" value="{{index $input "value"}}">
|
||||||
{{else if eq $type "submit"}}
|
{{else if eq $type "submit"}}
|
||||||
<input type="submit" value="{{index $input "value"}}">
|
<input type="submit" value="{{index $input "value"}}">
|
||||||
{{else if eq $type "file"}}
|
{{else if eq $type "file"}}
|
||||||
@ -127,7 +139,12 @@
|
|||||||
<input
|
<input
|
||||||
name="{{index $input "name"}}"
|
name="{{index $input "name"}}"
|
||||||
value="{{index $input "value"}}"
|
value="{{index $input "value"}}"
|
||||||
list="clipstack"
|
class="{{index $input "class"}}"
|
||||||
|
{{if index $input "clipstack"}}
|
||||||
|
list="{{index $input "clipstack"}}"
|
||||||
|
{{else}}
|
||||||
|
list="clipstack"
|
||||||
|
{{end}}
|
||||||
onclick="return onaction(event, 'click')"
|
onclick="return onaction(event, 'click')"
|
||||||
onkeyup="return onaction(event, 'input')">
|
onkeyup="return onaction(event, 'input')">
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user