diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-04-22 16:41:46 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-04-22 16:41:46 +0800 |
| commit | 56b76f68f127e438880bbd1a6178c67bd7d59cab (patch) | |
| tree | 95a21814cf4751807023b60ad5c3f2effa41fa99 | |
| parent | d4e8b147694f35ac37c48dbfdd4b179c892beb01 (diff) | |
| download | yuescript-56b76f68f127e438880bbd1a6178c67bd7d59cab.tar.gz yuescript-56b76f68f127e438880bbd1a6178c67bd7d59cab.tar.bz2 yuescript-56b76f68f127e438880bbd1a6178c67bd7d59cab.zip | |
Updated docs.
| -rw-r--r-- | doc/docs/de/doc/advanced/macro.md | 56 | ||||
| -rw-r--r-- | doc/docs/doc/advanced/macro.md | 56 | ||||
| -rw-r--r-- | doc/docs/id-id/doc/advanced/macro.md | 56 | ||||
| -rw-r--r-- | doc/docs/pt-br/doc/advanced/macro.md | 56 | ||||
| -rw-r--r-- | doc/docs/zh/doc/advanced/macro.md | 56 | ||||
| -rw-r--r-- | doc/yue-de.md | 27 | ||||
| -rw-r--r-- | doc/yue-en.md | 27 | ||||
| -rw-r--r-- | doc/yue-id-id.md | 27 | ||||
| -rw-r--r-- | doc/yue-pt-br.md | 27 | ||||
| -rw-r--r-- | doc/yue-zh.md | 27 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_de.lua | 24 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_en.lua | 24 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_id-id.lua | 24 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_pt-br.lua | 24 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 24 |
15 files changed, 535 insertions, 0 deletions
diff --git a/doc/docs/de/doc/advanced/macro.md b/doc/docs/de/doc/advanced/macro.md index a030aea..d0760b5 100644 --- a/doc/docs/de/doc/advanced/macro.md +++ b/doc/docs/de/doc/advanced/macro.md | |||
| @@ -229,6 +229,62 @@ print "Gültiger Enum-Typ:", $BodyType Static | |||
| 229 | 229 | ||
| 230 | </YueDisplay> | 230 | </YueDisplay> |
| 231 | 231 | ||
| 232 | ## Mehrzeiligen Yue-Code erzeugen | ||
| 233 | |||
| 234 | Wenn ein Makro mehrzeiligen Yue-Code zurückgibt, ist eine mehrzeilige Zeichenkette in Anführungszeichen nicht zu empfehlen. Verwende stattdessen bevorzugt `-> |`. | ||
| 235 | |||
| 236 | Eine Zeichenkette in Anführungszeichen behält den Text wörtlich bei, während ein YAML-Mehrzeilen-String die gemeinsame führende Einrückung entfernt. Dadurch bleiben erzeugte Yue-Blöcke in der Regel stabiler, besonders wenn der erzeugte Code Kommentare oder verschachtelte Blöcke enthält. | ||
| 237 | |||
| 238 | ```yuescript | ||
| 239 | macro default_conf = (conf) -> " | ||
| 240 | -- useful; only set once | ||
| 241 | #{conf}.identity = 'LOVE' | ||
| 242 | #{conf}.version = \"11.5\" | ||
| 243 | " | ||
| 244 | |||
| 245 | love.conf = (t) -> | ||
| 246 | $default_conf t | ||
| 247 | ``` | ||
| 248 | |||
| 249 | <YueDisplay> | ||
| 250 | |||
| 251 | ```yue | ||
| 252 | macro default_conf = (conf) -> " | ||
| 253 | -- useful; only set once | ||
| 254 | #{conf}.identity = 'LOVE' | ||
| 255 | #{conf}.version = \"11.5\" | ||
| 256 | " | ||
| 257 | |||
| 258 | love.conf = (t) -> | ||
| 259 | $default_conf t | ||
| 260 | ``` | ||
| 261 | |||
| 262 | </YueDisplay> | ||
| 263 | |||
| 264 | ```yuescript | ||
| 265 | macro default_conf = (conf) -> | | ||
| 266 | -- useful; only set once | ||
| 267 | #{conf}.identity = 'LOVE' | ||
| 268 | #{conf}.version = "11.5" | ||
| 269 | |||
| 270 | love.conf = (t) -> | ||
| 271 | $default_conf t | ||
| 272 | ``` | ||
| 273 | |||
| 274 | <YueDisplay> | ||
| 275 | |||
| 276 | ```yue | ||
| 277 | macro default_conf = (conf) -> | | ||
| 278 | -- useful; only set once | ||
| 279 | #{conf}.identity = 'LOVE' | ||
| 280 | #{conf}.version = "11.5" | ||
| 281 | |||
| 282 | love.conf = (t) -> | ||
| 283 | $default_conf t | ||
| 284 | ``` | ||
| 285 | |||
| 286 | </YueDisplay> | ||
| 287 | |||
| 232 | ## Argument-Validierung | 288 | ## Argument-Validierung |
| 233 | 289 | ||
| 234 | Du kannst erwartete AST-Knotentypen in der Argumentliste deklarieren und zur Compile-Zeit prüfen, ob die übergebenen Makroargumente den Erwartungen entsprechen. | 290 | Du kannst erwartete AST-Knotentypen in der Argumentliste deklarieren und zur Compile-Zeit prüfen, ob die übergebenen Makroargumente den Erwartungen entsprechen. |
diff --git a/doc/docs/doc/advanced/macro.md b/doc/docs/doc/advanced/macro.md index c057f40..935017e 100644 --- a/doc/docs/doc/advanced/macro.md +++ b/doc/docs/doc/advanced/macro.md | |||
| @@ -229,6 +229,62 @@ print "Valid enum type:", $BodyType Static | |||
| 229 | 229 | ||
| 230 | </YueDisplay> | 230 | </YueDisplay> |
| 231 | 231 | ||
| 232 | ## Generating Multi-line Yue Code | ||
| 233 | |||
| 234 | When a macro returns multi-line Yue code, using a quoted multi-line string is not recommended. Prefer `-> |` instead. | ||
| 235 | |||
| 236 | A quoted string keeps the literal text as-is, while a YAML multiline string removes the common leading indentation. This usually makes generated Yue blocks more stable, especially when the generated code contains comments or nested blocks. | ||
| 237 | |||
| 238 | ```yuescript | ||
| 239 | macro default_conf = (conf) -> " | ||
| 240 | -- useful; only set once | ||
| 241 | #{conf}.identity = 'LOVE' | ||
| 242 | #{conf}.version = \"11.5\" | ||
| 243 | " | ||
| 244 | |||
| 245 | love.conf = (t) -> | ||
| 246 | $default_conf t | ||
| 247 | ``` | ||
| 248 | |||
| 249 | <YueDisplay> | ||
| 250 | |||
| 251 | ```yue | ||
| 252 | macro default_conf = (conf) -> " | ||
| 253 | -- useful; only set once | ||
| 254 | #{conf}.identity = 'LOVE' | ||
| 255 | #{conf}.version = \"11.5\" | ||
| 256 | " | ||
| 257 | |||
| 258 | love.conf = (t) -> | ||
| 259 | $default_conf t | ||
| 260 | ``` | ||
| 261 | |||
| 262 | </YueDisplay> | ||
| 263 | |||
| 264 | ```yuescript | ||
| 265 | macro default_conf = (conf) -> | | ||
| 266 | -- useful; only set once | ||
| 267 | #{conf}.identity = 'LOVE' | ||
| 268 | #{conf}.version = "11.5" | ||
| 269 | |||
| 270 | love.conf = (t) -> | ||
| 271 | $default_conf t | ||
| 272 | ``` | ||
| 273 | |||
| 274 | <YueDisplay> | ||
| 275 | |||
| 276 | ```yue | ||
| 277 | macro default_conf = (conf) -> | | ||
| 278 | -- useful; only set once | ||
| 279 | #{conf}.identity = 'LOVE' | ||
| 280 | #{conf}.version = "11.5" | ||
| 281 | |||
| 282 | love.conf = (t) -> | ||
| 283 | $default_conf t | ||
| 284 | ``` | ||
| 285 | |||
| 286 | </YueDisplay> | ||
| 287 | |||
| 232 | ## Argument Validation | 288 | ## Argument Validation |
| 233 | 289 | ||
| 234 | You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time. | 290 | You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time. |
diff --git a/doc/docs/id-id/doc/advanced/macro.md b/doc/docs/id-id/doc/advanced/macro.md index d33ec5b..5f0021b 100644 --- a/doc/docs/id-id/doc/advanced/macro.md +++ b/doc/docs/id-id/doc/advanced/macro.md | |||
| @@ -229,6 +229,62 @@ print "Valid enum type:", $BodyType Static | |||
| 229 | 229 | ||
| 230 | </YueDisplay> | 230 | </YueDisplay> |
| 231 | 231 | ||
| 232 | ## Menghasilkan kode Yue multi-baris | ||
| 233 | |||
| 234 | Saat macro mengembalikan kode Yue multi-baris, penggunaan string multi-baris di dalam tanda kutip tidak direkomendasikan. Sebaiknya gunakan `-> |`. | ||
| 235 | |||
| 236 | String bertanda kutip mempertahankan teks apa adanya, sedangkan string multi-baris YAML menghapus indentasi awal yang sama. Ini biasanya membuat blok Yue yang dihasilkan lebih stabil, terutama ketika kode yang dihasilkan berisi komentar atau blok bertingkat. | ||
| 237 | |||
| 238 | ```yuescript | ||
| 239 | macro default_conf = (conf) -> " | ||
| 240 | -- useful; only set once | ||
| 241 | #{conf}.identity = 'LOVE' | ||
| 242 | #{conf}.version = \"11.5\" | ||
| 243 | " | ||
| 244 | |||
| 245 | love.conf = (t) -> | ||
| 246 | $default_conf t | ||
| 247 | ``` | ||
| 248 | |||
| 249 | <YueDisplay> | ||
| 250 | |||
| 251 | ```yue | ||
| 252 | macro default_conf = (conf) -> " | ||
| 253 | -- useful; only set once | ||
| 254 | #{conf}.identity = 'LOVE' | ||
| 255 | #{conf}.version = \"11.5\" | ||
| 256 | " | ||
| 257 | |||
| 258 | love.conf = (t) -> | ||
| 259 | $default_conf t | ||
| 260 | ``` | ||
| 261 | |||
| 262 | </YueDisplay> | ||
| 263 | |||
| 264 | ```yuescript | ||
| 265 | macro default_conf = (conf) -> | | ||
| 266 | -- useful; only set once | ||
| 267 | #{conf}.identity = 'LOVE' | ||
| 268 | #{conf}.version = "11.5" | ||
| 269 | |||
| 270 | love.conf = (t) -> | ||
| 271 | $default_conf t | ||
| 272 | ``` | ||
| 273 | |||
| 274 | <YueDisplay> | ||
| 275 | |||
| 276 | ```yue | ||
| 277 | macro default_conf = (conf) -> | | ||
| 278 | -- useful; only set once | ||
| 279 | #{conf}.identity = 'LOVE' | ||
| 280 | #{conf}.version = "11.5" | ||
| 281 | |||
| 282 | love.conf = (t) -> | ||
| 283 | $default_conf t | ||
| 284 | ``` | ||
| 285 | |||
| 286 | </YueDisplay> | ||
| 287 | |||
| 232 | ## Validasi Argumen | 288 | ## Validasi Argumen |
| 233 | 289 | ||
| 234 | Anda dapat mendeklarasikan tipe node AST yang diharapkan dalam daftar argumen, dan memeriksa apakah argumen macro yang masuk memenuhi harapan pada waktu kompilasi. | 290 | Anda dapat mendeklarasikan tipe node AST yang diharapkan dalam daftar argumen, dan memeriksa apakah argumen macro yang masuk memenuhi harapan pada waktu kompilasi. |
diff --git a/doc/docs/pt-br/doc/advanced/macro.md b/doc/docs/pt-br/doc/advanced/macro.md index 18d33e0..d1025d1 100644 --- a/doc/docs/pt-br/doc/advanced/macro.md +++ b/doc/docs/pt-br/doc/advanced/macro.md | |||
| @@ -228,6 +228,62 @@ print "Valid enum type:", $BodyType Static | |||
| 228 | 228 | ||
| 229 | </YueDisplay> | 229 | </YueDisplay> |
| 230 | 230 | ||
| 231 | ## Gerando código Yue em múltiplas linhas | ||
| 232 | |||
| 233 | Quando uma macro retorna código Yue em múltiplas linhas, não é recomendado usar uma string multilinha entre aspas. Prefira `-> |`. | ||
| 234 | |||
| 235 | Uma string entre aspas preserva o texto literal, enquanto uma string multilinha estilo YAML remove a indentação inicial comum. Isso normalmente deixa os blocos Yue gerados mais estáveis, especialmente quando o código gerado contém comentários ou blocos aninhados. | ||
| 236 | |||
| 237 | ```yuescript | ||
| 238 | macro default_conf = (conf) -> " | ||
| 239 | -- useful; only set once | ||
| 240 | #{conf}.identity = 'LOVE' | ||
| 241 | #{conf}.version = \"11.5\" | ||
| 242 | " | ||
| 243 | |||
| 244 | love.conf = (t) -> | ||
| 245 | $default_conf t | ||
| 246 | ``` | ||
| 247 | |||
| 248 | <YueDisplay> | ||
| 249 | |||
| 250 | ```yue | ||
| 251 | macro default_conf = (conf) -> " | ||
| 252 | -- useful; only set once | ||
| 253 | #{conf}.identity = 'LOVE' | ||
| 254 | #{conf}.version = \"11.5\" | ||
| 255 | " | ||
| 256 | |||
| 257 | love.conf = (t) -> | ||
| 258 | $default_conf t | ||
| 259 | ``` | ||
| 260 | |||
| 261 | </YueDisplay> | ||
| 262 | |||
| 263 | ```yuescript | ||
| 264 | macro default_conf = (conf) -> | | ||
| 265 | -- useful; only set once | ||
| 266 | #{conf}.identity = 'LOVE' | ||
| 267 | #{conf}.version = "11.5" | ||
| 268 | |||
| 269 | love.conf = (t) -> | ||
| 270 | $default_conf t | ||
| 271 | ``` | ||
| 272 | |||
| 273 | <YueDisplay> | ||
| 274 | |||
| 275 | ```yue | ||
| 276 | macro default_conf = (conf) -> | | ||
| 277 | -- useful; only set once | ||
| 278 | #{conf}.identity = 'LOVE' | ||
| 279 | #{conf}.version = "11.5" | ||
| 280 | |||
| 281 | love.conf = (t) -> | ||
| 282 | $default_conf t | ||
| 283 | ``` | ||
| 284 | |||
| 285 | </YueDisplay> | ||
| 286 | |||
| 231 | ## Validação de argumentos | 287 | ## Validação de argumentos |
| 232 | 288 | ||
| 233 | Você pode declarar os tipos de nós AST esperados na lista de argumentos e verificar se os argumentos da macro recebidos atendem às expectativas em tempo de compilação. | 289 | Você pode declarar os tipos de nós AST esperados na lista de argumentos e verificar se os argumentos da macro recebidos atendem às expectativas em tempo de compilação. |
diff --git a/doc/docs/zh/doc/advanced/macro.md b/doc/docs/zh/doc/advanced/macro.md index 64cfa6d..7027f62 100644 --- a/doc/docs/zh/doc/advanced/macro.md +++ b/doc/docs/zh/doc/advanced/macro.md | |||
| @@ -229,6 +229,62 @@ print "有效的枚举类型:", $BodyType Static | |||
| 229 | 229 | ||
| 230 | </YueDisplay> | 230 | </YueDisplay> |
| 231 | 231 | ||
| 232 | ## 生成多行 Yue 代码 | ||
| 233 | |||
| 234 |   当宏返回多行 Yue 代码时,不推荐使用带引号的多行字符串,建议优先使用 `-> |`。 | ||
| 235 | |||
| 236 |   带引号的字符串会按字面保留文本;而 YAML 风格多行字符串会移除公共前导缩进。对宏生成的 Yue 代码来说,这通常能让代码块结构更稳定,尤其是在生成代码里包含注释或嵌套块时。 | ||
| 237 | |||
| 238 | ```yuescript | ||
| 239 | macro default_conf = (conf) -> " | ||
| 240 | -- useful; only set once | ||
| 241 | #{conf}.identity = 'LOVE' | ||
| 242 | #{conf}.version = \"11.5\" | ||
| 243 | " | ||
| 244 | |||
| 245 | love.conf = (t) -> | ||
| 246 | $default_conf t | ||
| 247 | ``` | ||
| 248 | |||
| 249 | <YueDisplay> | ||
| 250 | |||
| 251 | ```yue | ||
| 252 | macro default_conf = (conf) -> " | ||
| 253 | -- useful; only set once | ||
| 254 | #{conf}.identity = 'LOVE' | ||
| 255 | #{conf}.version = \"11.5\" | ||
| 256 | " | ||
| 257 | |||
| 258 | love.conf = (t) -> | ||
| 259 | $default_conf t | ||
| 260 | ``` | ||
| 261 | |||
| 262 | </YueDisplay> | ||
| 263 | |||
| 264 | ```yuescript | ||
| 265 | macro default_conf = (conf) -> | | ||
| 266 | -- useful; only set once | ||
| 267 | #{conf}.identity = 'LOVE' | ||
| 268 | #{conf}.version = "11.5" | ||
| 269 | |||
| 270 | love.conf = (t) -> | ||
| 271 | $default_conf t | ||
| 272 | ``` | ||
| 273 | |||
| 274 | <YueDisplay> | ||
| 275 | |||
| 276 | ```yue | ||
| 277 | macro default_conf = (conf) -> | | ||
| 278 | -- useful; only set once | ||
| 279 | #{conf}.identity = 'LOVE' | ||
| 280 | #{conf}.version = "11.5" | ||
| 281 | |||
| 282 | love.conf = (t) -> | ||
| 283 | $default_conf t | ||
| 284 | ``` | ||
| 285 | |||
| 286 | </YueDisplay> | ||
| 287 | |||
| 232 | ## 宏参数检查 | 288 | ## 宏参数检查 |
| 233 | 289 | ||
| 234 |   可以直接在参数列表中声明期望的 AST 节点类型,并在编译时检查传入的宏参数是否符合预期。 | 290 |   可以直接在参数列表中声明期望的 AST 节点类型,并在编译时检查传入的宏参数是否符合预期。 |
diff --git a/doc/yue-de.md b/doc/yue-de.md index 97063f4..0d4fa7a 100644 --- a/doc/yue-de.md +++ b/doc/yue-de.md | |||
| @@ -183,6 +183,33 @@ print "Gültiger Enum-Typ:", $BodyType Static | |||
| 183 | -- print "Kompilierungsfehler bei Enum-Typ:", $BodyType Unknown | 183 | -- print "Kompilierungsfehler bei Enum-Typ:", $BodyType Unknown |
| 184 | ``` | 184 | ``` |
| 185 | 185 | ||
| 186 | ## Mehrzeiligen Yue-Code erzeugen | ||
| 187 | |||
| 188 | Wenn ein Makro mehrzeiligen Yue-Code zurückgibt, ist eine mehrzeilige Zeichenkette in Anführungszeichen nicht zu empfehlen. Verwende stattdessen bevorzugt `-> |`. | ||
| 189 | |||
| 190 | Eine Zeichenkette in Anführungszeichen behält den Text wörtlich bei, während ein YAML-Mehrzeilen-String die gemeinsame führende Einrückung entfernt. Dadurch bleiben erzeugte Yue-Blöcke in der Regel stabiler, besonders wenn der erzeugte Code Kommentare oder verschachtelte Blöcke enthält. | ||
| 191 | |||
| 192 | ```yuescript | ||
| 193 | macro default_conf = (conf) -> " | ||
| 194 | -- useful; only set once | ||
| 195 | #{conf}.identity = 'LOVE' | ||
| 196 | #{conf}.version = \"11.5\" | ||
| 197 | " | ||
| 198 | |||
| 199 | love.conf = (t) -> | ||
| 200 | $default_conf t | ||
| 201 | ``` | ||
| 202 | |||
| 203 | ```yuescript | ||
| 204 | macro default_conf = (conf) -> | | ||
| 205 | -- useful; only set once | ||
| 206 | #{conf}.identity = 'LOVE' | ||
| 207 | #{conf}.version = "11.5" | ||
| 208 | |||
| 209 | love.conf = (t) -> | ||
| 210 | $default_conf t | ||
| 211 | ``` | ||
| 212 | |||
| 186 | ## Argument-Validierung | 213 | ## Argument-Validierung |
| 187 | 214 | ||
| 188 | Du kannst erwartete AST-Knotentypen in der Argumentliste deklarieren und zur Compile-Zeit prüfen, ob die übergebenen Makroargumente den Erwartungen entsprechen. | 215 | Du kannst erwartete AST-Knotentypen in der Argumentliste deklarieren und zur Compile-Zeit prüfen, ob die übergebenen Makroargumente den Erwartungen entsprechen. |
diff --git a/doc/yue-en.md b/doc/yue-en.md index 8f8370d..2c97b28 100644 --- a/doc/yue-en.md +++ b/doc/yue-en.md | |||
| @@ -183,6 +183,33 @@ print "Valid enum type:", $BodyType Static | |||
| 183 | -- print "Compilation error with enum type:", $BodyType Unknown | 183 | -- print "Compilation error with enum type:", $BodyType Unknown |
| 184 | ``` | 184 | ``` |
| 185 | 185 | ||
| 186 | ## Generating Multi-line Yue Code | ||
| 187 | |||
| 188 | When a macro returns multi-line Yue code, using a quoted multi-line string is not recommended. Prefer `-> |` instead. | ||
| 189 | |||
| 190 | A quoted string keeps the literal text as-is, while a YAML multiline string removes the common leading indentation. This usually makes generated Yue blocks more stable, especially when the generated code contains comments or nested blocks. | ||
| 191 | |||
| 192 | ```yuescript | ||
| 193 | macro default_conf = (conf) -> " | ||
| 194 | -- useful; only set once | ||
| 195 | #{conf}.identity = 'LOVE' | ||
| 196 | #{conf}.version = \"11.5\" | ||
| 197 | " | ||
| 198 | |||
| 199 | love.conf = (t) -> | ||
| 200 | $default_conf t | ||
| 201 | ``` | ||
| 202 | |||
| 203 | ```yuescript | ||
| 204 | macro default_conf = (conf) -> | | ||
| 205 | -- useful; only set once | ||
| 206 | #{conf}.identity = 'LOVE' | ||
| 207 | #{conf}.version = "11.5" | ||
| 208 | |||
| 209 | love.conf = (t) -> | ||
| 210 | $default_conf t | ||
| 211 | ``` | ||
| 212 | |||
| 186 | ## Argument Validation | 213 | ## Argument Validation |
| 187 | 214 | ||
| 188 | You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time. | 215 | You can declare the expected AST node types in the argument list, and check whether the incoming macro arguments meet the expectations at compile time. |
diff --git a/doc/yue-id-id.md b/doc/yue-id-id.md index 39ba24d..8661ecf 100644 --- a/doc/yue-id-id.md +++ b/doc/yue-id-id.md | |||
| @@ -183,6 +183,33 @@ print "Valid enum type:", $BodyType Static | |||
| 183 | -- print "Compilation error with enum type:", $BodyType Unknown | 183 | -- print "Compilation error with enum type:", $BodyType Unknown |
| 184 | ``` | 184 | ``` |
| 185 | 185 | ||
| 186 | ## Menghasilkan kode Yue multi-baris | ||
| 187 | |||
| 188 | Saat macro mengembalikan kode Yue multi-baris, penggunaan string multi-baris di dalam tanda kutip tidak direkomendasikan. Sebaiknya gunakan `-> |`. | ||
| 189 | |||
| 190 | String bertanda kutip mempertahankan teks apa adanya, sedangkan string multi-baris YAML menghapus indentasi awal yang sama. Ini biasanya membuat blok Yue yang dihasilkan lebih stabil, terutama ketika kode yang dihasilkan berisi komentar atau blok bertingkat. | ||
| 191 | |||
| 192 | ```yuescript | ||
| 193 | macro default_conf = (conf) -> " | ||
| 194 | -- useful; only set once | ||
| 195 | #{conf}.identity = 'LOVE' | ||
| 196 | #{conf}.version = \"11.5\" | ||
| 197 | " | ||
| 198 | |||
| 199 | love.conf = (t) -> | ||
| 200 | $default_conf t | ||
| 201 | ``` | ||
| 202 | |||
| 203 | ```yuescript | ||
| 204 | macro default_conf = (conf) -> | | ||
| 205 | -- useful; only set once | ||
| 206 | #{conf}.identity = 'LOVE' | ||
| 207 | #{conf}.version = "11.5" | ||
| 208 | |||
| 209 | love.conf = (t) -> | ||
| 210 | $default_conf t | ||
| 211 | ``` | ||
| 212 | |||
| 186 | ## Validasi Argumen | 213 | ## Validasi Argumen |
| 187 | 214 | ||
| 188 | Anda dapat mendeklarasikan tipe node AST yang diharapkan dalam daftar argumen, dan memeriksa apakah argumen macro yang masuk memenuhi harapan pada waktu kompilasi. | 215 | Anda dapat mendeklarasikan tipe node AST yang diharapkan dalam daftar argumen, dan memeriksa apakah argumen macro yang masuk memenuhi harapan pada waktu kompilasi. |
diff --git a/doc/yue-pt-br.md b/doc/yue-pt-br.md index a0e3268..7bf5ab6 100644 --- a/doc/yue-pt-br.md +++ b/doc/yue-pt-br.md | |||
| @@ -183,6 +183,33 @@ print "Valid enum type:", $BodyType Static | |||
| 183 | -- print "Compilation error with enum type:", $BodyType Unknown | 183 | -- print "Compilation error with enum type:", $BodyType Unknown |
| 184 | ``` | 184 | ``` |
| 185 | 185 | ||
| 186 | ## Gerando código Yue em múltiplas linhas | ||
| 187 | |||
| 188 | Quando uma macro retorna código Yue em múltiplas linhas, não é recomendado usar uma string multilinha entre aspas. Prefira `-> |`. | ||
| 189 | |||
| 190 | Uma string entre aspas preserva o texto literal, enquanto uma string multilinha estilo YAML remove a indentação inicial comum. Isso normalmente deixa os blocos Yue gerados mais estáveis, especialmente quando o código gerado contém comentários ou blocos aninhados. | ||
| 191 | |||
| 192 | ```yuescript | ||
| 193 | macro default_conf = (conf) -> " | ||
| 194 | -- useful; only set once | ||
| 195 | #{conf}.identity = 'LOVE' | ||
| 196 | #{conf}.version = \"11.5\" | ||
| 197 | " | ||
| 198 | |||
| 199 | love.conf = (t) -> | ||
| 200 | $default_conf t | ||
| 201 | ``` | ||
| 202 | |||
| 203 | ```yuescript | ||
| 204 | macro default_conf = (conf) -> | | ||
| 205 | -- useful; only set once | ||
| 206 | #{conf}.identity = 'LOVE' | ||
| 207 | #{conf}.version = "11.5" | ||
| 208 | |||
| 209 | love.conf = (t) -> | ||
| 210 | $default_conf t | ||
| 211 | ``` | ||
| 212 | |||
| 186 | ## Validação de argumentos | 213 | ## Validação de argumentos |
| 187 | 214 | ||
| 188 | Você pode declarar os tipos de nós AST esperados na lista de argumentos e verificar se os argumentos da macro recebidos atendem às expectativas em tempo de compilação. | 215 | Você pode declarar os tipos de nós AST esperados na lista de argumentos e verificar se os argumentos da macro recebidos atendem às expectativas em tempo de compilação. |
diff --git a/doc/yue-zh.md b/doc/yue-zh.md index cb44d22..b69fcf6 100644 --- a/doc/yue-zh.md +++ b/doc/yue-zh.md | |||
| @@ -183,6 +183,33 @@ print "有效的枚举类型:", $BodyType Static | |||
| 183 | -- print "编译报错的枚举类型:", $BodyType Unknown | 183 | -- print "编译报错的枚举类型:", $BodyType Unknown |
| 184 | ``` | 184 | ``` |
| 185 | 185 | ||
| 186 | ## 生成多行 Yue 代码 | ||
| 187 | |||
| 188 |   当宏返回多行 Yue 代码时,不推荐使用带引号的多行字符串,建议优先使用 `-> |`。 | ||
| 189 | |||
| 190 |   带引号的字符串会按字面保留文本;而 YAML 风格多行字符串会移除公共前导缩进。对宏生成的 Yue 代码来说,这通常能让代码块结构更稳定,尤其是在生成代码里包含注释或嵌套块时。 | ||
| 191 | |||
| 192 | ```yuescript | ||
| 193 | macro default_conf = (conf) -> " | ||
| 194 | -- useful; only set once | ||
| 195 | #{conf}.identity = 'LOVE' | ||
| 196 | #{conf}.version = \"11.5\" | ||
| 197 | " | ||
| 198 | |||
| 199 | love.conf = (t) -> | ||
| 200 | $default_conf t | ||
| 201 | ``` | ||
| 202 | |||
| 203 | ```yuescript | ||
| 204 | macro default_conf = (conf) -> | | ||
| 205 | -- useful; only set once | ||
| 206 | #{conf}.identity = 'LOVE' | ||
| 207 | #{conf}.version = "11.5" | ||
| 208 | |||
| 209 | love.conf = (t) -> | ||
| 210 | $default_conf t | ||
| 211 | ``` | ||
| 212 | |||
| 186 | ## 宏参数检查 | 213 | ## 宏参数检查 |
| 187 | 214 | ||
| 188 |   可以直接在参数列表中声明期望的 AST 节点类型,并在编译时检查传入的宏参数是否符合预期。 | 215 |   可以直接在参数列表中声明期望的 AST 节点类型,并在编译时检查传入的宏参数是否符合预期。 |
diff --git a/spec/outputs/codes_from_doc_de.lua b/spec/outputs/codes_from_doc_de.lua index 28ed4e7..2530977 100644 --- a/spec/outputs/codes_from_doc_de.lua +++ b/spec/outputs/codes_from_doc_de.lua | |||
| @@ -125,6 +125,18 @@ end | |||
| 125 | print("yuescript") | 125 | print("yuescript") |
| 126 | print(2) | 126 | print(2) |
| 127 | print("Gültiger Enum-Typ:", "Static") | 127 | print("Gültiger Enum-Typ:", "Static") |
| 128 | love.conf = function(t) | ||
| 129 | do | ||
| 130 | t.identity = 'LOVE' | ||
| 131 | t.version = "11.5" | ||
| 132 | end | ||
| 133 | end | ||
| 134 | love.conf = function(t) | ||
| 135 | do | ||
| 136 | t.identity = 'LOVE' | ||
| 137 | t.version = "11.5" | ||
| 138 | end | ||
| 139 | end | ||
| 128 | do | 140 | do |
| 129 | print(123, "hallo") | 141 | print(123, "hallo") |
| 130 | end | 142 | end |
| @@ -164,6 +176,18 @@ end | |||
| 164 | print("yuescript") | 176 | print("yuescript") |
| 165 | print(2) | 177 | print(2) |
| 166 | print("Gültiger Enum-Typ:", "Static") | 178 | print("Gültiger Enum-Typ:", "Static") |
| 179 | love.conf = function(t) | ||
| 180 | do | ||
| 181 | t.identity = 'LOVE' | ||
| 182 | t.version = "11.5" | ||
| 183 | end | ||
| 184 | end | ||
| 185 | love.conf = function(t) | ||
| 186 | do | ||
| 187 | t.identity = 'LOVE' | ||
| 188 | t.version = "11.5" | ||
| 189 | end | ||
| 190 | end | ||
| 167 | do | 191 | do |
| 168 | print(123, "hallo") | 192 | print(123, "hallo") |
| 169 | end | 193 | end |
diff --git a/spec/outputs/codes_from_doc_en.lua b/spec/outputs/codes_from_doc_en.lua index 1fdc56d..18f0227 100644 --- a/spec/outputs/codes_from_doc_en.lua +++ b/spec/outputs/codes_from_doc_en.lua | |||
| @@ -125,6 +125,18 @@ end | |||
| 125 | print("yuescript") | 125 | print("yuescript") |
| 126 | print(2) | 126 | print(2) |
| 127 | print("Valid enum type:", "Static") | 127 | print("Valid enum type:", "Static") |
| 128 | love.conf = function(t) | ||
| 129 | do | ||
| 130 | t.identity = 'LOVE' | ||
| 131 | t.version = "11.5" | ||
| 132 | end | ||
| 133 | end | ||
| 134 | love.conf = function(t) | ||
| 135 | do | ||
| 136 | t.identity = 'LOVE' | ||
| 137 | t.version = "11.5" | ||
| 138 | end | ||
| 139 | end | ||
| 128 | do | 140 | do |
| 129 | print(123, "hello") | 141 | print(123, "hello") |
| 130 | end | 142 | end |
| @@ -164,6 +176,18 @@ end | |||
| 164 | print("yuescript") | 176 | print("yuescript") |
| 165 | print(2) | 177 | print(2) |
| 166 | print("Valid enum type:", "Static") | 178 | print("Valid enum type:", "Static") |
| 179 | love.conf = function(t) | ||
| 180 | do | ||
| 181 | t.identity = 'LOVE' | ||
| 182 | t.version = "11.5" | ||
| 183 | end | ||
| 184 | end | ||
| 185 | love.conf = function(t) | ||
| 186 | do | ||
| 187 | t.identity = 'LOVE' | ||
| 188 | t.version = "11.5" | ||
| 189 | end | ||
| 190 | end | ||
| 167 | do | 191 | do |
| 168 | print(123, "hello") | 192 | print(123, "hello") |
| 169 | end | 193 | end |
diff --git a/spec/outputs/codes_from_doc_id-id.lua b/spec/outputs/codes_from_doc_id-id.lua index 2201dee..452d88d 100644 --- a/spec/outputs/codes_from_doc_id-id.lua +++ b/spec/outputs/codes_from_doc_id-id.lua | |||
| @@ -125,6 +125,18 @@ end | |||
| 125 | print("yuescript") | 125 | print("yuescript") |
| 126 | print(2) | 126 | print(2) |
| 127 | print("Valid enum type:", "Static") | 127 | print("Valid enum type:", "Static") |
| 128 | love.conf = function(t) | ||
| 129 | do | ||
| 130 | t.identity = 'LOVE' | ||
| 131 | t.version = "11.5" | ||
| 132 | end | ||
| 133 | end | ||
| 134 | love.conf = function(t) | ||
| 135 | do | ||
| 136 | t.identity = 'LOVE' | ||
| 137 | t.version = "11.5" | ||
| 138 | end | ||
| 139 | end | ||
| 128 | do | 140 | do |
| 129 | print(123, "hello") | 141 | print(123, "hello") |
| 130 | end | 142 | end |
| @@ -164,6 +176,18 @@ end | |||
| 164 | print("yuescript") | 176 | print("yuescript") |
| 165 | print(2) | 177 | print(2) |
| 166 | print("Valid enum type:", "Static") | 178 | print("Valid enum type:", "Static") |
| 179 | love.conf = function(t) | ||
| 180 | do | ||
| 181 | t.identity = 'LOVE' | ||
| 182 | t.version = "11.5" | ||
| 183 | end | ||
| 184 | end | ||
| 185 | love.conf = function(t) | ||
| 186 | do | ||
| 187 | t.identity = 'LOVE' | ||
| 188 | t.version = "11.5" | ||
| 189 | end | ||
| 190 | end | ||
| 167 | do | 191 | do |
| 168 | print(123, "hello") | 192 | print(123, "hello") |
| 169 | end | 193 | end |
diff --git a/spec/outputs/codes_from_doc_pt-br.lua b/spec/outputs/codes_from_doc_pt-br.lua index b3bf0b3..f9784d7 100644 --- a/spec/outputs/codes_from_doc_pt-br.lua +++ b/spec/outputs/codes_from_doc_pt-br.lua | |||
| @@ -125,6 +125,18 @@ end | |||
| 125 | print("yuescript") | 125 | print("yuescript") |
| 126 | print(2) | 126 | print(2) |
| 127 | print("Valid enum type:", "Static") | 127 | print("Valid enum type:", "Static") |
| 128 | love.conf = function(t) | ||
| 129 | do | ||
| 130 | t.identity = 'LOVE' | ||
| 131 | t.version = "11.5" | ||
| 132 | end | ||
| 133 | end | ||
| 134 | love.conf = function(t) | ||
| 135 | do | ||
| 136 | t.identity = 'LOVE' | ||
| 137 | t.version = "11.5" | ||
| 138 | end | ||
| 139 | end | ||
| 128 | do | 140 | do |
| 129 | print(123, "hello") | 141 | print(123, "hello") |
| 130 | end | 142 | end |
| @@ -164,6 +176,18 @@ end | |||
| 164 | print("yuescript") | 176 | print("yuescript") |
| 165 | print(2) | 177 | print(2) |
| 166 | print("Valid enum type:", "Static") | 178 | print("Valid enum type:", "Static") |
| 179 | love.conf = function(t) | ||
| 180 | do | ||
| 181 | t.identity = 'LOVE' | ||
| 182 | t.version = "11.5" | ||
| 183 | end | ||
| 184 | end | ||
| 185 | love.conf = function(t) | ||
| 186 | do | ||
| 187 | t.identity = 'LOVE' | ||
| 188 | t.version = "11.5" | ||
| 189 | end | ||
| 190 | end | ||
| 167 | do | 191 | do |
| 168 | print(123, "hello") | 192 | print(123, "hello") |
| 169 | end | 193 | end |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 5756793..4c254a2 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -125,6 +125,18 @@ end | |||
| 125 | print("yuescript") | 125 | print("yuescript") |
| 126 | print(2) | 126 | print(2) |
| 127 | print("有效的枚举类型:", "Static") | 127 | print("有效的枚举类型:", "Static") |
| 128 | love.conf = function(t) | ||
| 129 | do | ||
| 130 | t.identity = 'LOVE' | ||
| 131 | t.version = "11.5" | ||
| 132 | end | ||
| 133 | end | ||
| 134 | love.conf = function(t) | ||
| 135 | do | ||
| 136 | t.identity = 'LOVE' | ||
| 137 | t.version = "11.5" | ||
| 138 | end | ||
| 139 | end | ||
| 128 | do | 140 | do |
| 129 | print(123, "hello") | 141 | print(123, "hello") |
| 130 | end | 142 | end |
| @@ -164,6 +176,18 @@ end | |||
| 164 | print("yuescript") | 176 | print("yuescript") |
| 165 | print(2) | 177 | print(2) |
| 166 | print("有效的枚举类型:", "Static") | 178 | print("有效的枚举类型:", "Static") |
| 179 | love.conf = function(t) | ||
| 180 | do | ||
| 181 | t.identity = 'LOVE' | ||
| 182 | t.version = "11.5" | ||
| 183 | end | ||
| 184 | end | ||
| 185 | love.conf = function(t) | ||
| 186 | do | ||
| 187 | t.identity = 'LOVE' | ||
| 188 | t.version = "11.5" | ||
| 189 | end | ||
| 190 | end | ||
| 167 | do | 191 | do |
| 168 | print(123, "hello") | 192 | print(123, "hello") |
| 169 | end | 193 | end |
