mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt lex.go
This commit is contained in:
parent
f5a1339271
commit
26c006a88a
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-07-18 17:37:28", "ZYB-20190522USI", 176,
|
"2019-07-20 15:41:22", "mac", 229,
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
},
|
},
|
||||||
Commands: map[string]*Command{
|
Commands: map[string]*Command{
|
||||||
"_init": &Command{Name: "_init", Help: "启动", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
"_init": &Command{Name: "_init", Help: "启动", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
for _, x := range []string{"cli", "nfs", "aaa", "ssh", "web"} {
|
for _, x := range []string{"lex", "cli", "nfs", "aaa", "ssh", "web"} {
|
||||||
m.Cmd(x + "._init")
|
m.Cmd(x + "._init")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -532,11 +532,15 @@ func (m *Message) Log(action string, str string, arg ...interface{}) *Message {
|
|||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Show(args ...interface{}) *Message {
|
func (m *Message) Show(str string, args ...interface{}) *Message {
|
||||||
|
res := fmt.Sprintf(str, args...)
|
||||||
|
|
||||||
if m.Option("cli.modal") == "action" {
|
if m.Option("cli.modal") == "action" {
|
||||||
fmt.Printf(kit.Format(args...))
|
fmt.Printf(res)
|
||||||
} else if kit.STDIO != nil {
|
} else if kit.STDIO != nil {
|
||||||
kit.STDIO.Show(args...)
|
kit.STDIO.Show(res)
|
||||||
|
} else {
|
||||||
|
m.Log("info", "show: %v", res)
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Seed struct {
|
type Seed struct {
|
||||||
@ -12,38 +13,41 @@ type Seed struct {
|
|||||||
hash int
|
hash int
|
||||||
word string
|
word string
|
||||||
}
|
}
|
||||||
|
type Point struct {
|
||||||
|
s int
|
||||||
|
c byte
|
||||||
|
}
|
||||||
type State struct {
|
type State struct {
|
||||||
star bool
|
star bool
|
||||||
next int
|
next int
|
||||||
hash int
|
hash int
|
||||||
}
|
}
|
||||||
type Point struct {
|
|
||||||
s int
|
|
||||||
c byte
|
|
||||||
}
|
|
||||||
type LEX struct {
|
type LEX struct {
|
||||||
seed []*Seed
|
seed []*Seed
|
||||||
page map[string]int
|
hash map[string]int
|
||||||
hash map[string]int
|
hashs map[int]string
|
||||||
|
pages map[int]string
|
||||||
|
page map[string]int
|
||||||
|
|
||||||
mat []map[byte]*State
|
|
||||||
state map[State]*State
|
|
||||||
char map[byte][]byte
|
char map[byte][]byte
|
||||||
|
state map[State]*State
|
||||||
|
mat []map[byte]*State
|
||||||
|
|
||||||
*ctx.Context
|
*ctx.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lex *LEX) index(m *ctx.Message, hash string, h string) int {
|
func (lex *LEX) index(m *ctx.Message, hash string, h string) int {
|
||||||
which := lex.page
|
which, names := lex.hash, lex.hashs
|
||||||
if hash == "nhash" {
|
if hash == "npage" {
|
||||||
which = lex.hash
|
which, names = lex.page, lex.pages
|
||||||
}
|
}
|
||||||
|
|
||||||
if x, e := strconv.Atoi(h); e == nil {
|
if x, e := strconv.Atoi(h); e == nil {
|
||||||
if hash == "nhash" {
|
if hash == "npage" {
|
||||||
lex.hash[hash] = x
|
m.Assert(x <= m.Capi("npage"), "语法集合未创建")
|
||||||
|
} else {
|
||||||
|
lex.hash[h] = x
|
||||||
}
|
}
|
||||||
m.Assert(hash != "npage" || x < m.Capi("npage"))
|
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +56,8 @@ func (lex *LEX) index(m *ctx.Message, hash string, h string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
which[h] = m.Capi(hash, 1)
|
which[h] = m.Capi(hash, 1)
|
||||||
m.Assert(hash != "npage" || m.Capi("npage") < m.Confi("info", "nlang"))
|
names[which[h]] = h
|
||||||
|
m.Assert(hash != "npage" || m.Capi("npage") < m.Confi("meta", "nlang"), "语法集合超过上限")
|
||||||
return which[h]
|
return which[h]
|
||||||
}
|
}
|
||||||
func (lex *LEX) charset(c byte) []byte {
|
func (lex *LEX) charset(c byte) []byte {
|
||||||
@ -65,8 +70,8 @@ func (lex *LEX) train(m *ctx.Message, page int, hash int, seed []byte) int {
|
|||||||
m.Log("debug", "%s %s page: %v hash: %v seed: %v", "train", "lex", page, hash, string(seed))
|
m.Log("debug", "%s %s page: %v hash: %v seed: %v", "train", "lex", page, hash, string(seed))
|
||||||
|
|
||||||
ss := []int{page}
|
ss := []int{page}
|
||||||
cn := make([]bool, m.Confi("info", "ncell"))
|
cn := make([]bool, m.Confi("meta", "ncell"))
|
||||||
cc := make([]byte, 0, m.Confi("info", "ncell"))
|
cc := make([]byte, 0, m.Confi("meta", "ncell"))
|
||||||
sn := make([]bool, m.Capi("nline"))
|
sn := make([]bool, m.Capi("nline"))
|
||||||
|
|
||||||
points := []*Point{}
|
points := []*Point{}
|
||||||
@ -160,7 +165,7 @@ func (lex *LEX) train(m *ctx.Message, page int, hash int, seed []byte) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if state.next == 0 {
|
if state.next == 0 {
|
||||||
if line == 0 || !m.Confs("info", "compact") {
|
if line == 0 || !m.Confs("meta", "compact") {
|
||||||
lex.mat = append(lex.mat, make(map[byte]*State))
|
lex.mat = append(lex.mat, make(map[byte]*State))
|
||||||
line = m.Capi("nline", 1) - 1
|
line = m.Capi("nline", 1) - 1
|
||||||
sn = append(sn, false)
|
sn = append(sn, false)
|
||||||
@ -184,7 +189,7 @@ func (lex *LEX) train(m *ctx.Message, page int, hash int, seed []byte) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
if s < m.Confi("info", "nlang") || s >= len(lex.mat) {
|
if s < m.Confi("meta", "nlang") || s >= len(lex.mat) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,27 +275,21 @@ func (lex *LEX) parse(m *ctx.Message, page int, line []byte) (hash int, rest []b
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
c.Caches = map[string]*ctx.Cache{}
|
return &LEX{Context: c}
|
||||||
c.Configs = map[string]*ctx.Config{}
|
|
||||||
|
|
||||||
s := new(LEX)
|
|
||||||
s.Context = c
|
|
||||||
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.Caches["nseed"] = &ctx.Cache{Name: "种子数量", Value: "0", Help: "词法模板的数量"}
|
lex.Caches["nseed"] = &ctx.Cache{Name: "种子数量", Value: "0", Help: "词法模板的数量"}
|
||||||
lex.Caches["npage"] = &ctx.Cache{Name: "集合数量", Value: "0", Help: "词法集合的数量"}
|
lex.Caches["npage"] = &ctx.Cache{Name: "集合数量", Value: "0", Help: "词法集合的数量"}
|
||||||
lex.Caches["nhash"] = &ctx.Cache{Name: "类型数量", Value: "0", Help: "单词类型的数量"}
|
lex.Caches["nhash"] = &ctx.Cache{Name: "类型数量", Value: "0", Help: "词法类型的数量"}
|
||||||
|
|
||||||
lex.Caches["nline"] = &ctx.Cache{Name: "状态数量", Value: m.Conf("info", "nlang"), Help: "状态机状态的数量"}
|
lex.Caches["nline"] = &ctx.Cache{Name: "状态数量", Value: m.Conf("meta", "nlang"), Help: "状态机状态的数量"}
|
||||||
lex.Caches["nnode"] = &ctx.Cache{Name: "节点数量", Value: "0", Help: "状态机连接的逻辑数量"}
|
lex.Caches["nnode"] = &ctx.Cache{Name: "节点数量", Value: "0", Help: "状态机连接的逻辑数量"}
|
||||||
lex.Caches["nreal"] = &ctx.Cache{Name: "实点数量", Value: "0", Help: "状态机连接的存储数量"}
|
lex.Caches["nreal"] = &ctx.Cache{Name: "实点数量", Value: "0", Help: "状态机连接的存储数量"}
|
||||||
|
|
||||||
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.hashs = map[int]string{0: "nil"}
|
||||||
lex.mat = make([]map[byte]*State, m.Confi("info", "nlang"))
|
lex.pages = map[int]string{0: "nil"}
|
||||||
lex.state = make(map[State]*State)
|
|
||||||
|
|
||||||
lex.char = map[byte][]byte{
|
lex.char = map[byte][]byte{
|
||||||
't': []byte{'\t'},
|
't': []byte{'\t'},
|
||||||
@ -300,6 +299,8 @@ func (lex *LEX) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
|||||||
'd': []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'},
|
'd': []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'},
|
||||||
'x': []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F'},
|
'x': []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F'},
|
||||||
}
|
}
|
||||||
|
lex.state = make(map[State]*State)
|
||||||
|
lex.mat = make([]map[byte]*State, m.Capi("nline"))
|
||||||
|
|
||||||
return lex
|
return lex
|
||||||
}
|
}
|
||||||
@ -307,62 +308,89 @@ func (lex *LEX) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (lex *LEX) Close(m *ctx.Message, arg ...string) bool {
|
func (lex *LEX) Close(m *ctx.Message, arg ...string) bool {
|
||||||
switch lex.Context {
|
|
||||||
case m.Target():
|
|
||||||
case m.Source():
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
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: "矩阵数量"},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"npage": &ctx.Config{Name: "npage", Value: "1", Help: "npage"},
|
"npage": &ctx.Config{Name: "npage", Value: "1", Help: "默认页"},
|
||||||
"nhash": &ctx.Config{Name: "nhash", Value: "1", Help: "npage"},
|
"nhash": &ctx.Config{Name: "nhash", Value: "1", Help: "默认值"},
|
||||||
"info": &ctx.Config{Name: "info", Value: map[string]interface{}{"compact": true, "ncell": 128, "nlang": 64}, Help: "嵌套层级日志的标记"},
|
"meta": &ctx.Config{Name: "meta", Value: map[string]interface{}{
|
||||||
|
"ncell": 128, "nlang": 64, "compact": true,
|
||||||
|
"name": "mat%d", "help": "matrix",
|
||||||
|
}, Help: "初始参数"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"init": &ctx.Command{Name: "init", Help: "启动", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"_init": &ctx.Command{Name: "_init", Help: "默认矩阵", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
return
|
|
||||||
}},
|
|
||||||
"spawn": &ctx.Command{Name: "spawn", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
if _, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if _, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
m.Start(fmt.Sprintf("matrix%d", m.Capi("nmat", 1)), "matrix")
|
m.Spawn().Cmd("train", "-?[a-zA-Z_0-9:/.]+", "key", "cmd")
|
||||||
|
m.Spawn().Cmd("train", "\"[^\"]*\"", "str", "cmd")
|
||||||
|
m.Spawn().Cmd("train", "'[^']*'", "str", "cmd")
|
||||||
|
m.Spawn().Cmd("train", "#[^\n]*", "com", "cmd")
|
||||||
|
m.Spawn().Cmd("train", "[~!@$%()]", "ops", "cmd")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"train": &ctx.Command{Name: "train seed [hash [page]", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"spawn": &ctx.Command{Name: "spawn [help [name]]", Help: "创建矩阵", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
if _, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
|
m.Start(fmt.Sprintf(kit.Select(m.Conf("lex.meta", "name"), arg, 1), m.Capi("nmat", 1)),
|
||||||
|
kit.Select(m.Conf("lex.meta", "help"), arg, 0))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}},
|
||||||
|
"train": &ctx.Command{Name: "train seed [hash [page]", Help: "词法训练", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
page := lex.index(m, "npage", m.Confx("npage", arg, 2))
|
|
||||||
hash := lex.index(m, "nhash", m.Confx("nhash", arg, 1))
|
hash := lex.index(m, "nhash", m.Confx("nhash", arg, 1))
|
||||||
|
page := lex.index(m, "npage", m.Confx("npage", arg, 2))
|
||||||
if lex.mat[page] == nil {
|
if lex.mat[page] == nil {
|
||||||
lex.mat[page] = map[byte]*State{}
|
lex.mat[page] = map[byte]*State{}
|
||||||
}
|
}
|
||||||
m.Cap("npage", len(lex.page))
|
|
||||||
m.Cap("nhash", len(lex.hash))
|
|
||||||
|
|
||||||
m.Result(0, lex.train(m, 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]})
|
||||||
m.Cap("stream", fmt.Sprintf("%d,%s,%s", m.Capi("nseed", 1), m.Cap("npage"), m.Cap("nhash")))
|
m.Cap("stream", fmt.Sprintf("%s,%s,%s", m.Cap("nseed", len(lex.seed)),
|
||||||
|
m.Cap("npage"), m.Cap("nhash", len(lex.hash)-1)))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"parse": &ctx.Command{Name: "parse line [page]", Help: "解析单词", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"parse": &ctx.Command{Name: "parse line [page]", Help: "词法解析", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
page := lex.index(m, "npage", m.Confx("npage", arg, 1))
|
hash, rest, word := lex.parse(m, lex.index(m, "npage", m.Confx("npage", arg, 1)), []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))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"show": &ctx.Command{Name: "show seed|page|hash|mat", Help: "查看信息", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"split": &ctx.Command{Name: "split line [page]", Help: "词法分隔", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
|
for input := []byte(arg[0]); len(input) > 0; {
|
||||||
|
hash, rest, word := lex.parse(m, lex.index(m, "npage", m.Confx("npage", arg, 1)), input)
|
||||||
|
m.Log("fuck", "what %v %v %v", hash, rest, word)
|
||||||
|
if hash == 0 || len(word) == 0 || len(rest) == len(input) {
|
||||||
|
if len(input) > 0 {
|
||||||
|
input = input[1:]
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Push("word", string(word))
|
||||||
|
m.Push("hash", lex.hashs[hash])
|
||||||
|
m.Push("rest", string(rest))
|
||||||
|
input = rest
|
||||||
|
}
|
||||||
|
m.Table()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}},
|
||||||
|
"show": &ctx.Command{Name: "show seed|page|hash|mat|node", Help: "查看信息", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Append("seed", len(lex.seed))
|
m.Append("seed", len(lex.seed))
|
||||||
m.Append("page", len(lex.page))
|
m.Append("page", len(lex.page))
|
||||||
m.Append("hash", len(lex.hash))
|
m.Append("hash", len(lex.hash))
|
||||||
|
m.Append("nmat", len(lex.mat))
|
||||||
m.Append("node", len(lex.state))
|
m.Append("node", len(lex.state))
|
||||||
m.Table()
|
m.Table()
|
||||||
return
|
return
|
||||||
@ -370,35 +398,72 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "seed":
|
case "seed":
|
||||||
for _, v := range lex.seed {
|
for _, v := range lex.seed {
|
||||||
m.Add("append", "page", fmt.Sprintf("%d", v.page))
|
m.Push("page", fmt.Sprintf("%s", lex.pages[v.page]))
|
||||||
m.Add("append", "hash", fmt.Sprintf("%d", v.hash))
|
m.Push("word", fmt.Sprintf("%s", strings.Replace(strings.Replace(v.word, "\n", "\\n", -1), "\t", "\\t", -1)))
|
||||||
m.Add("append", "word", fmt.Sprintf("%s", strings.Replace(strings.Replace(v.word, "\n", "\\n", -1), "\t", "\\t", -1)))
|
m.Push("hash", fmt.Sprintf("%s", lex.hashs[v.hash]))
|
||||||
}
|
}
|
||||||
m.Table()
|
m.Sort("page", "int").Table()
|
||||||
|
|
||||||
case "page":
|
case "page":
|
||||||
for k, v := range lex.page {
|
for k, v := range lex.page {
|
||||||
m.Add("append", "page", k)
|
if k == "nil" {
|
||||||
m.Add("append", "code", fmt.Sprintf("%d", v))
|
continue
|
||||||
|
}
|
||||||
|
m.Push("page", k)
|
||||||
|
m.Push("code", fmt.Sprintf("%d", v))
|
||||||
}
|
}
|
||||||
m.Sort("code", "int").Table()
|
m.Sort("code", "int").Table()
|
||||||
|
|
||||||
case "hash":
|
case "hash":
|
||||||
for k, v := range lex.hash {
|
for k, v := range lex.hash {
|
||||||
m.Add("append", "hash", k)
|
if k == "nil" {
|
||||||
m.Add("append", "code", fmt.Sprintf("%d", v))
|
continue
|
||||||
|
}
|
||||||
|
m.Push("hash", k)
|
||||||
|
m.Push("code", fmt.Sprintf("%d", v))
|
||||||
|
}
|
||||||
|
m.Sort("code", "int").Table()
|
||||||
|
|
||||||
|
case "node":
|
||||||
|
for _, v := range lex.state {
|
||||||
|
m.Push("star", v.star)
|
||||||
|
m.Push("next", v.next)
|
||||||
|
m.Push("hash", v.hash)
|
||||||
}
|
}
|
||||||
m.Table()
|
m.Table()
|
||||||
|
|
||||||
case "mat":
|
case "mat":
|
||||||
for _, v := range lex.mat {
|
for i, v := range lex.mat {
|
||||||
for j := byte(0); j < byte(m.Confi("info", "ncell")); j++ {
|
if i <= m.Capi("npage") {
|
||||||
s := v[j]
|
m.Push("index", lex.pages[i])
|
||||||
if s == nil {
|
} else if i < m.Confi("meta", "nlang") {
|
||||||
m.Add("append", fmt.Sprintf("%c", j), "")
|
continue
|
||||||
|
} else {
|
||||||
|
m.Push("index", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
for j := byte(0); j < byte(m.Confi("meta", "ncell")); j++ {
|
||||||
|
c := fmt.Sprintf("%c", j)
|
||||||
|
switch c {
|
||||||
|
case "\n":
|
||||||
|
c = "\\n"
|
||||||
|
case "\t":
|
||||||
|
c = "\\t"
|
||||||
|
case " ":
|
||||||
|
default:
|
||||||
|
if j < 0x20 {
|
||||||
|
c = fmt.Sprintf("\\%x", j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if s := v[j]; s == nil {
|
||||||
|
m.Push(c, "")
|
||||||
} else {
|
} else {
|
||||||
star := 0
|
star := 0
|
||||||
if s.star {
|
if s.star {
|
||||||
star = 1
|
star = 1
|
||||||
}
|
}
|
||||||
m.Add("append", fmt.Sprintf("%c", j), fmt.Sprintf("%d,%d,%d", star, s.next, s.hash))
|
m.Push(c, fmt.Sprintf("%d,%d,%d", star, s.next, s.hash))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -443,7 +508,5 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
lex := &LEX{}
|
ctx.Index.Register(Index, &LEX{Context: Index})
|
||||||
lex.Context = Index
|
|
||||||
ctx.Index.Register(Index, lex)
|
|
||||||
}
|
}
|
||||||
|
@ -233,15 +233,11 @@ func (yac *YAC) parse(m *ctx.Message, out *ctx.Message, page int, void int, line
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.Configs = map[string]*ctx.Config{}
|
|
||||||
if len(arg) > 0 && arg[0] == "scan" {
|
if len(arg) > 0 && arg[0] == "scan" {
|
||||||
return yac
|
return yac
|
||||||
}
|
}
|
||||||
|
|
||||||
s := new(YAC)
|
return &YAC{Context: c}
|
||||||
s.Context = c
|
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
func (yac *YAC) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
func (yac *YAC) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||||
return yac
|
return yac
|
||||||
@ -259,10 +255,6 @@ func (yac *YAC) Start(m *ctx.Message, arg ...string) (close bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (yac *YAC) Close(m *ctx.Message, arg ...string) bool {
|
func (yac *YAC) Close(m *ctx.Message, arg ...string) bool {
|
||||||
switch yac.Context {
|
|
||||||
case m.Target():
|
|
||||||
case m.Source():
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +484,5 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
yac := &YAC{}
|
ctx.Index.Register(Index, &YAC{Context: Index})
|
||||||
yac.Context = Index
|
|
||||||
ctx.Index.Register(Index, yac)
|
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,9 @@ fieldset.Login>form.option button {
|
|||||||
height:28px;
|
height:28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldset.item {
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
fieldset.item>div.output {
|
fieldset.item>div.output {
|
||||||
overflow:auto;
|
overflow:auto;
|
||||||
}
|
}
|
||||||
|
@ -623,7 +623,7 @@ function Plugin(page, pane, field) {
|
|||||||
plugin.Append(item).focus()
|
plugin.Append(item).focus()
|
||||||
break
|
break
|
||||||
case "m":
|
case "m":
|
||||||
plugin.Clone().plugin.Plugin.Select()
|
plugin.Clone().Select()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user