aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/docs/de/doc/advanced/macro.md142
-rw-r--r--doc/docs/doc/advanced/macro.md153
-rw-r--r--doc/docs/id-id/doc/advanced/macro.md142
-rw-r--r--doc/docs/pt-br/doc/advanced/macro.md142
-rw-r--r--doc/docs/zh/doc/advanced/macro.md142
-rw-r--r--doc/yue-de.md70
-rw-r--r--doc/yue-en.md81
-rw-r--r--doc/yue-id-id.md70
-rw-r--r--doc/yue-pt-br.md70
-rw-r--r--doc/yue-zh.md70
-rw-r--r--spec/outputs/codes_from_doc_de.lua110
-rw-r--r--spec/outputs/codes_from_doc_en.lua110
-rw-r--r--spec/outputs/codes_from_doc_id-id.lua110
-rw-r--r--spec/outputs/codes_from_doc_pt-br.lua110
-rw-r--r--spec/outputs/codes_from_doc_zh.lua110
15 files changed, 1630 insertions, 2 deletions
diff --git a/doc/docs/de/doc/advanced/macro.md b/doc/docs/de/doc/advanced/macro.md
index 8b78306..4287b2f 100644
--- a/doc/docs/de/doc/advanced/macro.md
+++ b/doc/docs/de/doc/advanced/macro.md
@@ -338,3 +338,145 @@ $printNumAndStr 123, "hallo"
338</YueDisplay> 338</YueDisplay>
339 339
340Weitere Details zu verfügbaren AST-Knoten findest du in den großgeschriebenen Definitionen in `yue_parser.cpp`. 340Weitere Details zu verfügbaren AST-Knoten findest du in den großgeschriebenen Definitionen in `yue_parser.cpp`.
341
342## Annotation-Anweisungen
343
344Annotation-Anweisungen wenden ein Makro auf die direkt folgende Anweisung an.
345
346Das entspricht einem Makroaufruf, bei dem der Quelltext der folgenden Anweisung als letztes Argument zusätzlich übergeben wird.
347
348```yuescript
349macro ShowName = (code) -> |
350 print "#{code\match '^[%w_]*'}"
351
352$[ShowName]
353myFunc = ->
354
355return
356```
357
358<YueDisplay>
359
360```yue
361macro ShowName = (code) -> |
362 print "#{code\match '^[%w_]*'}"
363
364$[ShowName]
365myFunc = ->
366
367return
368```
369
370</YueDisplay>
371
372Wenn das Annotationsmakro eine Konfigurationstabelle zurückgibt, steuert das optionale Feld `before`, ob das Ergebnis vor oder nach der annotierten Anweisung eingefügt wird.
373
374```yuescript
375macro Tag = (tag, code) ->
376 tableName = code\match "^[%w_]+"
377 return
378 type: "text"
379 before: tag == "before"
380 code: "-- #{tag}:#{tableName}"
381
382$[Tag before]
383tableA = {}
384
385$[Tag after]
386tableB = {}
387
388return
389```
390
391<YueDisplay>
392
393```yue
394macro Tag = (tag, code) ->
395 tableName = code\match "^[%w_]+"
396 return
397 type: "text"
398 before: tag == "before"
399 code: "-- #{tag}:#{tableName}"
400
401$[Tag before]
402tableA = {}
403
404$[Tag after]
405tableB = {}
406
407return
408```
409
410</YueDisplay>
411
412Da die folgende Anweisung als zusätzliches Makroargument übergeben wird, lassen sich mit Annotationen auch direkt Registrierungszeilen aus Klassendeklarationen erzeugen. Du kannst dabei dieselben AST-Argumentprüfungen wie bei normalen Makros verwenden.
413
414```yuescript
415macro Register = (registry, code`ClassDecl) ->
416 className = code\match "^class%s+(%w+)"
417 return |
418 #{registry}["#{className}"] = #{className}
419
420registry = {}
421
422$[Register(registry)]
423class Worker
424 run: => "ok"
425
426return
427```
428
429<YueDisplay>
430
431```yue
432macro Register = (registry, code`ClassDecl) ->
433 className = code\match "^class%s+(%w+)"
434 return |
435 #{registry}["#{className}"] = #{className}
436
437registry = {}
438
439$[Register(registry)]
440class Worker
441 run: => "ok"
442
443return
444```
445
446</YueDisplay>
447
448Annotationen können auch Wrapper-Code um Funktionen herum einfügen:
449
450```yuescript
451macro ValidateNumberArgs = (code) ->
452 funcName = code\match "^(%w+)%s*="
453 return |
454 local __orig_#{funcName} = #{funcName}
455 #{funcName} = (...) ->
456 for i = 1, select "#", ...
457 assert type(select i, ...) == "number", "expected number for arg \#{i}"
458 __orig_#{funcName} ...
459
460$[ValidateNumberArgs]
461add = (a, b) -> a + b
462```
463
464<YueDisplay>
465
466```yue
467macro ValidateNumberArgs = (code) ->
468 funcName = code\match "^(%w+)%s*="
469 return |
470 local __orig_#{funcName} = #{funcName}
471 #{funcName} = (...) ->
472 for i = 1, select "#", ...
473 assert type(select i, ...) == "number", "expected number for arg \#{i}"
474 __orig_#{funcName} ...
475
476$[ValidateNumberArgs]
477add = (a, b) -> a + b
478```
479
480</YueDisplay>
481
482Auf eine Annotation muss immer eine Anweisung folgen, und sie kann nicht auf eine `return`-Anweisung angewendet werden. Wenn die annotierte Anweisung am Ende eines Blocks steht und du die rohe AST-Form der Anweisung brauchst, füge ein explizites `return` danach ein, damit sie nicht in einen implizit zurückgegebenen Ausdruck eingebettet wird.
diff --git a/doc/docs/doc/advanced/macro.md b/doc/docs/doc/advanced/macro.md
index af7c773..bc7b56c 100644
--- a/doc/docs/doc/advanced/macro.md
+++ b/doc/docs/doc/advanced/macro.md
@@ -68,7 +68,7 @@ if $and f1!, f2!, f3!
68 68
69## Insert Raw Codes 69## Insert Raw Codes
70 70
71A macro function can either return a YueScript string or a config table containing Lua codes. 71A macro function can either return a YueScript string or a config table containing generated code.
72 72
73```yuescript 73```yuescript
74macro yueFunc = (var) -> "local #{var} = ->" 74macro yueFunc = (var) -> "local #{var} = ->"
@@ -126,6 +126,15 @@ end
126 126
127</YueDisplay> 127</YueDisplay>
128 128
129The returned table can be used to control how the generated code gets inserted.
130
131- `code` is the generated text.
132- `type` chooses how the text is handled. It can be `"yue"` (the default), `"lua"`, or `"text"`.
133- `locals` declares local names introduced by inserted text.
134- `before` puts the generated result before the annotated statement instead of after it.
135
136In most cases you only need to choose a `type`. Use `"yue"` for generated YueScript, `"lua"` for raw Lua, and `"text"` for text that should be copied straight into the final output.
137
129## Export Macro 138## Export Macro
130 139
131Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module. 140Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module.
@@ -338,3 +347,145 @@ $printNumAndStr 123, "hello"
338</YueDisplay> 347</YueDisplay>
339 348
340For more details about available AST nodes, please refer to the uppercased definitions in [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). 349For more details about available AST nodes, please refer to the uppercased definitions in [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp).
350
351## Annotation Statements
352
353Annotation statements apply a macro to the statement immediately following them.
354
355This is equivalent to calling the macro with the following statement's source text appended as the last argument.
356
357```yuescript
358macro ShowName = (code) -> |
359 print "#{code\match '^[%w_]*'}"
360
361$[ShowName]
362myFunc = ->
363
364return
365```
366
367<YueDisplay>
368
369```yue
370macro ShowName = (code) -> |
371 print "#{code\match '^[%w_]*'}"
372
373$[ShowName]
374myFunc = ->
375
376return
377```
378
379</YueDisplay>
380
381When the annotation macro returns a config table, the optional `before` field controls whether the generated result is emitted before or after the annotated statement.
382
383```yuescript
384macro Tag = (tag, code) ->
385 tableName = code\match "^[%w_]+"
386 return
387 type: "text"
388 before: tag == "before"
389 code: "-- #{tag}:#{tableName}"
390
391$[Tag before]
392tableA = {}
393
394$[Tag after]
395tableB = {}
396
397return
398```
399
400<YueDisplay>
401
402```yue
403macro Tag = (tag, code) ->
404 tableName = code\match "^[%w_]+"
405 return
406 type: "text"
407 before: tag == "before"
408 code: "-- #{tag}:#{tableName}"
409
410$[Tag before]
411tableA = {}
412
413$[Tag after]
414tableB = {}
415
416return
417```
418
419</YueDisplay>
420
421Because the followed statement is passed in as an extra macro argument, annotations can also be used to generate registration code from class declarations. Because the followed statement is passed in as an extra macro argument, you can use the same AST argument checks as normal macros:
422
423```yuescript
424macro Register = (registry, code`ClassDecl) ->
425 className = code\match "^class%s+(%w+)"
426 return |
427 #{registry}["#{className}"] = #{className}
428
429registry = {}
430
431$[Register(registry)]
432class Worker
433 run: => "ok"
434
435return
436```
437
438<YueDisplay>
439
440```yue
441macro Register = (registry, code`ClassDecl) ->
442 className = code\match "^class%s+(%w+)"
443 return |
444 #{registry}["#{className}"] = #{className}
445
446registry = {}
447
448$[Register(registry)]
449class Worker
450 run: => "ok"
451
452return
453```
454
455</YueDisplay>
456
457Annotations can also inject wrapper code around functions:
458
459```yuescript
460macro ValidateNumberArgs = (code) ->
461 funcName = code\match "^(%w+)%s*="
462 return |
463 local __orig_#{funcName} = #{funcName}
464 #{funcName} = (...) ->
465 for i = 1, select "#", ...
466 assert type(select i, ...) == "number", "expected number for arg \#{i}"
467 __orig_#{funcName} ...
468
469$[ValidateNumberArgs]
470add = (a, b) -> a + b
471```
472
473<YueDisplay>
474
475```yue
476macro ValidateNumberArgs = (code) ->
477 funcName = code\match "^(%w+)%s*="
478 return |
479 local __orig_#{funcName} = #{funcName}
480 #{funcName} = (...) ->
481 for i = 1, select "#", ...
482 assert type(select i, ...) == "number", "expected number for arg \#{i}"
483 __orig_#{funcName} ...
484
485$[ValidateNumberArgs]
486add = (a, b) -> a + b
487```
488
489</YueDisplay>
490
491An annotation must always be followed by a statement, and it can not be applied to a `return` statement. If the annotated statement appears at the end of a block, add an explicit trailing `return` when you need the raw statement AST shape instead of an implicitly returned expression.
diff --git a/doc/docs/id-id/doc/advanced/macro.md b/doc/docs/id-id/doc/advanced/macro.md
index 9a1494f..96e1785 100644
--- a/doc/docs/id-id/doc/advanced/macro.md
+++ b/doc/docs/id-id/doc/advanced/macro.md
@@ -338,3 +338,145 @@ $printNumAndStr 123, "hello"
338</YueDisplay> 338</YueDisplay>
339 339
340Untuk detail lebih lanjut tentang node AST yang tersedia, silakan lihat definisi huruf besar di [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). 340Untuk detail lebih lanjut tentang node AST yang tersedia, silakan lihat definisi huruf besar di [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp).
341
342## Pernyataan anotasi
343
344Pernyataan anotasi menerapkan sebuah macro ke pernyataan yang tepat mengikutinya.
345
346Ini setara dengan memanggil macro sambil menambahkan kode sumber dari pernyataan berikutnya sebagai argumen terakhir.
347
348```yuescript
349macro ShowName = (code) -> |
350 print "#{code\match '^[%w_]*'}"
351
352$[ShowName]
353myFunc = ->
354
355return
356```
357
358<YueDisplay>
359
360```yue
361macro ShowName = (code) -> |
362 print "#{code\match '^[%w_]*'}"
363
364$[ShowName]
365myFunc = ->
366
367return
368```
369
370</YueDisplay>
371
372Saat macro anotasi mengembalikan tabel konfigurasi, field opsional `before` mengatur apakah hasil yang dihasilkan akan diletakkan sebelum atau sesudah pernyataan yang dianotasi.
373
374```yuescript
375macro Tag = (tag, code) ->
376 tableName = code\match "^[%w_]+"
377 return
378 type: "text"
379 before: tag == "before"
380 code: "-- #{tag}:#{tableName}"
381
382$[Tag before]
383tableA = {}
384
385$[Tag after]
386tableB = {}
387
388return
389```
390
391<YueDisplay>
392
393```yue
394macro Tag = (tag, code) ->
395 tableName = code\match "^[%w_]+"
396 return
397 type: "text"
398 before: tag == "before"
399 code: "-- #{tag}:#{tableName}"
400
401$[Tag before]
402tableA = {}
403
404$[Tag after]
405tableB = {}
406
407return
408```
409
410</YueDisplay>
411
412Karena pernyataan berikutnya diteruskan sebagai argumen macro tambahan, anotasi juga bisa digunakan untuk menghasilkan kode registrasi langsung dari deklarasi class. Anda juga dapat menggunakan pemeriksaan argumen AST yang sama seperti pada macro biasa.
413
414```yuescript
415macro Register = (registry, code`ClassDecl) ->
416 className = code\match "^class%s+(%w+)"
417 return |
418 #{registry}["#{className}"] = #{className}
419
420registry = {}
421
422$[Register(registry)]
423class Worker
424 run: => "ok"
425
426return
427```
428
429<YueDisplay>
430
431```yue
432macro Register = (registry, code`ClassDecl) ->
433 className = code\match "^class%s+(%w+)"
434 return |
435 #{registry}["#{className}"] = #{className}
436
437registry = {}
438
439$[Register(registry)]
440class Worker
441 run: => "ok"
442
443return
444```
445
446</YueDisplay>
447
448Anotasi juga bisa menyisipkan kode pembungkus di sekitar fungsi:
449
450```yuescript
451macro ValidateNumberArgs = (code) ->
452 funcName = code\match "^(%w+)%s*="
453 return |
454 local __orig_#{funcName} = #{funcName}
455 #{funcName} = (...) ->
456 for i = 1, select "#", ...
457 assert type(select i, ...) == "number", "expected number for arg \#{i}"
458 __orig_#{funcName} ...
459
460$[ValidateNumberArgs]
461add = (a, b) -> a + b
462```
463
464<YueDisplay>
465
466```yue
467macro ValidateNumberArgs = (code) ->
468 funcName = code\match "^(%w+)%s*="
469 return |
470 local __orig_#{funcName} = #{funcName}
471 #{funcName} = (...) ->
472 for i = 1, select "#", ...
473 assert type(select i, ...) == "number", "expected number for arg \#{i}"
474 __orig_#{funcName} ...
475
476$[ValidateNumberArgs]
477add = (a, b) -> a + b
478```
479
480</YueDisplay>
481
482Sebuah anotasi harus selalu diikuti oleh sebuah pernyataan, dan tidak bisa diterapkan ke pernyataan `return`. Jika pernyataan yang dianotasi berada di akhir sebuah blok dan Anda membutuhkan bentuk AST mentah dari pernyataan itu, tambahkan `return` eksplisit setelahnya agar ia tidak dibungkus menjadi ekspresi yang dikembalikan secara implisit.
diff --git a/doc/docs/pt-br/doc/advanced/macro.md b/doc/docs/pt-br/doc/advanced/macro.md
index 248011e..6fa04be 100644
--- a/doc/docs/pt-br/doc/advanced/macro.md
+++ b/doc/docs/pt-br/doc/advanced/macro.md
@@ -337,3 +337,145 @@ $printNumAndStr 123, "hello"
337</YueDisplay> 337</YueDisplay>
338 338
339Para mais detalhes sobre os nós AST disponíveis, consulte as definições em maiúsculas em [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). 339Para mais detalhes sobre os nós AST disponíveis, consulte as definições em maiúsculas em [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp).
340
341## Instruções de anotação
342
343As instruções de anotação aplicam uma macro à instrução logo em seguida.
344
345Isso equivale a chamar a macro com o código-fonte da instrução seguinte anexado como último argumento.
346
347```yuescript
348macro ShowName = (code) -> |
349 print "#{code\match '^[%w_]*'}"
350
351$[ShowName]
352myFunc = ->
353
354return
355```
356
357<YueDisplay>
358
359```yue
360macro ShowName = (code) -> |
361 print "#{code\match '^[%w_]*'}"
362
363$[ShowName]
364myFunc = ->
365
366return
367```
368
369</YueDisplay>
370
371Quando a macro de anotação retorna uma tabela de configuração, o campo opcional `before` controla se o resultado gerado será emitido antes ou depois da instrução anotada.
372
373```yuescript
374macro Tag = (tag, code) ->
375 tableName = code\match "^[%w_]+"
376 return
377 type: "text"
378 before: tag == "before"
379 code: "-- #{tag}:#{tableName}"
380
381$[Tag before]
382tableA = {}
383
384$[Tag after]
385tableB = {}
386
387return
388```
389
390<YueDisplay>
391
392```yue
393macro Tag = (tag, code) ->
394 tableName = code\match "^[%w_]+"
395 return
396 type: "text"
397 before: tag == "before"
398 code: "-- #{tag}:#{tableName}"
399
400$[Tag before]
401tableA = {}
402
403$[Tag after]
404tableB = {}
405
406return
407```
408
409</YueDisplay>
410
411Como a instrução seguinte é passada como um argumento extra para a macro, anotações também podem ser usadas para gerar código de registro a partir de declarações de classe. Você também pode usar as mesmas checagens de AST nos argumentos que macros normais oferecem.
412
413```yuescript
414macro Register = (registry, code`ClassDecl) ->
415 className = code\match "^class%s+(%w+)"
416 return |
417 #{registry}["#{className}"] = #{className}
418
419registry = {}
420
421$[Register(registry)]
422class Worker
423 run: => "ok"
424
425return
426```
427
428<YueDisplay>
429
430```yue
431macro Register = (registry, code`ClassDecl) ->
432 className = code\match "^class%s+(%w+)"
433 return |
434 #{registry}["#{className}"] = #{className}
435
436registry = {}
437
438$[Register(registry)]
439class Worker
440 run: => "ok"
441
442return
443```
444
445</YueDisplay>
446
447Anotações também podem injetar código de empacotamento em volta de funções:
448
449```yuescript
450macro ValidateNumberArgs = (code) ->
451 funcName = code\match "^(%w+)%s*="
452 return |
453 local __orig_#{funcName} = #{funcName}
454 #{funcName} = (...) ->
455 for i = 1, select "#", ...
456 assert type(select i, ...) == "number", "expected number for arg \#{i}"
457 __orig_#{funcName} ...
458
459$[ValidateNumberArgs]
460add = (a, b) -> a + b
461```
462
463<YueDisplay>
464
465```yue
466macro ValidateNumberArgs = (code) ->
467 funcName = code\match "^(%w+)%s*="
468 return |
469 local __orig_#{funcName} = #{funcName}
470 #{funcName} = (...) ->
471 for i = 1, select "#", ...
472 assert type(select i, ...) == "number", "expected number for arg \#{i}"
473 __orig_#{funcName} ...
474
475$[ValidateNumberArgs]
476add = (a, b) -> a + b
477```
478
479</YueDisplay>
480
481Uma anotação sempre precisa ser seguida por uma instrução, e ela não pode ser aplicada a uma instrução `return`. Se a instrução anotada aparecer no fim de um bloco e você precisar da forma AST bruta dessa instrução, adicione um `return` explícito em seguida para evitar que ela seja envolvida por uma expressão com retorno implícito.
diff --git a/doc/docs/zh/doc/advanced/macro.md b/doc/docs/zh/doc/advanced/macro.md
index 5110571..0d7ee6d 100644
--- a/doc/docs/zh/doc/advanced/macro.md
+++ b/doc/docs/zh/doc/advanced/macro.md
@@ -338,3 +338,145 @@ $printNumAndStr 123, "hello"
338</YueDisplay> 338</YueDisplay>
339 339
340&emsp;&emsp;更多关于可用 AST 节点的详细信息,请参考 [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp) 中大写的规则定义。 340&emsp;&emsp;更多关于可用 AST 节点的详细信息,请参考 [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp) 中大写的规则定义。
341
342## 注解语句
343
344&emsp;&emsp;注解语句会把一个宏应用到它后面的那条语句上。
345
346&emsp;&emsp;这等价于调用该宏,并把后面那条语句的源码作为最后一个参数附加进去。
347
348```yuescript
349macro ShowName = (code) -> |
350 print "#{code\match '^[%w_]*'}"
351
352$[ShowName]
353myFunc = ->
354
355return
356```
357
358<YueDisplay>
359
360```yue
361macro ShowName = (code) -> |
362 print "#{code\match '^[%w_]*'}"
363
364$[ShowName]
365myFunc = ->
366
367return
368```
369
370</YueDisplay>
371
372&emsp;&emsp;如果注解宏返回的是配置表,可选字段 `before` 可以控制生成结果插入到被注解语句之前还是之后。
373
374```yuescript
375macro Tag = (tag, code) ->
376 tableName = code\match "^[%w_]+"
377 return
378 type: "text"
379 before: tag == "before"
380 code: "-- #{tag}:#{tableName}"
381
382$[Tag before]
383tableA = {}
384
385$[Tag after]
386tableB = {}
387
388return
389```
390
391<YueDisplay>
392
393```yue
394macro Tag = (tag, code) ->
395 tableName = code\match "^[%w_]+"
396 return
397 type: "text"
398 before: tag == "before"
399 code: "-- #{tag}:#{tableName}"
400
401$[Tag before]
402tableA = {}
403
404$[Tag after]
405tableB = {}
406
407return
408```
409
410</YueDisplay>
411
412&emsp;&emsp;由于后面的语句会作为额外的宏参数传入,注解也可以从类声明生成注册代码。它同样可以使用普通宏支持的 AST 参数检查。
413
414```yuescript
415macro Register = (registry, code`ClassDecl) ->
416 className = code\match "^class%s+(%w+)"
417 return |
418 #{registry}["#{className}"] = #{className}
419
420registry = {}
421
422$[Register(registry)]
423class Worker
424 run: => "ok"
425
426return
427```
428
429<YueDisplay>
430
431```yue
432macro Register = (registry, code`ClassDecl) ->
433 className = code\match "^class%s+(%w+)"
434 return |
435 #{registry}["#{className}"] = #{className}
436
437registry = {}
438
439$[Register(registry)]
440class Worker
441 run: => "ok"
442
443return
444```
445
446</YueDisplay>
447
448&emsp;&emsp;注解也可以用来给函数注入包装代码。
449
450```yuescript
451macro ValidateNumberArgs = (code) ->
452 funcName = code\match "^(%w+)%s*="
453 return |
454 local __orig_#{funcName} = #{funcName}
455 #{funcName} = (...) ->
456 for i = 1, select "#", ...
457 assert type(select i, ...) == "number", "expected number for arg \#{i}"
458 __orig_#{funcName} ...
459
460$[ValidateNumberArgs]
461add = (a, b) -> a + b
462```
463
464<YueDisplay>
465
466```yue
467macro ValidateNumberArgs = (code) ->
468 funcName = code\match "^(%w+)%s*="
469 return |
470 local __orig_#{funcName} = #{funcName}
471 #{funcName} = (...) ->
472 for i = 1, select "#", ...
473 assert type(select i, ...) == "number", "expected number for arg \#{i}"
474 __orig_#{funcName} ...
475
476$[ValidateNumberArgs]
477add = (a, b) -> a + b
478```
479
480</YueDisplay>
481
482&emsp;&emsp;注解后面必须紧跟一条语句,而且不能作用在 `return` 语句上。如果被注解的语句正好位于代码块末尾,而你又需要拿到原始的语句 AST 形态,就需要额外补一个显式的 `return`,避免它被隐式返回表达式包起来。
diff --git a/doc/yue-de.md b/doc/yue-de.md
index 4c7ede9..8ad750d 100644
--- a/doc/yue-de.md
+++ b/doc/yue-de.md
@@ -237,6 +237,76 @@ $printNumAndStr 123, "hallo"
237 237
238Weitere Details zu verfügbaren AST-Knoten findest du in den großgeschriebenen Definitionen in `yue_parser.cpp`. 238Weitere Details zu verfügbaren AST-Knoten findest du in den großgeschriebenen Definitionen in `yue_parser.cpp`.
239 239
240## Annotation-Anweisungen
241
242Annotation-Anweisungen wenden ein Makro auf die direkt folgende Anweisung an.
243
244Das entspricht einem Makroaufruf, bei dem der Quelltext der folgenden Anweisung als letztes Argument zusätzlich übergeben wird.
245
246```yuescript
247macro ShowName = (code) -> |
248 print "#{code\match '^[%w_]*'}"
249
250$[ShowName]
251myFunc = ->
252
253return
254```
255
256Wenn das Annotationsmakro eine Konfigurationstabelle zurückgibt, steuert das optionale Feld `before`, ob das Ergebnis vor oder nach der annotierten Anweisung eingefügt wird.
257
258```yuescript
259macro Tag = (tag, code) ->
260 tableName = code\match "^[%w_]+"
261 return
262 type: "text"
263 before: tag == "before"
264 code: "-- #{tag}:#{tableName}"
265
266$[Tag before]
267tableA = {}
268
269$[Tag after]
270tableB = {}
271
272return
273```
274
275Da die folgende Anweisung als zusätzliches Makroargument übergeben wird, lassen sich mit Annotationen auch direkt Registrierungszeilen aus Klassendeklarationen erzeugen. Du kannst dabei dieselben AST-Argumentprüfungen wie bei normalen Makros verwenden.
276
277```yuescript
278macro Register = (registry, code`ClassDecl) ->
279 className = code\match "^class%s+(%w+)"
280 return |
281 #{registry}["#{className}"] = #{className}
282
283registry = {}
284
285$[Register(registry)]
286class Worker
287 run: => "ok"
288
289return
290```
291
292Annotationen können auch Wrapper-Code um Funktionen herum einfügen:
293
294```yuescript
295macro ValidateNumberArgs = (code) ->
296 funcName = code\match "^(%w+)%s*="
297 return |
298 local __orig_#{funcName} = #{funcName}
299 #{funcName} = (...) ->
300 for i = 1, select "#", ...
301 assert type(select i, ...) == "number", "expected number for arg \#{i}"
302 __orig_#{funcName} ...
303
304$[ValidateNumberArgs]
305add = (a, b) -> a + b
306```
307
308Auf eine Annotation muss immer eine Anweisung folgen, und sie kann nicht auf eine `return`-Anweisung angewendet werden. Wenn die annotierte Anweisung am Ende eines Blocks steht und du die rohe AST-Form der Anweisung brauchst, füge ein explizites `return` danach ein, damit sie nicht in einen implizit zurückgegebenen Ausdruck eingebettet wird.
309
240# Try 310# Try
241 311
242Die Syntax für Fehlerbehandlung in Lua in einer gängigen Form. 312Die Syntax für Fehlerbehandlung in Lua in einer gängigen Form.
diff --git a/doc/yue-en.md b/doc/yue-en.md
index dc61570..ab43a7c 100644
--- a/doc/yue-en.md
+++ b/doc/yue-en.md
@@ -105,7 +105,7 @@ if $and f1!, f2!, f3!
105 105
106## Insert Raw Codes 106## Insert Raw Codes
107 107
108A macro function can either return a YueScript string or a config table containing Lua codes. 108A macro function can either return a YueScript string or a config table containing generated code.
109 109
110```yuescript 110```yuescript
111macro yueFunc = (var) -> "local #{var} = ->" 111macro yueFunc = (var) -> "local #{var} = ->"
@@ -133,6 +133,15 @@ end
133]==] 133]==]
134``` 134```
135 135
136The returned table can be used to control how the generated code gets inserted.
137
138- `code` is the generated text.
139- `type` chooses how the text is handled. It can be `"yue"` (the default), `"lua"`, or `"text"`.
140- `locals` declares local names introduced by inserted text.
141- `before` puts the generated result before the annotated statement instead of after it.
142
143In most cases you only need to choose a `type`. Use `"yue"` for generated YueScript, `"lua"` for raw Lua, and `"text"` for text that should be copied straight into the final output.
144
136## Export Macro 145## Export Macro
137 146
138Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module. 147Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module.
@@ -237,6 +246,76 @@ $printNumAndStr 123, "hello"
237 246
238For more details about available AST nodes, please refer to the uppercased definitions in [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). 247For more details about available AST nodes, please refer to the uppercased definitions in [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp).
239 248
249## Annotation Statements
250
251Annotation statements apply a macro to the statement immediately following them.
252
253This is equivalent to calling the macro with the following statement's source text appended as the last argument.
254
255```yuescript
256macro ShowName = (code) -> |
257 print "#{code\match '^[%w_]*'}"
258
259$[ShowName]
260myFunc = ->
261
262return
263```
264
265When the annotation macro returns a config table, the optional `before` field controls whether the generated result is emitted before or after the annotated statement.
266
267```yuescript
268macro Tag = (tag, code) ->
269 tableName = code\match "^[%w_]+"
270 return
271 type: "text"
272 before: tag == "before"
273 code: "-- #{tag}:#{tableName}"
274
275$[Tag before]
276tableA = {}
277
278$[Tag after]
279tableB = {}
280
281return
282```
283
284Because the followed statement is passed in as an extra macro argument, annotations can also be used to generate registration code from class declarations. Because the followed statement is passed in as an extra macro argument, you can use the same AST argument checks as normal macros:
285
286```yuescript
287macro Register = (registry, code`ClassDecl) ->
288 className = code\match "^class%s+(%w+)"
289 return |
290 #{registry}["#{className}"] = #{className}
291
292registry = {}
293
294$[Register(registry)]
295class Worker
296 run: => "ok"
297
298return
299```
300
301Annotations can also inject wrapper code around functions:
302
303```yuescript
304macro ValidateNumberArgs = (code) ->
305 funcName = code\match "^(%w+)%s*="
306 return |
307 local __orig_#{funcName} = #{funcName}
308 #{funcName} = (...) ->
309 for i = 1, select "#", ...
310 assert type(select i, ...) == "number", "expected number for arg \#{i}"
311 __orig_#{funcName} ...
312
313$[ValidateNumberArgs]
314add = (a, b) -> a + b
315```
316
317An annotation must always be followed by a statement, and it can not be applied to a `return` statement. If the annotated statement appears at the end of a block, add an explicit trailing `return` when you need the raw statement AST shape instead of an implicitly returned expression.
318
240# Try 319# Try
241 320
242The syntax for Lua error handling in a common form. 321The syntax for Lua error handling in a common form.
diff --git a/doc/yue-id-id.md b/doc/yue-id-id.md
index a2a70d4..d891c57 100644
--- a/doc/yue-id-id.md
+++ b/doc/yue-id-id.md
@@ -237,6 +237,76 @@ $printNumAndStr 123, "hello"
237 237
238Untuk detail lebih lanjut tentang node AST yang tersedia, silakan lihat definisi huruf besar di [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). 238Untuk detail lebih lanjut tentang node AST yang tersedia, silakan lihat definisi huruf besar di [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp).
239 239
240## Pernyataan anotasi
241
242Pernyataan anotasi menerapkan sebuah macro ke pernyataan yang tepat mengikutinya.
243
244Ini setara dengan memanggil macro sambil menambahkan kode sumber dari pernyataan berikutnya sebagai argumen terakhir.
245
246```yuescript
247macro ShowName = (code) -> |
248 print "#{code\match '^[%w_]*'}"
249
250$[ShowName]
251myFunc = ->
252
253return
254```
255
256Saat macro anotasi mengembalikan tabel konfigurasi, field opsional `before` mengatur apakah hasil yang dihasilkan akan diletakkan sebelum atau sesudah pernyataan yang dianotasi.
257
258```yuescript
259macro Tag = (tag, code) ->
260 tableName = code\match "^[%w_]+"
261 return
262 type: "text"
263 before: tag == "before"
264 code: "-- #{tag}:#{tableName}"
265
266$[Tag before]
267tableA = {}
268
269$[Tag after]
270tableB = {}
271
272return
273```
274
275Karena pernyataan berikutnya diteruskan sebagai argumen macro tambahan, anotasi juga bisa digunakan untuk menghasilkan kode registrasi langsung dari deklarasi class. Anda juga dapat menggunakan pemeriksaan argumen AST yang sama seperti pada macro biasa.
276
277```yuescript
278macro Register = (registry, code`ClassDecl) ->
279 className = code\match "^class%s+(%w+)"
280 return |
281 #{registry}["#{className}"] = #{className}
282
283registry = {}
284
285$[Register(registry)]
286class Worker
287 run: => "ok"
288
289return
290```
291
292Anotasi juga bisa menyisipkan kode pembungkus di sekitar fungsi:
293
294```yuescript
295macro ValidateNumberArgs = (code) ->
296 funcName = code\match "^(%w+)%s*="
297 return |
298 local __orig_#{funcName} = #{funcName}
299 #{funcName} = (...) ->
300 for i = 1, select "#", ...
301 assert type(select i, ...) == "number", "expected number for arg \#{i}"
302 __orig_#{funcName} ...
303
304$[ValidateNumberArgs]
305add = (a, b) -> a + b
306```
307
308Sebuah anotasi harus selalu diikuti oleh sebuah pernyataan, dan tidak bisa diterapkan ke pernyataan `return`. Jika pernyataan yang dianotasi berada di akhir sebuah blok dan Anda membutuhkan bentuk AST mentah dari pernyataan itu, tambahkan `return` eksplisit setelahnya agar ia tidak dibungkus menjadi ekspresi yang dikembalikan secara implisit.
309
240# Try 310# Try
241 311
242Sintaks untuk penanganan error Lua dalam bentuk umum. 312Sintaks untuk penanganan error Lua dalam bentuk umum.
diff --git a/doc/yue-pt-br.md b/doc/yue-pt-br.md
index 2e9ab40..a858c50 100644
--- a/doc/yue-pt-br.md
+++ b/doc/yue-pt-br.md
@@ -237,6 +237,76 @@ $printNumAndStr 123, "hello"
237 237
238Para mais detalhes sobre os nós AST disponíveis, consulte as definições em maiúsculas em [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp). 238Para mais detalhes sobre os nós AST disponíveis, consulte as definições em maiúsculas em [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp).
239 239
240## Instruções de anotação
241
242As instruções de anotação aplicam uma macro à instrução logo em seguida.
243
244Isso equivale a chamar a macro com o código-fonte da instrução seguinte anexado como último argumento.
245
246```yuescript
247macro ShowName = (code) -> |
248 print "#{code\match '^[%w_]*'}"
249
250$[ShowName]
251myFunc = ->
252
253return
254```
255
256Quando a macro de anotação retorna uma tabela de configuração, o campo opcional `before` controla se o resultado gerado será emitido antes ou depois da instrução anotada.
257
258```yuescript
259macro Tag = (tag, code) ->
260 tableName = code\match "^[%w_]+"
261 return
262 type: "text"
263 before: tag == "before"
264 code: "-- #{tag}:#{tableName}"
265
266$[Tag before]
267tableA = {}
268
269$[Tag after]
270tableB = {}
271
272return
273```
274
275Como a instrução seguinte é passada como um argumento extra para a macro, anotações também podem ser usadas para gerar código de registro a partir de declarações de classe. Você também pode usar as mesmas checagens de AST nos argumentos que macros normais oferecem.
276
277```yuescript
278macro Register = (registry, code`ClassDecl) ->
279 className = code\match "^class%s+(%w+)"
280 return |
281 #{registry}["#{className}"] = #{className}
282
283registry = {}
284
285$[Register(registry)]
286class Worker
287 run: => "ok"
288
289return
290```
291
292Anotações também podem injetar código de empacotamento em volta de funções:
293
294```yuescript
295macro ValidateNumberArgs = (code) ->
296 funcName = code\match "^(%w+)%s*="
297 return |
298 local __orig_#{funcName} = #{funcName}
299 #{funcName} = (...) ->
300 for i = 1, select "#", ...
301 assert type(select i, ...) == "number", "expected number for arg \#{i}"
302 __orig_#{funcName} ...
303
304$[ValidateNumberArgs]
305add = (a, b) -> a + b
306```
307
308Uma anotação sempre precisa ser seguida por uma instrução, e ela não pode ser aplicada a uma instrução `return`. Se a instrução anotada aparecer no fim de um bloco e você precisar da forma AST bruta dessa instrução, adicione um `return` explícito em seguida para evitar que ela seja envolvida por uma expressão com retorno implícito.
309
240# Try 310# Try
241 311
242A sintaxe para tratamento de erros do Lua em uma forma comum. 312A sintaxe para tratamento de erros do Lua em uma forma comum.
diff --git a/doc/yue-zh.md b/doc/yue-zh.md
index e0f8b36..6494bf8 100644
--- a/doc/yue-zh.md
+++ b/doc/yue-zh.md
@@ -237,6 +237,76 @@ $printNumAndStr 123, "hello"
237 237
238&emsp;&emsp;更多关于可用 AST 节点的详细信息,请参考 [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp) 中大写的规则定义。 238&emsp;&emsp;更多关于可用 AST 节点的详细信息,请参考 [yue_parser.cpp](https://github.com/IppClub/YueScript/blob/main/src/yuescript/yue_parser.cpp) 中大写的规则定义。
239 239
240## 注解语句
241
242&emsp;&emsp;注解语句会把一个宏应用到它后面的那条语句上。
243
244&emsp;&emsp;这等价于调用该宏,并把后面那条语句的源码作为最后一个参数附加进去。
245
246```yuescript
247macro ShowName = (code) -> |
248 print "#{code\match '^[%w_]*'}"
249
250$[ShowName]
251myFunc = ->
252
253return
254```
255
256&emsp;&emsp;如果注解宏返回的是配置表,可选字段 `before` 可以控制生成结果插入到被注解语句之前还是之后。
257
258```yuescript
259macro Tag = (tag, code) ->
260 tableName = code\match "^[%w_]+"
261 return
262 type: "text"
263 before: tag == "before"
264 code: "-- #{tag}:#{tableName}"
265
266$[Tag before]
267tableA = {}
268
269$[Tag after]
270tableB = {}
271
272return
273```
274
275&emsp;&emsp;由于后面的语句会作为额外的宏参数传入,注解也可以从类声明生成注册代码。它同样可以使用普通宏支持的 AST 参数检查。
276
277```yuescript
278macro Register = (registry, code`ClassDecl) ->
279 className = code\match "^class%s+(%w+)"
280 return |
281 #{registry}["#{className}"] = #{className}
282
283registry = {}
284
285$[Register(registry)]
286class Worker
287 run: => "ok"
288
289return
290```
291
292&emsp;&emsp;注解也可以用来给函数注入包装代码。
293
294```yuescript
295macro ValidateNumberArgs = (code) ->
296 funcName = code\match "^(%w+)%s*="
297 return |
298 local __orig_#{funcName} = #{funcName}
299 #{funcName} = (...) ->
300 for i = 1, select "#", ...
301 assert type(select i, ...) == "number", "expected number for arg \#{i}"
302 __orig_#{funcName} ...
303
304$[ValidateNumberArgs]
305add = (a, b) -> a + b
306```
307
308&emsp;&emsp;注解后面必须紧跟一条语句,而且不能作用在 `return` 语句上。如果被注解的语句正好位于代码块末尾,而你又需要拿到原始的语句 AST 形态,就需要额外补一个显式的 `return`,避免它被隐式返回表达式包起来。
309
240# 错误处理 310# 错误处理
241 311
242&emsp;&emsp;用于统一进行 Lua 错误处理的便捷语法。 312&emsp;&emsp;用于统一进行 Lua 错误处理的便捷语法。
diff --git a/spec/outputs/codes_from_doc_de.lua b/spec/outputs/codes_from_doc_de.lua
index 2530977..e1346db 100644
--- a/spec/outputs/codes_from_doc_de.lua
+++ b/spec/outputs/codes_from_doc_de.lua
@@ -143,6 +143,61 @@ end
143do 143do
144 print(123, "hallo") 144 print(123, "hallo")
145end 145end
146local myFunc
147myFunc = function() end
148do
149 print("myFunc")
150end
151return
152-- before:tableA
153local tableA = { }
154local tableB = { }
155-- after:tableB
156return
157local registry = { }
158local Worker
159do
160 local _class_0
161 local _base_0 = {
162 run = function(self)
163 return "ok"
164 end
165 }
166 if _base_0.__index == nil then
167 _base_0.__index = _base_0
168 end
169 _class_0 = setmetatable({
170 __init = function() end,
171 __base = _base_0,
172 __name = "Worker"
173 }, {
174 __index = _base_0,
175 __call = function(cls, ...)
176 local _self_0 = setmetatable({ }, _base_0)
177 cls.__init(_self_0, ...)
178 return _self_0
179 end
180 })
181 _base_0.__class = _class_0
182 Worker = _class_0
183end
184do
185 registry["Worker"] = Worker
186end
187return
188local add
189add = function(a, b)
190 return a + b
191end
192do
193 local __orig_add = add
194 add = function(...)
195 for i = 1, select("#", ...) do
196 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
197 end
198 return __orig_add(...)
199 end
200end
146local area = 6.2831853071796 * 5 201local area = 6.2831853071796 * 5
147print('Hallo Welt') 202print('Hallo Welt')
148do 203do
@@ -194,6 +249,61 @@ end
194do 249do
195 print(123, "hallo") 250 print(123, "hallo")
196end 251end
252local myFunc
253myFunc = function() end
254do
255 print("myFunc")
256end
257return
258-- before:tableA
259local tableA = { }
260local tableB = { }
261-- after:tableB
262return
263local registry = { }
264local Worker
265do
266 local _class_0
267 local _base_0 = {
268 run = function(self)
269 return "ok"
270 end
271 }
272 if _base_0.__index == nil then
273 _base_0.__index = _base_0
274 end
275 _class_0 = setmetatable({
276 __init = function() end,
277 __base = _base_0,
278 __name = "Worker"
279 }, {
280 __index = _base_0,
281 __call = function(cls, ...)
282 local _self_0 = setmetatable({ }, _base_0)
283 cls.__init(_self_0, ...)
284 return _self_0
285 end
286 })
287 _base_0.__class = _class_0
288 Worker = _class_0
289end
290do
291 registry["Worker"] = Worker
292end
293return
294local add
295add = function(a, b)
296 return a + b
297end
298do
299 local __orig_add = add
300 add = function(...)
301 for i = 1, select("#", ...) do
302 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
303 end
304 return __orig_add(...)
305 end
306end
197xpcall(function() 307xpcall(function()
198 return func(1, 2, 3) 308 return func(1, 2, 3)
199end, function(err) 309end, function(err)
diff --git a/spec/outputs/codes_from_doc_en.lua b/spec/outputs/codes_from_doc_en.lua
index 18f0227..1a6469d 100644
--- a/spec/outputs/codes_from_doc_en.lua
+++ b/spec/outputs/codes_from_doc_en.lua
@@ -143,6 +143,61 @@ end
143do 143do
144 print(123, "hello") 144 print(123, "hello")
145end 145end
146local myFunc
147myFunc = function() end
148do
149 print("myFunc")
150end
151return
152-- before:tableA
153local tableA = { }
154local tableB = { }
155-- after:tableB
156return
157local registry = { }
158local Worker
159do
160 local _class_0
161 local _base_0 = {
162 run = function(self)
163 return "ok"
164 end
165 }
166 if _base_0.__index == nil then
167 _base_0.__index = _base_0
168 end
169 _class_0 = setmetatable({
170 __init = function() end,
171 __base = _base_0,
172 __name = "Worker"
173 }, {
174 __index = _base_0,
175 __call = function(cls, ...)
176 local _self_0 = setmetatable({ }, _base_0)
177 cls.__init(_self_0, ...)
178 return _self_0
179 end
180 })
181 _base_0.__class = _class_0
182 Worker = _class_0
183end
184do
185 registry["Worker"] = Worker
186end
187return
188local add
189add = function(a, b)
190 return a + b
191end
192do
193 local __orig_add = add
194 add = function(...)
195 for i = 1, select("#", ...) do
196 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
197 end
198 return __orig_add(...)
199 end
200end
146local area = 6.2831853071796 * 5 201local area = 6.2831853071796 * 5
147print('hello world') 202print('hello world')
148do 203do
@@ -194,6 +249,61 @@ end
194do 249do
195 print(123, "hello") 250 print(123, "hello")
196end 251end
252local myFunc
253myFunc = function() end
254do
255 print("myFunc")
256end
257return
258-- before:tableA
259local tableA = { }
260local tableB = { }
261-- after:tableB
262return
263local registry = { }
264local Worker
265do
266 local _class_0
267 local _base_0 = {
268 run = function(self)
269 return "ok"
270 end
271 }
272 if _base_0.__index == nil then
273 _base_0.__index = _base_0
274 end
275 _class_0 = setmetatable({
276 __init = function() end,
277 __base = _base_0,
278 __name = "Worker"
279 }, {
280 __index = _base_0,
281 __call = function(cls, ...)
282 local _self_0 = setmetatable({ }, _base_0)
283 cls.__init(_self_0, ...)
284 return _self_0
285 end
286 })
287 _base_0.__class = _class_0
288 Worker = _class_0
289end
290do
291 registry["Worker"] = Worker
292end
293return
294local add
295add = function(a, b)
296 return a + b
297end
298do
299 local __orig_add = add
300 add = function(...)
301 for i = 1, select("#", ...) do
302 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
303 end
304 return __orig_add(...)
305 end
306end
197xpcall(function() 307xpcall(function()
198 return func(1, 2, 3) 308 return func(1, 2, 3)
199end, function(err) 309end, function(err)
diff --git a/spec/outputs/codes_from_doc_id-id.lua b/spec/outputs/codes_from_doc_id-id.lua
index 452d88d..868c6ec 100644
--- a/spec/outputs/codes_from_doc_id-id.lua
+++ b/spec/outputs/codes_from_doc_id-id.lua
@@ -143,6 +143,61 @@ end
143do 143do
144 print(123, "hello") 144 print(123, "hello")
145end 145end
146local myFunc
147myFunc = function() end
148do
149 print("myFunc")
150end
151return
152-- before:tableA
153local tableA = { }
154local tableB = { }
155-- after:tableB
156return
157local registry = { }
158local Worker
159do
160 local _class_0
161 local _base_0 = {
162 run = function(self)
163 return "ok"
164 end
165 }
166 if _base_0.__index == nil then
167 _base_0.__index = _base_0
168 end
169 _class_0 = setmetatable({
170 __init = function() end,
171 __base = _base_0,
172 __name = "Worker"
173 }, {
174 __index = _base_0,
175 __call = function(cls, ...)
176 local _self_0 = setmetatable({ }, _base_0)
177 cls.__init(_self_0, ...)
178 return _self_0
179 end
180 })
181 _base_0.__class = _class_0
182 Worker = _class_0
183end
184do
185 registry["Worker"] = Worker
186end
187return
188local add
189add = function(a, b)
190 return a + b
191end
192do
193 local __orig_add = add
194 add = function(...)
195 for i = 1, select("#", ...) do
196 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
197 end
198 return __orig_add(...)
199 end
200end
146local area = 6.2831853071796 * 5 201local area = 6.2831853071796 * 5
147print('hello world') 202print('hello world')
148do 203do
@@ -194,6 +249,61 @@ end
194do 249do
195 print(123, "hello") 250 print(123, "hello")
196end 251end
252local myFunc
253myFunc = function() end
254do
255 print("myFunc")
256end
257return
258-- before:tableA
259local tableA = { }
260local tableB = { }
261-- after:tableB
262return
263local registry = { }
264local Worker
265do
266 local _class_0
267 local _base_0 = {
268 run = function(self)
269 return "ok"
270 end
271 }
272 if _base_0.__index == nil then
273 _base_0.__index = _base_0
274 end
275 _class_0 = setmetatable({
276 __init = function() end,
277 __base = _base_0,
278 __name = "Worker"
279 }, {
280 __index = _base_0,
281 __call = function(cls, ...)
282 local _self_0 = setmetatable({ }, _base_0)
283 cls.__init(_self_0, ...)
284 return _self_0
285 end
286 })
287 _base_0.__class = _class_0
288 Worker = _class_0
289end
290do
291 registry["Worker"] = Worker
292end
293return
294local add
295add = function(a, b)
296 return a + b
297end
298do
299 local __orig_add = add
300 add = function(...)
301 for i = 1, select("#", ...) do
302 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
303 end
304 return __orig_add(...)
305 end
306end
197xpcall(function() 307xpcall(function()
198 return func(1, 2, 3) 308 return func(1, 2, 3)
199end, function(err) 309end, function(err)
diff --git a/spec/outputs/codes_from_doc_pt-br.lua b/spec/outputs/codes_from_doc_pt-br.lua
index f9784d7..ce8c016 100644
--- a/spec/outputs/codes_from_doc_pt-br.lua
+++ b/spec/outputs/codes_from_doc_pt-br.lua
@@ -143,6 +143,61 @@ end
143do 143do
144 print(123, "hello") 144 print(123, "hello")
145end 145end
146local myFunc
147myFunc = function() end
148do
149 print("myFunc")
150end
151return
152-- before:tableA
153local tableA = { }
154local tableB = { }
155-- after:tableB
156return
157local registry = { }
158local Worker
159do
160 local _class_0
161 local _base_0 = {
162 run = function(self)
163 return "ok"
164 end
165 }
166 if _base_0.__index == nil then
167 _base_0.__index = _base_0
168 end
169 _class_0 = setmetatable({
170 __init = function() end,
171 __base = _base_0,
172 __name = "Worker"
173 }, {
174 __index = _base_0,
175 __call = function(cls, ...)
176 local _self_0 = setmetatable({ }, _base_0)
177 cls.__init(_self_0, ...)
178 return _self_0
179 end
180 })
181 _base_0.__class = _class_0
182 Worker = _class_0
183end
184do
185 registry["Worker"] = Worker
186end
187return
188local add
189add = function(a, b)
190 return a + b
191end
192do
193 local __orig_add = add
194 add = function(...)
195 for i = 1, select("#", ...) do
196 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
197 end
198 return __orig_add(...)
199 end
200end
146local area = 6.2831853071796 * 5 201local area = 6.2831853071796 * 5
147print('hello world') 202print('hello world')
148do 203do
@@ -194,6 +249,61 @@ end
194do 249do
195 print(123, "hello") 250 print(123, "hello")
196end 251end
252local myFunc
253myFunc = function() end
254do
255 print("myFunc")
256end
257return
258-- before:tableA
259local tableA = { }
260local tableB = { }
261-- after:tableB
262return
263local registry = { }
264local Worker
265do
266 local _class_0
267 local _base_0 = {
268 run = function(self)
269 return "ok"
270 end
271 }
272 if _base_0.__index == nil then
273 _base_0.__index = _base_0
274 end
275 _class_0 = setmetatable({
276 __init = function() end,
277 __base = _base_0,
278 __name = "Worker"
279 }, {
280 __index = _base_0,
281 __call = function(cls, ...)
282 local _self_0 = setmetatable({ }, _base_0)
283 cls.__init(_self_0, ...)
284 return _self_0
285 end
286 })
287 _base_0.__class = _class_0
288 Worker = _class_0
289end
290do
291 registry["Worker"] = Worker
292end
293return
294local add
295add = function(a, b)
296 return a + b
297end
298do
299 local __orig_add = add
300 add = function(...)
301 for i = 1, select("#", ...) do
302 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
303 end
304 return __orig_add(...)
305 end
306end
197xpcall(function() 307xpcall(function()
198 return func(1, 2, 3) 308 return func(1, 2, 3)
199end, function(err) 309end, function(err)
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index 4c254a2..2f849b8 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -143,6 +143,61 @@ end
143do 143do
144 print(123, "hello") 144 print(123, "hello")
145end 145end
146local myFunc
147myFunc = function() end
148do
149 print("myFunc")
150end
151return
152-- before:tableA
153local tableA = { }
154local tableB = { }
155-- after:tableB
156return
157local registry = { }
158local Worker
159do
160 local _class_0
161 local _base_0 = {
162 run = function(self)
163 return "ok"
164 end
165 }
166 if _base_0.__index == nil then
167 _base_0.__index = _base_0
168 end
169 _class_0 = setmetatable({
170 __init = function() end,
171 __base = _base_0,
172 __name = "Worker"
173 }, {
174 __index = _base_0,
175 __call = function(cls, ...)
176 local _self_0 = setmetatable({ }, _base_0)
177 cls.__init(_self_0, ...)
178 return _self_0
179 end
180 })
181 _base_0.__class = _class_0
182 Worker = _class_0
183end
184do
185 registry["Worker"] = Worker
186end
187return
188local add
189add = function(a, b)
190 return a + b
191end
192do
193 local __orig_add = add
194 add = function(...)
195 for i = 1, select("#", ...) do
196 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
197 end
198 return __orig_add(...)
199 end
200end
146local area = 6.2831853071796 * 5 201local area = 6.2831853071796 * 5
147print('你好 世界') 202print('你好 世界')
148do 203do
@@ -194,6 +249,61 @@ end
194do 249do
195 print(123, "hello") 250 print(123, "hello")
196end 251end
252local myFunc
253myFunc = function() end
254do
255 print("myFunc")
256end
257return
258-- before:tableA
259local tableA = { }
260local tableB = { }
261-- after:tableB
262return
263local registry = { }
264local Worker
265do
266 local _class_0
267 local _base_0 = {
268 run = function(self)
269 return "ok"
270 end
271 }
272 if _base_0.__index == nil then
273 _base_0.__index = _base_0
274 end
275 _class_0 = setmetatable({
276 __init = function() end,
277 __base = _base_0,
278 __name = "Worker"
279 }, {
280 __index = _base_0,
281 __call = function(cls, ...)
282 local _self_0 = setmetatable({ }, _base_0)
283 cls.__init(_self_0, ...)
284 return _self_0
285 end
286 })
287 _base_0.__class = _class_0
288 Worker = _class_0
289end
290do
291 registry["Worker"] = Worker
292end
293return
294local add
295add = function(a, b)
296 return a + b
297end
298do
299 local __orig_add = add
300 add = function(...)
301 for i = 1, select("#", ...) do
302 assert(type(select(i, ...)) == "number", "expected number for arg " .. tostring(i))
303 end
304 return __orig_add(...)
305 end
306end
197xpcall(function() 307xpcall(function()
198 return func(1, 2, 3) 308 return func(1, 2, 3)
199end, function(err) 309end, function(err)