@mirascript/help 0.1.62-alpha.9 → 0.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/package.json +15 -2
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @mirascript/help
|
|
2
|
+
|
|
3
|
+
`@mirascript/help` 用于将仓库中的参考文档编译为可直接消费的帮助数据,当前主要生成关键字和运算符说明表,供编辑器集成或网站功能使用。
|
|
4
|
+
|
|
5
|
+
## 数据来源
|
|
6
|
+
|
|
7
|
+
构建脚本会读取仓库中的 `docs/references` 文档目录,并根据 front-matter 中的 `token`、`title` 等字段生成发布内容。
|
|
8
|
+
|
|
9
|
+
## 导出内容
|
|
10
|
+
|
|
11
|
+
- `KEYWORDS`:关键字到 Markdown 文本的映射
|
|
12
|
+
- `OPERATORS`:运算符到 Markdown 文本的映射
|
|
13
|
+
- `Keyword` / `Operator`:由生成结果推导出的字面量类型
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @mirascript/help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 示例
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { KEYWORDS, OPERATORS } from '@mirascript/help';
|
|
25
|
+
|
|
26
|
+
console.log(KEYWORDS['match']);
|
|
27
|
+
console.log(OPERATORS['??']);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 构建
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm --filter @mirascript/help build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
如果新增或调整 `docs/references` 下的文档,需要重新执行构建以刷新 `dist/` 内容。
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export const KEYWORDS = Object.freeze({
|
|
|
23
23
|
"mut": "`mut` 用于声明可变变量。\n\n---\n\n使用 `let` 语句时声明一个可变变量:\n\n```mira\nlet mut x = 1;\nx += 2;\n// x == 3\n```\n\n---\n\n在模式匹配中声明一个可变绑定:\n\n```mira\nlet (mut a, b) = (1, 2);\na += 10;\n// b += 10; // 这行代码会报错,因为 b 是不可变的\n```\n",
|
|
24
24
|
"nan": "`nan` 是一个特殊的 `number` 值(Not a Number)。它与任何值都不相等(包括它自己)。\n\n```mira\nnan == nan; // false\nnan =~ nan; // false\n```\n",
|
|
25
25
|
"nil": "`nil` 表示“空值”。当访问不存在的字段、对 `nil` 进行空安全链式调用等场景时,结果也会是 `nil`。\n\n```mira\nlet x = nil;\nlet y = x ?? 0; // 0\nlet z = x.anything; // nil(空安全访问)\n```\n",
|
|
26
|
+
"not in": "`in` 的否定形式,结果与之相反。\n\n```mira\nfn is_not_spring(month) {\n month not in [3, 4, 5]\n}\n```\n",
|
|
26
27
|
"not": "`not` 用于在模式匹配中取反一个模式,也可以作为 `!` 运算符的替代写法。\n\n---\n\n逻辑非模式:\n\n```mira\nfn is_not_weekend(day) {\n day is not 6 and not 7\n}\n```\n\n---\n\n逻辑非运算符:\n\n```mira\nfn is_minor(age) {\n // 等同于 !(age >= 18)\n not (age >= 18)\n}\n```\n",
|
|
27
28
|
"or": "`or` 用于在模式匹配中组合多个模式,也可以作为 `||` 运算符的替代写法。\n\n---\n\n逻辑或模式:\n\n```mira\nfn is_weekend(day) {\n day is 6 or 7\n}\n```\n\n---\n\n逻辑或运算符:\n\n```mira\nfn is_superuser(role) {\n // 等同于 role == \"admin\" || role == \"superuser\"\n role == \"admin\" or role == \"superuser\"\n}\n```\n",
|
|
28
29
|
"pub": "`pub` 用于将模块内的声明导出。\n\n```mira\nmod counter {\n pub let mut value = 0;\n pub fn inc(){\n value += 1;\n }\n}\n\ndebug_print(counter.value); // 0\ncounter.inc();\ndebug_print(counter.value); // 1\n```\n",
|
|
@@ -44,7 +45,7 @@ export const OPERATORS = Object.freeze({
|
|
|
44
45
|
"^": "`^` 用于乘方,结合性为从右到左。\n\n```mira\n2^3 // 8\n```\n\n```mira\n2^3^2 // 2^(3^2)\n```\n",
|
|
45
46
|
"^=": "`^=` 是复合赋值,`x ^= y` 等价于 `x = x ^ y`。\n\n```mira\nlet mut x = 2;\nx ^= 3;\n// x == 8\n```\n",
|
|
46
47
|
":": "`:` 用于记录字面量、条件表达式和插值格式。\n\n---\n\n在记录字面量中,`:` 用于分隔字段名和字段值。\n\n```mira\nlet r = (x: 1, y: 2);\n```\n\n---\n\n在条件表达式中,`:` 用于分隔条件的不同分支。\n\n```mira\nlet status = score >= 60 ? \"及格\" : \"不及格\";\n```\n\n---\n\n在插值格式中,`:` 用于指定格式化选项。在指定格式化选项时,必须使用圆括号 `$(expr:format)`。\n\n```mira\ndebug_print(\"π 的值约为 $(PI:.2)\"); // 输出: π 的值约为 3.14\n```\n",
|
|
47
|
-
"::": "`::` 用于扩展调用。\n\n```mira\n\"Hello\"::chars()::join(\"|\")\n// 相当于 join(chars(\"Hello\"), \"
|
|
48
|
+
"::": "`::` 用于扩展调用。\n\n```mira\n\"Hello\"::chars()::join(\"|\")\n// 相当于 join(chars(\"Hello\"), \"|\")\n```\n",
|
|
48
49
|
",": "`,` 用于分隔参数、数组元素、记录字段等。\n\n```mira\nlet arr = [1, 2, 3];\nlet r = (a: 1, b: 2);\n\nfn f(a, b, c) { a + b + c }\nf(1, 2, 3);\n```\n",
|
|
49
50
|
".": "`.` 用于成员访问。\n\n```mira\nlet r = (a: 1);\nr.a; // 1\nr.b; // nil\n\nlet arr = [10, 20];\narr.0; // 10\narr.2; // nil\n```\n",
|
|
50
51
|
"==": "使用 `==` 运算符可以比较两个值是否严格相等。\n\n---\n\n对于原始值,如果它们的类型和值都相同,则认为它们相等。\n\n```mira\n5 == 5 // true\n```\n\n```mira\n\"hello\" == \"hello\" // true\n```\n\n```mira\ntrue == true // true\n```\n\n```mira\n5 == \"5\" // false\n```\n\n特别地,对于 `number` 类型的值 `nan`,它与任何值都不相等,包括它自己。\n\n```mira\nnan == nan // false\n```\n\n---\n\n对于 `array` 和 `record`,只有他们的元素和属性都相等时,才认为它们相等。\n\n```mira\n[1, 2, 3] == [1, 2, 3] // true\n```\n\n```mira\n(a: 1, b: 2) == (a: 1, b: 2) // true\n```\n\n```mira\n[1, 2, 3] == [1, 2, 4] // false\n```\n\n---\n\n对于 `function` `module` 和 `extern`,只有它们引用的是同一个对象时,才认为它们相等。\n\n```mira\nlet fn1 = fn() { return 1; };\nlet fn2 = fn() { return 1; };\n(fn1 == fn1, fn1 == fn2) // (true, false)\n```\n",
|
package/package.json
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/help",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.63",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Help documentation for Mirascript core language.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"mirascript",
|
|
9
|
+
"help",
|
|
10
|
+
"documentation",
|
|
11
|
+
"keywords",
|
|
12
|
+
"operators"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://mira.cloudpss.net",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/CloudPSS/MiraScript.git",
|
|
18
|
+
"directory": "packages/help"
|
|
19
|
+
},
|
|
7
20
|
"type": "module",
|
|
8
21
|
"main": "./dist/index.js",
|
|
9
22
|
"types": "./dist/index.d.ts",
|
|
@@ -12,7 +25,7 @@
|
|
|
12
25
|
"./package.json": "./package.json"
|
|
13
26
|
},
|
|
14
27
|
"devDependencies": {
|
|
15
|
-
"js-yaml": "^
|
|
28
|
+
"js-yaml": "^5.2.0"
|
|
16
29
|
},
|
|
17
30
|
"scripts": {
|
|
18
31
|
"build": "pnpm clean && node ./scripts/build.js",
|