From ec26010fd100bb014584653e0e1370dba816fd1f Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 4 Dec 2025 02:57:43 +0800 Subject: Updated reserved comments function. --- doc/docs/doc/README.md | 43 ++++++++++++++++++++++++++++++++++++++- doc/docs/zh/doc/README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) (limited to 'doc/docs') diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 07e35e7..11c9427 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -4729,7 +4729,7 @@ Converts the code to the AST. **Signature:** ```lua -to_ast: function(code: string, flattenLevel?: number, astName?: string): +to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean): --[[AST]] AST | nil, --[[error]] nil | string ``` @@ -4741,6 +4741,7 @@ to_ast: function(code: string, flattenLevel?: number, astName?: string): | code | string | The code. | | flattenLevel | integer | [Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2. | | astName | string | [Optional] The AST name. Default is "File". | +| reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is false. | **Returns:** @@ -4749,6 +4750,33 @@ to_ast: function(code: string, flattenLevel?: number, astName?: string): | AST \| nil | The AST, or nil if the conversion failed. | | string \| nil | The error message, or nil if the conversion succeeded. | +#### format + +**Type:** Function. + +**Description:** + +Formats the YueScript code. + +**Signature:** +```lua +format: function(code: string, tabSize?: number, reserveComment?: boolean): string +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| code | string | The code. | +| tabSize | integer | [Optional] The tab size. Default is 4. | +| reserveComment | boolean | [Optional] Whether to reserve the original comments. Default is true. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| string | The formatted code. | + #### __call **Type:** Metamethod. @@ -4820,6 +4848,19 @@ Whether the compiler should reserve the original line number in the compiled cod reserve_line_number: boolean ``` +#### reserve_comment + +**Type:** Field. + +**Description:** + +Whether the compiler should reserve the original comments in the compiled code. + +**Signature:** +```lua +reserve_comment: boolean +``` + #### space_over_tab **Type:** Field. diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index afef94e..da69e22 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md @@ -4686,7 +4686,7 @@ type AST = {string, integer, integer, any} **签名:** ```lua -to_ast: function(code: string, flattenLevel?: number, astName?: string): +to_ast: function(code: string, flattenLevel?: number, astName?: string, reserveComment?: boolean): --[[AST]] AST | nil, --[[error]] nil | string ``` @@ -4697,6 +4697,42 @@ to_ast: function(code: string, flattenLevel?: number, astName?: string): | --- | --- | --- | | code | string | 代码。 | | flattenLevel | integer | [可选] 扁平化级别。级别越高,会消除更多的 AST 结构的嵌套。默认为 0。最大为 2。 | +| astName | string | [可选] AST 名称。默认为 "File"。 | +| reserveComment | boolean | [可选] 是否保留原始注释。默认为 false。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| AST \| nil | AST,如果转换失败则为 nil。 | +| string \| nil | 错误消息,如果转换成功则为 nil。 | + +#### format + +**类型:** 函数。 + +**描述:** + +格式化 YueScript 代码。 + +**签名:** +```lua +format: function(code: string, tabSize?: number, reserveComment?: boolean): string +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| code | string | 代码。 | +| tabSize | integer | [可选] 制表符大小。默认为 4。 | +| reserveComment | boolean | [可选] 是否保留原始注释。默认为 true。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| string | 格式化后的代码。 | #### __call @@ -4769,6 +4805,19 @@ implicit_return_root: boolean reserve_line_number: boolean ``` +#### reserve_comment + +**类型:** 成员变量。 + +**描述:** + +编译器是否应该在编译后的代码中保留原始注释。 + +**签名:** +```lua +reserve_comment: boolean +``` + #### space_over_tab **类型:** 成员变量。 -- cgit v1.2.3-55-g6feb