@nova-lang/cli 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +158 -144
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,13 +1,17 @@
1
- 我设计了一种全新的标记语言,命名为 **Nova**(全称:**N**ested **O**rdered **V**ersatile **A**rchitecture)。它并非将 HTML、YAML、TeX 等语法简单堆砌,而是从它们各自的优势中抽象出**统一节点模型**——一切皆是可带属性、可含子节点的**函数式块(Block)**。Nova 的语法规则如下。
1
+ # Nova
2
+
3
+ **N**ested **O**rdered **V**ersatile **A**rchitecture — a programmable markup language.
4
+
5
+ Nova is not a simple mashup of HTML, YAML, and TeX. It abstracts their strengths into a **unified node model** — everything is a **functional Block** with attributes and children.
2
6
 
3
7
  ---
4
8
 
5
- ## 安装
9
+ ## 安装 / Install
6
10
 
7
- ### npm(推荐)
11
+ ### npm (recommended)
8
12
  ```bash
9
13
  npm install -g @nova-lang/cli
10
- # 需要先安装 Zig 编译器:https://ziglang.org/download/
14
+ # Requires Zig compiler: https://ziglang.org/download/
11
15
  nova examples/sample.nv output.html
12
16
  ```
13
17
 
@@ -17,7 +21,7 @@ pip install -e .
17
21
  nova examples/sample.nv output.html
18
22
  ```
19
23
 
20
- ### Zig 编译
24
+ ### Zig
21
25
  ```bash
22
26
  zig build
23
27
  ./zig-out/bin/nova examples/sample.nv output.html
@@ -25,194 +29,202 @@ zig build
25
29
 
26
30
  ---
27
31
 
28
- ## Nova 语法规范 v1.0
32
+ ## Nova 语法规范 v1.0 / Language Specification
33
+
34
+ ### 核心理念 / Core Design
29
35
 
30
- ### 核心设计理念
31
- - **一切皆块**:文档元素、元数据、样式、数据类型、宏都是块,语法形式统一。
32
- - **缩进定界**:块内容由缩进界定,省略闭合标记,类似 YAML Python。
33
- - **标签即函数**:块类型通过 `@命令名` 调用,属性写在圆括号 `()` 里,子块写在缩进大括号 `{}` 里——这是一种**函数式标记**。
34
- - **双模数据**:内联采用自然书写,数据表可采用紧凑的类 CSV 表示或外部引用。
35
- - **强类型可编译**:可内嵌类型定义和接口,直接生成代码或验证数据。
36
- - **数学与宏不变质**:保留 TeX 强大排版,但将其融入统一语法。
36
+ - **一切皆块 / Everything is a Block** — document elements, metadata, styles, data types, and macros all share one syntax form.
37
+ - **缩进定界 / Indentation-based** — block content is delimited by indentation (like YAML/Python), no closing tags needed.
38
+ - **标签即函数 / Tags are Functions** — block types are invoked with `@command`, attributes in `()`, children in indented `{}` — **functional markup**.
39
+ - **双模数据 / Dual-mode Data** natural inline writing for prose, compact CSV-like tables or external references for data.
40
+ - **强类型可编译 / Strongly Typed** — embed type definitions and interfaces, generate code or validate data directly.
41
+ - **数学与宏不变质 / Math & Macros** — retains TeX's powerful typesetting, unified into one syntax.
42
+
43
+ English · [中文](#nova-语法规范-v10)
37
44
 
38
45
  ---
39
46
 
40
- ### 1. 基础词法
47
+ ### 1. 基础词法 / Lexical Basics
41
48
 
42
49
  ```nova
43
- // 单行注释
44
- /* 多行
45
- 注释 */
50
+ // single-line comment
51
+ /* multi-line
52
+ comment */
46
53
 
47
- // 文档元数据块
54
+ // document metadata
48
55
  @meta {
49
- title: "Nova 示例"
56
+ title: "Nova Example"
50
57
  author: Li Hua
51
58
  date: 2026-06-20
52
59
  }
53
60
 
54
- // 引入外部包(如预定义类型、宏集)
61
+ // importing external packages
55
62
  @use "nova/std/typography"
56
63
  @use "nova/schema/gencode"
57
64
  ```
58
65
 
59
- - 字符串:`"双引号"` `'单引号'`,支持 `#{...}` 插值。
60
- - 数字:`42`、`3.14`、`6.02e23`、`0xAB`。
61
- - 布尔与空:`true`、`false`、`null`。
62
- - 标识符:`[a-zA-Z_][a-zA-Z0-9_-]*`。
66
+ | Token | Examples | Notes |
67
+ |-------|----------|-------|
68
+ | 字符串 / String | `"double"` `'single'` | Supports `#{...}` interpolation |
69
+ | 数字 / Number | `42` `3.14` `6.02e23` `0xAB` | Integer, float, hex, scientific |
70
+ | 布尔与空 / Bool & Null | `true` `false` `null` | |
71
+ | 标识符 / Identifier | `[a-zA-Z_][a-zA-Z0-9_-]*` | |
63
72
 
64
73
  ---
65
74
 
66
- ### 2. 块语法(融合 HTML/XML 结构 + YAML 简洁)
75
+ ### 2. 块语法 / Block Syntax
67
76
 
68
- 一个块的基本形式为:
77
+ A block's basic form:
69
78
 
70
79
  ```nova
71
- @块名(属性1: 值, 属性2: ) 可选内联正文 {
72
- 子块1
73
- 子块2
80
+ @BlockName(attr1: val, attr2: val) optional inline text {
81
+ child block 1
82
+ child block 2
74
83
  }
75
84
  ```
76
85
 
77
- - **无子块**可省略大括号和缩进:
78
- `@image(src: "photo.png", alt: "头像")`
79
- - **块名省略**时为无名容器,等价于 `<div>` YAML 映射。
80
- - **属性列表**写在紧跟的 `()` 中,逗号分隔,键值对用 `:` 分隔(也可用 `=`),布尔属性可省略值。
81
- - **子块**必须比父块缩进一层(2 个空格)。
86
+ - **No children** → omit braces: `@image(src: "photo.png", alt: "avatar")`
87
+ - **Anonymous block** → unnamed container, acts like `<div>` or YAML mapping.
88
+ - **Attributes** in `()`, comma-separated, `:` or `=` for key-value pairs, boolean attrs can omit value.
89
+ - **Children** must be indented 2 spaces deeper than parent.
90
+
91
+ #### 示例 / Example
82
92
 
83
- #### 示例
84
93
  ```nova
85
94
  @page {
86
95
  @header {
87
- @title "Nova 语言手册"
96
+ @title "Nova Language Manual"
88
97
  @author "Li Hua"
89
98
  }
90
99
  @body {
91
100
  @section(id: "intro") {
92
- @p "Nova 是一种全新的可编程标记语言。"
101
+ @p "Nova is a new programmable markup language."
93
102
  }
94
103
  }
95
104
  }
96
105
  ```
97
- 相当于 HTML 的 `<page><header><title>...</title>`…,但无需闭合标签,且结构由缩进清晰表达。
106
+
107
+ Equivalent to HTML `<page><header><title>...</title>`… but without closing tags, structure clearly expressed by indentation.
98
108
 
99
109
  ---
100
110
 
101
- ### 3. 内联元素与格式(融合 HTML 行内标签 + TeX 命令)
111
+ ### 3. 内联元素与格式 / Inline Elements & Formatting
112
+
113
+ Inline content uses `@tag{ text }` or `@tag(attrs){ text }`:
102
114
 
103
- 内联内容使用 `@标记{ 文本 }` 或 `@标记(属性){ 文本 }`:
104
115
  ```nova
105
- 这是一段包含 @em{强调} @strong{粗体} 的文本,
106
- 还有 @a(href: "https://nova-lang.org"){链接} @code{print(x)}
116
+ Text with @em{emphasis} and @strong{bold},
117
+ a @a(href: "https://nova-lang.org"){link} and @code{print(x)}.
107
118
  ```
108
- 与 TeX 的 `\emph{...}` 相似,但统一了属性传递方式。
109
119
 
110
- 数学公式直接内嵌,支持 TeX 语法:
111
- - 行内:`$E = mc^2$`
112
- - 展示:`$$ \sum_{i=1}^n i = \frac{n(n+1)}{2} $$`
113
- - 也可使用块形式:`@equation { x = \frac{-b \pm \sqrt{b^2-4ac}}{2a} }`
120
+ Similar to TeX's `\emph{...}`, but with unified attribute syntax.
121
+
122
+ **Math** TeX syntax embedded directly:
123
+ - Inline: `$E = mc^2$`
124
+ - Display: `$$ \sum_{i=1}^n i = \frac{n(n+1)}{2} $$`
125
+ - Block form: `@equation { x = \frac{-b \pm \sqrt{b^2-4ac}}{2a} }`
114
126
 
115
127
  ---
116
128
 
117
- ### 4. 列表与映射(YAML 优势)
118
-
119
- - **无序列表**用 `-` `*` 引导:
120
- ```nova
121
- @ul {
122
- - 苹果
123
- - 香蕉
124
- - 橘子
125
- }
126
- ```
127
- - **有序列表**用 `+` 后跟数字或 `#`:
128
- ```nova
129
- @ol {
130
- + 1. 第一步
131
- + 2. 第二步
132
- }
133
- ```
134
- - **映射**用键值对,可内联或展开:
135
- ```nova
136
- @config {
137
- host: "localhost"
138
- port: 8080
139
- timeout: 30s
140
- }
141
- ```
142
-
143
- 列表项本身可以是块,允许包含多段落或其他块:
129
+ ### 4. 列表与映射 / Lists & Maps
130
+
131
+ **Unordered** (`-` or `*`):
144
132
  ```nova
145
- - @p "第一点详细说明"
146
- @note "补充信息"
147
- - @p "第二点"
133
+ @ul {
134
+ - Apple
135
+ - Banana
136
+ - Orange
137
+ }
148
138
  ```
149
139
 
150
- ---
140
+ **Ordered** (`+`):
141
+ ```nova
142
+ @ol {
143
+ + Step one
144
+ + Step two
145
+ }
146
+ ```
147
+
148
+ **Maps** — key-value pairs:
149
+ ```nova
150
+ @config {
151
+ host: "localhost"
152
+ port: 8080
153
+ timeout: 30s
154
+ }
155
+ ```
151
156
 
152
- ### 5. 表格系统(融合 CSV 紧凑 + 管道表可读性)
157
+ List items can be blocks themselves:
158
+ ```nova
159
+ - @p "First point with details"
160
+ @note "Supplementary info"
161
+ - @p "Second point"
162
+ ```
153
163
 
154
- Nova 提供三种表格写法,适应不同场景。
164
+ ---
155
165
 
156
- #### 5.1 内联二维数组(CSV 风格)
166
+ ### 5. 表格系统 / Tables
167
+
168
+ #### 5.1 Inline 2D Array (CSV style)
157
169
  ```nova
158
170
  @table {
159
- [["姓名", "年龄", "城市"],
160
- ["张三", 30, "北京"],
161
- ["李四", 25, "上海"]]
171
+ [["Name", "Age", "City"],
172
+ ["Alice", 30, "Beijing"],
173
+ ["Bob", 25, "Shanghai"]]
162
174
  }
163
175
  ```
164
176
 
165
- #### 5.2 带表头的块表(可读性)
177
+ #### 5.2 Block table with headers
166
178
  ```nova
167
179
  @table {
168
- @header { 姓名, 年龄, 城市 }
169
- @row { 张三, 30, 北京 }
170
- @row { 李四, 25, 上海 }
180
+ @header { Name, Age, City }
181
+ @row { Alice, 30, Beijing }
182
+ @row { Bob, 25, Shanghai }
171
183
  }
172
184
  ```
173
185
 
174
- #### 5.3 外部数据引用(CSV 文件绑定)
186
+ #### 5.3 External data reference
175
187
  ```nova
176
- @table(src: @csv("data/measurements.csv"), caption: "测量数据")
188
+ @table(src: @csv("data/measurements.csv"), caption: "Measurement Data")
177
189
  ```
178
- 这样保留了 CSV 的简单数据交换能力,同时能被解析器直接处理。
179
190
 
180
191
  ---
181
192
 
182
- ### 6. 宏与变量(TeX + 现代模板)
193
+ ### 6. 宏与变量 / Macros & Variables
194
+
195
+ Define macros with `@def` or `@macro`, supporting positional, keyword, and block parameters.
183
196
 
184
- 宏定义使用 `@def` 或 `@macro`,支持位置参数和块参数。
185
197
  ```nova
186
198
  @def greet(name) {
187
- @p "您好,#{name}"
199
+ @p "Hello, #{name}!"
188
200
  }
189
201
 
190
- @def framed(title: String = "提示", @content) {
202
+ @def framed(title: String = "Notice", @content) {
191
203
  @div(style: "border") {
192
204
  @strong "#{title}"
193
205
  @content
194
206
  }
195
207
  }
196
208
 
197
- @greet("世界")
198
- @framed("警告") {
199
- 这是一条重要信息。
209
+ @greet("World")
210
+ @framed("Warning") {
211
+ This is important information.
200
212
  }
201
213
  ```
202
- 调用方式与普通块完全一致,实现了 **标记即代码**。
203
214
 
204
- 还支持**命名参数**、**默认值**和**块参数**(如 `@content`),这吸收了 LaTeX3 的新特性,但语法更清晰。
215
+ Calls are syntactically identical to regular blocks — **markup is code**.
205
216
 
206
217
  ---
207
218
 
208
- ### 7. 类型定义与代码生成(gencode / 接口描述语言)
219
+ ### 7. 类型定义与代码生成 / Types & Code Generation
220
+
221
+ Define strongly-typed schemas for code generation, data validation, or API contracts.
209
222
 
210
- Nova 可直接定义强类型消息,用于生成序列化代码、验证数据,或作为 API 合同。
211
223
  ```nova
212
224
  @schema(Person) {
213
225
  id: Int32 @1
214
226
  name: String @2 = ""
215
- email: String? @3 // ? 表示可选
227
+ email: String? @3 // ? means optional
216
228
  tags: List<String> @4
217
229
  }
218
230
 
@@ -222,20 +234,24 @@ Nova 可直接定义强类型消息,用于生成序列化代码、验证数据
222
234
  updateUser(id: Int32, data: UpdateMask) -> Person
223
235
  }
224
236
  ```
225
- 编译器可根据这些定义输出 Go struct、Protobuf、JSON Schema 或 Python dataclass。这继承了 gencode 的核心优势,并且语法与文档其他部分无缝融合。
237
+
238
+ The compiler can output Go structs, Protobuf, JSON Schema, or Python dataclasses.
226
239
 
227
240
  ---
228
241
 
229
- ### 8. 交叉引用与参考文献(LaTeX 优势)
242
+ ### 8. 交叉引用与参考文献 / Cross-references & Bibliography
243
+
244
+ - **Label**: `@label(identifier)`
245
+ - **Reference**: `@ref(identifier)`
246
+ - **Citation**: `@cite(key)`
230
247
 
231
- **标签**使用 `@label(标识符)`,**引用**使用 `@ref(标识符)`,**文献**使用 `@cite(key)`。
232
248
  ```nova
233
249
  @chapter(id: "intro") {
234
- @title "简介"
250
+ @title "Introduction"
235
251
  @label(sec:intro)
236
252
  }
237
253
 
238
- 参见 @ref(sec:intro) 的讨论。该方法源自 @cite(lamport94)
254
+ See @ref(sec:intro) for discussion. This method originates from @cite(lamport94).
239
255
 
240
256
  @bibliography {
241
257
  @entry(key: lamport94, type: book,
@@ -244,70 +260,68 @@ Nova 可直接定义强类型消息,用于生成序列化代码、验证数据
244
260
  year: 1994)
245
261
  }
246
262
  ```
247
- 文档的元数据中可指定参考文献风格,生成 PDF 或 HTML 时自动格式化。
248
263
 
249
264
  ---
250
265
 
251
- ### 9. 环境与条件(TeX 环境 + 现代流程控制)
252
-
253
- - **环境块**:`@if(条件) { ... }`,`@for(item in list) { ... }`。
254
- - **条件显示**:
255
- ```nova
256
- @if(@defined(debug)) {
257
- @warn "调试模式开启,当前值:#{value}"
258
- }
259
- ```
260
- - **循环生成列表项**:
261
- ```nova
262
- @ul {
263
- @for(user in users) {
264
- - @strong(user.name) (#{user.email})
265
- }
266
- }
267
- ```
268
-
269
- 这使得文档不仅仅是静态文本,而是带有轻量逻辑的**活文档**。
266
+ ### 9. 流程控制 / Flow Control
267
+
268
+ - **Conditional**: `@if(condition) { ... }` `@else { ... }`
269
+ - **Loop**: `@for(item in list) { ... }`
270
+
271
+ ```nova
272
+ @if(@defined(debug)) {
273
+ @warn "Debug mode: #{value}"
274
+ }
275
+
276
+ @ul {
277
+ @for(user in users) {
278
+ - @strong(user.name) (#{user.email})
279
+ }
280
+ }
281
+ ```
282
+
283
+ Documents become **living documents** with lightweight logic, not just static text.
270
284
 
271
285
  ---
272
286
 
273
- ### 10. 完整综合示例
287
+ ### 10. 完整综合示例 / Complete Example
274
288
 
275
289
  ```nova
276
290
  @use "nova/std"
277
291
  @use "nova/plot"
278
292
 
279
293
  @meta {
280
- title: "Nova 语言白皮书"
294
+ title: "Nova Language Whitepaper"
281
295
  authors: ["Li Hua", "Zhang Wei"]
282
296
  version: 1.0
283
297
  }
284
298
 
285
299
  @page {
286
- @title "Nova 语言白皮书"
300
+ @title "Nova Language Whitepaper"
287
301
 
288
302
  @abstract {
289
- Nova 统一了文档与数据,提供前所未有的编写体验。
290
- 详见 @ref(sec:design)
303
+ Nova unifies document and data, providing an unprecedented authoring experience.
304
+ See @ref(sec:design) for details.
291
305
  }
292
306
 
293
307
  @chapter(id: "intro") @label(sec:intro) {
294
- @p "本文介绍 Nova 的语法及设计理念。"
295
- @p "数学示例:能量守恒 $E = mc^2$。"
308
+ @p "This paper describes Nova's syntax and design philosophy."
309
+ @p "Math example: conservation of energy $E = mc^2$."
296
310
  }
297
311
 
298
312
  @chapter(id: "design") @label(sec:design) {
299
- @p "核心架构基于统一函数式块。"
300
- @table(caption: "主流语言对比") {
301
- @header { 特性, HTML, YAML, TeX, Nova }
302
- @row { 标签, ✅, ❌, ✅, ✅ 函数式 }
303
- @row { 缩进块, ❌, ✅, 部分, ✅ }
304
- @row { 数学, ❌, ❌, ✅, ✅ }
305
- @row { 类型定义, ❌, ❌, ❌, ✅ }
313
+ @p "Core architecture is based on unified functional blocks."
314
+ @table(caption: "Language Comparison") {
315
+ @header { Feature, HTML, YAML, TeX, Nova }
316
+ @row { Tags, ✅, ❌, ✅, ✅ Functional }
317
+ @row { Indentation, ❌, ✅, Partial, ✅ }
318
+ @row { Math, ❌, ❌, ✅, ✅ }
319
+ @row { Type Defs, ❌, ❌, ❌, ✅ }
306
320
  }
307
321
  }
308
322
 
309
323
  @chapter(id: "api") {
310
- @p "数据模型定义:"
324
+ @p "Data model definition:"
311
325
  @schema(Measurement) {
312
326
  sensor_id: Int32 @1
313
327
  value: Float64 @2 = 0.0
@@ -319,4 +333,4 @@ Nova 可直接定义强类型消息,用于生成序列化代码、验证数据
319
333
  @entry(key: nova2026, title: "Nova Language Spec", year: 2026)
320
334
  }
321
335
  }
322
- ```
336
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nova-lang/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Nova: Nested Ordered Versatile Architecture — a programmable markup language CLI",
5
5
  "license": "MIT",
6
6
  "keywords": [