# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# README
Lang LK
⌨️ 体验
获取
- 一键安装:
go install github.com/lollipopkit/lk@latest
- Release 下载
- 克隆后,
go build
生成
CLI
详细说明可以运行 lk --help
查看
# 进入REPL交互式解释器
lk
# 执行.lk(c)文件
lk <file>
# 编译.lk文件
lk -c <file>
# 为.lk文件,生成语法树
lk -a <file>
📄 语法
详细
示例
// http发送请求示例
resp, err := http.post(
'http://httpbin.org/post', // URL
{'accept': 'application/json'}, // Headers
'{"foo": "bar"}' // Body
)
if err != nil {
error(err) // 内置的error方法
}
print(resp.code, resp.body)
// json解析
if json.get(resp.body, 'json.foo') != 'bar' {
error('mismatch result')
}
// 以下是http监听部分
class Header {
'items': {}
}
fn Header.fromTable(h) {
self := new(Header)
for k, v in h {
self.items[k] = v
}
rt self
}
// `print`的参数,如果非`str`类型,会调用`__str`方法
// 这里`Header`类实现了`__str`方法
fn Header:__str() {
shy s = ''
for k, v in self.items {
s = fmt('%s%s: %s\n', s, k, v)
}
rt s
}
/*
处理监听事件
`req`包含属性`method`, `url`, `body`, `headers`
*/
handler := fn(req) => 200, fmt('%s %s\n\n%s\n%s', req.method, req.url, Header.fromTable(req.headers), req.body)
// 监听
if http.listen(':8080', handler) != nil {
error(err)
}
🔖 TODO
- 语法
- 注释:
//
/* */
- 去除
repeat
,until
,goto
,..
(concat
) - Raw String, 使用
`
包裹字符 - 面向对象
- 自动添加
range
(paris
) - 语法糖
- 三元操作符
a ? b : c
-
a == nil ? b : a
->a ?? b
-
shy a = b
->a := b
-
shy a = fn(b) {rt c}
->shy a = fn(b) => c
- 支持
a++
a+=b
等
- 三元操作符
- Table
- key为StringExp,而不是NameExp
- 构造方式:
=
->:
, eg:{a = 'a'}
->{a: 'a'}
- 索引从
0
开始 - 改变
metatable
设置方式 - 支持
a.0
(等同于a[0]
)
- 注释:
- CLI
- 支持传入参数 (
lk args.lk arg1
->.lk
内调用os.args
) - REPL,直接运行
./lk
即可进入- 支持方向键
- 识别代码块
- 支持传入参数 (
- 资源
- 文档
-
LANG.md
- 测试集,位于
test
文件夹
-
- IDE
- VSCode高亮
- 文档
🌳 生态
- Vscode插件:高亮
📝 License
lollipopkit 2023 GPL v3