|
6 | 6 | --= Tokenize Lua code or create ASTs (Abstract Syntax Trees) |
7 | 7 | --= and convert the data back to Lua. |
8 | 8 | --= |
9 | | ---= Version: 2.0.1-dev |
| 9 | +--= Version: 2.1 (2021-09-03) |
10 | 10 | --= |
11 | 11 | --= License: MIT (see the bottom of this file) |
12 | 12 | --= Website: http://luaparser.refreezed.com/ |
@@ -216,6 +216,7 @@ toLua() |
216 | 216 | Convert an AST to Lua, optionally call a function on each node before they are turned into Lua. |
217 | 217 | Any node in the tree with a .pretty attribute will override the 'prettyOuput' flag for itself and its children. |
218 | 218 | Nodes can also have a .prefix and/or .suffix attribute with Lua code to output before/after the node (e.g. declaration.names[1].suffix="--[[foo]]"). |
| 219 | + outputBuffer is an array of Lua code that has been output so far. |
219 | 220 | Returns nil and a message on error. |
220 | 221 |
|
221 | 222 | printTokens() |
@@ -421,7 +422,7 @@ Special number notation rules. |
421 | 422 |
|
422 | 423 | -============================================================]=] |
423 | 424 |
|
424 | | -local PARSER_VERSION = "2.0.1-dev" |
| 425 | +local PARSER_VERSION = "2.1.0" |
425 | 426 |
|
426 | 427 | local NORMALIZE_MINUS_ZERO, HANDLE_ENV |
427 | 428 | do |
@@ -619,6 +620,11 @@ local function populateCommonNodeFields(token, node) |
619 | 620 | -- node.container = nil -- Refers to the specific table that the node is in, which could be the parent itself or a field in the parent. |
620 | 621 | -- node.key = nil -- Refers to the specific field in the container that the node is in (which is either a string or an integer). |
621 | 622 |
|
| 623 | + -- toLua() uses these fields if present: |
| 624 | + -- node.pretty = bool |
| 625 | + -- node.prefix = luaString |
| 626 | + -- node.suffix = luaString |
| 627 | + |
622 | 628 | return node |
623 | 629 | end |
624 | 630 |
|
@@ -3040,6 +3046,11 @@ local function cloneNodeAndMaybeChildren(node, cloneChildren) |
3040 | 3046 | errorf("Invalid node type '%s'.", tostring(nodeType)) |
3041 | 3047 | end |
3042 | 3048 |
|
| 3049 | + clone.pretty = node.pretty |
| 3050 | + clone.prefix = node.prefix |
| 3051 | + clone.suffix = node.suffix |
| 3052 | + -- Should we set node.token etc. too? @Incomplete |
| 3053 | + |
3043 | 3054 | return clone |
3044 | 3055 | end |
3045 | 3056 |
|
|
0 commit comments