@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.
- package/README.md +158 -144
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
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
|
-
#
|
|
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
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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.
|
|
75
|
+
### 2. 块语法 / Block Syntax
|
|
67
76
|
|
|
68
|
-
|
|
77
|
+
A block's basic form:
|
|
69
78
|
|
|
70
79
|
```nova
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
|
|
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
|
-
|
|
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.
|
|
111
|
+
### 3. 内联元素与格式 / Inline Elements & Formatting
|
|
112
|
+
|
|
113
|
+
Inline content uses `@tag{ text }` or `@tag(attrs){ text }`:
|
|
102
114
|
|
|
103
|
-
内联内容使用 `@标记{ 文本 }` 或 `@标记(属性){ 文本 }`:
|
|
104
115
|
```nova
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
-
|
|
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.
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
164
|
+
---
|
|
155
165
|
|
|
156
|
-
|
|
166
|
+
### 5. 表格系统 / Tables
|
|
167
|
+
|
|
168
|
+
#### 5.1 Inline 2D Array (CSV style)
|
|
157
169
|
```nova
|
|
158
170
|
@table {
|
|
159
|
-
[["
|
|
160
|
-
["
|
|
161
|
-
["
|
|
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 {
|
|
170
|
-
@row {
|
|
180
|
+
@header { Name, Age, City }
|
|
181
|
+
@row { Alice, 30, Beijing }
|
|
182
|
+
@row { Bob, 25, Shanghai }
|
|
171
183
|
}
|
|
172
184
|
```
|
|
173
185
|
|
|
174
|
-
#### 5.3
|
|
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.
|
|
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 "
|
|
199
|
+
@p "Hello, #{name}!"
|
|
188
200
|
}
|
|
189
201
|
|
|
190
|
-
@def framed(title: String = "
|
|
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
|
-
|
|
215
|
+
Calls are syntactically identical to regular blocks — **markup is code**.
|
|
205
216
|
|
|
206
217
|
---
|
|
207
218
|
|
|
208
|
-
### 7.
|
|
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
|
-
|
|
237
|
+
|
|
238
|
+
The compiler can output Go structs, Protobuf, JSON Schema, or Python dataclasses.
|
|
226
239
|
|
|
227
240
|
---
|
|
228
241
|
|
|
229
|
-
### 8.
|
|
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
|
-
|
|
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.
|
|
252
|
-
|
|
253
|
-
-
|
|
254
|
-
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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 "
|
|
295
|
-
@p "
|
|
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 {
|
|
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
|
+
```
|