1- --[[ = ===========================================================
1+ --[=[ ===========================================================
22--=
33--= Dumb Lua Parser - Lua parsing library
44--= by Marcus 'ReFreezed' Thunström
@@ -54,7 +54,7 @@ print(lua)
5454tokenize, tokenizeFile
5555newToken, concatTokens
5656parse, parseExpression, parseFile
57- newNode, newNodeFast, cloneNode, cloneTree, getChild, setChild, addChild, removeChild
57+ newNode, newNodeFast, valueToAst, cloneNode, cloneTree, getChild, setChild, addChild, removeChild
5858validateTree
5959traverseTree, traverseTreeReverse
6060updateReferences
@@ -107,6 +107,10 @@ newNodeFast()
107107 astNode = parser.newNodeFast( nodeType, arguments... )
108108 Same as newNode() but without any validation. (Search for 'NodeCreation' for more info.)
109109
110+ valueToAst()
111+ astNode = parser.valueToAst( value [, sortTableKeys=false ] )
112+ Convert a Lua value (number, string, boolean, nil or table) to an AST.
113+
110114cloneNode()
111115 astNode = parser.cloneNode( astNode )
112116 Clone an existing AST node (but not any children).
@@ -155,6 +159,10 @@ removeChild()
155159 The result is the same as doing the following, but with more error checking:
156160 table.remove(astNode[fieldName], index)
157161
162+ isExpression()
163+ bool = parser.isExpression( astNode )
164+ Returns true for expression nodes and false for statements.
165+
158166validateTree()
159167 isValid, errorMessages = validateTree( astNode )
160168 Check for errors in an AST (e.g. missing condition expressions for if statements).
@@ -206,6 +214,8 @@ toLua()
206214 luaString = parser.toLua( astNode [, prettyOuput=false, nodeCallback ] )
207215 nodeCallback = function( node, outputBuffer )
208216 Convert an AST to Lua, optionally call a function on each node before they are turned into Lua.
217+ Any node in the tree with a .pretty attribute will override the 'prettyOuput' flag for itself and its children.
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]]").
209219 Returns nil and a message on error.
210220
211221printTokens()
@@ -409,7 +419,7 @@ Special number notation rules.
409419 NaN.
410420
411421
412- -- ============================================================]]
422+ -============================================================]= ]
413423
414424local PARSER_VERSION = " 2.0.1-dev"
415425
52175227 -- Returns nil and a message or error.
52185228 function writeNode (buffer , pretty , indent , lastOutput , node , maySafelyOmitParens , nodeCb )
52195229 if nodeCb then nodeCb (node , buffer ) end
5220- pretty = choosePretty (node , pretty ) -- @Doc: AstNode.pretty
5230+ pretty = choosePretty (node , pretty )
52215231
5222- tableInsert (buffer , node .prefix ) -- @Doc: AstNode.prefix
5232+ tableInsert (buffer , node .prefix )
52235233
52245234 local nodeType = node .type
52255235
57455755 return false , F (" Error: Unknown node type '%s'." , tostring (nodeType ))
57465756 end
57475757
5748- tableInsert (buffer , node .suffix ) -- @Doc: AstNode.suffix
5758+ tableInsert (buffer , node .suffix )
57495759
57505760 return true , lastOutput
57515761 end
@@ -6490,15 +6500,15 @@ parser = {
64906500
64916501 newNode = newNode ,
64926502 newNodeFast = newNodeFast ,
6493- valueToAst = valueToAst , -- @Doc
6503+ valueToAst = valueToAst ,
64946504 cloneNode = cloneNode ,
64956505 cloneTree = cloneTree ,
64966506 getChild = getChild ,
64976507 setChild = setChild ,
64986508 addChild = addChild ,
64996509 removeChild = removeChild ,
65006510
6501- isExpression = isExpression , -- @Doc
6511+ isExpression = isExpression ,
65026512 validateTree = validateTree ,
65036513
65046514 traverseTree = traverseTree ,
@@ -6517,7 +6527,7 @@ parser = {
65176527
65186528 formatMessage = formatMessage ,
65196529
6520- resetNextId = resetNextId , -- @Doc
6530+ resetNextId = resetNextId , -- @Undocumented
65216531
65226532 -- Settings.
65236533 printIds = false ,
0 commit comments