Skip to content

Commit e21d228

Browse files
committed
Updated changelog.
1 parent 2da7088 commit e21d228

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

CHANGELOG.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
Changelog
22
Dumb Lua Parser
33

4+
v2.3 (2022-06-23)
5+
- Added utility functions: findDeclaredNames(), findGlobalReferences(), findShadows().
6+
- Added token functions: updateToken(), cloneToken().
7+
- simplify() handles some more cases.
8+
- Fixed newToken("string", ...) always raising an error.
9+
410
v2.2 (2022-06-02)
5-
- Added function isStatement().
11+
- Added function: isStatement().
612
- Fixed updateReferences() not always updating all references properly (which sometimes broke minify()).
713
- Fixed backslashes in string literals not being outputted as \\.
814
- LuaJIT: Fixed validateTree() reporting 64-bit integers as invalid literal values.
915

1016
v2.1 (2021-09-03)
11-
- Added functions: parseExpression(), valueToAst(), validateTree(), isExpression(), newNodeFast().
17+
- Added AST functions: parseExpression(), valueToAst(), validateTree(), isExpression(), newNodeFast().
1218
- Added AST node fields: AstNode.pretty, AstNode.prefix, AstNode.suffix .
1319
- tokenize(): Added option to keep whitespace tokens (which is a new token type).
1420
- toLua(): Added nodeCallback argument.
@@ -34,7 +40,7 @@ Added:
3440
- Added special parsing rules for 'n/0'.
3541
- Added AST functions: cloneNode(), cloneTree(), traverseTreeReverse(), getChild(), setChild(), addChild(), removeChild().
3642
- Added token functions: concatTokens(), newToken().
37-
- Added function formatMessage().
43+
- Added function: formatMessage().
3844
- Added AST node fields: AstVararg.declaration, AstGoto.label, AstIdentifier.attribute .
3945
- Added more common fields to AST nodes.
4046
- Added argument 'leavesFirst' to traverseTree().

dumbParser.lua

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
--= Tokenize Lua code or create ASTs (Abstract Syntax Trees)
77
--= and convert the data back to Lua.
88
--=
9-
--= Version: 2.2-dev
9+
--= Version: 2.3
1010
--=
1111
--= License: MIT (see the bottom of this file)
1212
--= Website: http://refreezed.com/luaparser/
@@ -454,9 +454,9 @@ Special number notation rules.
454454
455455
-============================================================]=]
456456

457-
local PARSER_VERSION = "2.2.0-dev"
457+
local PARSER_VERSION = "2.3.0"
458458

459-
local NORMALIZE_MINUS_ZERO, HANDLE_ENV
459+
local NORMALIZE_MINUS_ZERO, HANDLE_ENV -- Should HANDLE_ENV be a setting?
460460
do
461461
local n = 0
462462
NORMALIZE_MINUS_ZERO = tostring(-n) == "0" -- Lua 5.3+ normalizes -0 to 0.
@@ -478,7 +478,6 @@ local tonumber = tonumber
478478
local tostring = tostring
479479
local type = type
480480

481-
local io = io
482481
local ioOpen = io.open
483482
local ioWrite = io.write
484483

@@ -574,7 +573,6 @@ local TOKEN_BYTES = {
574573
NAME_START = newCharSet"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_",
575574
DASH = newCharSet"-",
576575
NUM = newCharSet"0123456789",
577-
-- NUM_OR_DOT = newCharSet"0123456789.",
578576
QUOTE = newCharSet"\"'",
579577
SQUARE = newCharSet"[",
580578
DOT = newCharSet".",
@@ -602,8 +600,6 @@ do
602600
MIN_INT = math.mininteger or -MAX_INT-1
603601
end
604602

605-
-- local EMPTY_TABLE = {}
606-
607603
local nextSerialNumber = 1
608604

609605

@@ -858,7 +854,7 @@ do
858854
["\r"] = "{CR}",
859855
}
860856

861-
function ensurePrintable(s)
857+
--[[local]] function ensurePrintable(s)
862858
return (stringGsub(s, "[%z\1-\31\127-\255]", function(c)
863859
return CONTROL_TO_READABLE[c] or (stringByte(c) <= 31 or stringByte(c) >= 127) and F("{%d}", stringByte(c)) or nil
864860
end))
@@ -932,7 +928,7 @@ do
932928
return len
933929
end
934930

935-
function formatMessageInFile(prefix, contents, path, pos, agent, s, ...)
931+
--[[local]] function formatMessageInFile(prefix, contents, path, pos, agent, s, ...)
936932
if agent ~= "" then
937933
agent = "["..agent.."] "
938934
end
@@ -1294,7 +1290,7 @@ do
12941290
end
12951291

12961292
-- tokens, error = tokenize( luaString [, keepWhitespaceTokens=false ] [, pathForErrorMessages="?" ] )
1297-
function tokenize(s, keepWhitespaceTokens, path)
1293+
--[[local]] function tokenize(s, keepWhitespaceTokens, path)
12981294
assertArg1("tokenize", 1, s, "string")
12991295

13001296
if type(keepWhitespaceTokens) == "string" then
@@ -1318,7 +1314,6 @@ do
13181314
local BYTES_NAME_START = TOKEN_BYTES.NAME_START
13191315
local BYTES_DASH = TOKEN_BYTES.DASH
13201316
local BYTES_NUM = TOKEN_BYTES.NUM
1321-
-- local BYTES_NUM_OR_DOT = TOKEN_BYTES.NUM_OR_DOT
13221317
local BYTES_QUOTE = TOKEN_BYTES.QUOTE
13231318
local BYTES_SQUARE = TOKEN_BYTES.SQUARE
13241319
local BYTES_DOT = TOKEN_BYTES.DOT
@@ -1740,6 +1735,8 @@ end
17401735
-- updateToken( whitespaceToken, contents )
17411736
--
17421737
local function updateToken(tok, tokValue)
1738+
-- @Copypaste from newToken().
1739+
17431740
if tok.type == "keyword" then
17441741
if type(tokValue) ~= "string" then errorf(2, "Expected string value for 'keyword' token. (Got %s)", type(tokValue)) end
17451742
if not KEYWORDS[tokValue] then errorf(2, "Invalid keyword '%s'.", tokValue) end
@@ -2009,7 +2006,7 @@ local function parseTable(tokens, tokStart) --> tableNode, token, error
20092006
return tableNode, tok
20102007
end
20112008

2012-
function parseExpressionInternal(tokens, tokStart, lastPrecedence) --> expression, token, error
2009+
--[[local]] function parseExpressionInternal(tokens, tokStart, lastPrecedence) --> expression, token, error
20132010
local tok = tokStart
20142011
local canParseLookupOrCall = false
20152012
local currentToken = tokens[tok]
@@ -2323,7 +2320,7 @@ function parseExpressionInternal(tokens, tokStart, lastPrecedence) --> expressio
23232320
return expr, tok
23242321
end
23252322

2326-
function parseExpressionList(tokens, tok, expressions) --> success, token, error
2323+
--[[local]] function parseExpressionList(tokens, tok, expressions) --> success, token, error
23272324
while true do
23282325
local expr, tokNext, err = parseExpressionInternal(tokens, tok, 0)
23292326
if not expr then return false, tok, err end
@@ -2338,7 +2335,7 @@ function parseExpressionList(tokens, tok, expressions) --> success, token, error
23382335
end
23392336
end
23402337

2341-
function parseFunctionParametersAndBody(tokens, tokStart, funcTok) --> func, token, error
2338+
--[[local]] function parseFunctionParametersAndBody(tokens, tokStart, funcTok) --> func, token, error
23422339
local tok = tokStart
23432340
local func = AstFunction(tokens[funcTok])
23442341

@@ -2799,7 +2796,7 @@ end
27992796

28002797
local statementErrorReported = false
28012798

2802-
function parseBlock(tokens, tok, blockTok, stopAtEndKeyword) --> block, token, error
2799+
--[[local]] function parseBlock(tokens, tok, blockTok, stopAtEndKeyword) --> block, token, error
28032800
local block = AstBlock(tokens[blockTok])
28042801
local statements = block.statements
28052802

@@ -3303,7 +3300,7 @@ local function cloneNodeAndMaybeChildren(node, cloneChildren)
33033300
return clone
33043301
end
33053302

3306-
function cloneNodeArrayAndChildren(cloneArray, sourceArray)
3303+
--[[local]] function cloneNodeArrayAndChildren(cloneArray, sourceArray)
33073304
for i, node in ipairs(sourceArray) do
33083305
cloneArray[i] = cloneNodeAndMaybeChildren(node, true)
33093306
end
@@ -3541,11 +3538,11 @@ do
35413538
end
35423539
end
35433540

3544-
function printNode(node)
3541+
--[[local]] function printNode(node)
35453542
_printNode(node)
35463543
end
35473544

3548-
function printTree(node)
3545+
--[[local]] function printTree(node)
35493546
_printTree(node, 0, nil)
35503547
end
35513548
end
@@ -5112,7 +5109,7 @@ do
51125109

51135110
local cache = {}
51145111

5115-
function generateName(nameGeneration)
5112+
--[[local]] function generateName(nameGeneration)
51165113
if not cache[nameGeneration] then
51175114
-- @Cleanup: Output the most significant byte first. (We need to know the length beforehand then, probably, so we use the correct bank.)
51185115
local charBytes = {}
@@ -5421,7 +5418,7 @@ do
54215418
end
54225419

54235420
-- Returns nil and a message or error.
5424-
function writeStatements(buffer, pretty, indent, lastOutput, statements, nodeCb)
5421+
--[[local]] function writeStatements(buffer, pretty, indent, lastOutput, statements, nodeCb)
54255422
local skipNext = false
54265423

54275424
for i, statement in ipairs(statements) do
@@ -5584,7 +5581,7 @@ do
55845581

55855582
-- success, lastOutput = writeNode( buffer, pretty, indent, lastOutput, node, maySafelyOmitParens, nodeCallback )
55865583
-- Returns nil and a message or error.
5587-
function writeNode(buffer, pretty, indent, lastOutput, node, maySafelyOmitParens, nodeCb)
5584+
--[[local]] function writeNode(buffer, pretty, indent, lastOutput, node, maySafelyOmitParens, nodeCb)
55885585
if nodeCb then nodeCb(node, buffer) end
55895586
pretty = choosePretty(node, pretty)
55905587

@@ -6122,7 +6119,7 @@ do
61226119
-- luaString = toLua( astNode [, prettyOuput=false, nodeCallback ] )
61236120
-- nodeCallback = function( node, outputBuffer )
61246121
-- Returns nil and a message on error.
6125-
function toLua(node, pretty, nodeCb)
6122+
--[[local]] function toLua(node, pretty, nodeCb)
61266123
assertArg1("toLua", 1, node, "table")
61276124

61286125
local buffer = {}
@@ -6623,7 +6620,7 @@ do
66236620
end
66246621

66256622
-- isValid, errors = validateTree( astNode )
6626-
function validateTree(node)
6623+
--[[local]] function validateTree(node)
66276624
local path = {}
66286625
local errors = {}
66296626

@@ -6712,6 +6709,7 @@ end
67126709

67136710

67146711
-- identifiers = findGlobalReferences( astNode )
6712+
-- Note: updateReferences() must have been called first!
67156713
local function findGlobalReferences(theNode)
67166714
local idents = {}
67176715

@@ -6781,6 +6779,7 @@ end
67816779
-- shadowSequences = findShadows( astNode )
67826780
-- shadowSequences = { shadowSequence1, ... }
67836781
-- shadowSequence = { shadowingIdentifier, shadowedIdentifier1, ... }
6782+
-- Note: updateReferences() must have been called first!
67846783
local function findShadows(theNode)
67856784
local shadowSequences = {}
67866785
local shadowSequenceByIdent = {}

0 commit comments

Comments
 (0)