Skip to content

Commit d985e62

Browse files
committed
Added isStatement().
1 parent 085da25 commit d985e62

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

dumbParser.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ removeChild()
162162
isExpression()
163163
bool = parser.isExpression( astNode )
164164
Returns true for expression nodes and false for statements.
165+
Note that call nodes count as expressions for this function, i.e. return true.
166+
167+
isStatement()
168+
bool = parser.isStatement( astNode )
169+
Returns true for statements and false for expression nodes.
170+
Note that call nodes count as statements for this function, i.e. return true.
165171
166172
validateTree()
167173
isValid, errorMessages = validateTree( astNode )
@@ -186,7 +192,7 @@ updateReferences()
186192
parser.updateReferences( astNode [, updateTopNodePositionInfo=true ] )
187193
Update references between nodes in the tree.
188194
This function sets 'parent'+'container'+'key' for all nodes, 'declaration' for identifiers and vararg nodes, and 'label' for goto nodes.
189-
If 'updateTopNodePositionInfo' is false then 'parent', 'container' and 'key' will remain as-it for 'astNode' specifically.
195+
If 'updateTopNodePositionInfo' is false then 'parent', 'container' and 'key' will remain as-is for 'astNode' specifically.
190196
191197
simplify()
192198
stats = simplify( astNode )
@@ -6428,6 +6434,10 @@ local function isExpression(node)
64286434
return EXPRESSION_TYPES[node.type] == true
64296435
end
64306436

6437+
local function isStatement(node)
6438+
return EXPRESSION_TYPES[node.type] == nil or node.type == "call"
6439+
end
6440+
64316441

64326442

64336443
local function resetNextId()
@@ -6520,6 +6530,7 @@ parser = {
65206530
removeChild = removeChild,
65216531

65226532
isExpression = isExpression,
6533+
isStatement = isStatement,
65236534
validateTree = validateTree,
65246535

65256536
traverseTree = traverseTree,
@@ -6554,7 +6565,7 @@ return parser
65546565

65556566
--[=[===========================================================
65566567
6557-
Copyright © 2020-2021 Marcus 'ReFreezed' Thunström
6568+
Copyright © 2020-2022 Marcus 'ReFreezed' Thunström
65586569
65596570
Permission is hereby granted, free of charge, to any person obtaining a copy
65606571
of this software and associated documentation files (the "Software"), to deal

testsuite.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ test("AST manipulation", function()
395395
local repeatLoop = parser.newNode("repeat")
396396
local forLoop = parser.newNode("for", "numeric")
397397

398+
assert( parser.isExpression(identifier1))
399+
assert(not parser.isStatement (identifier1))
400+
assert(not parser.isExpression(block))
401+
assert( parser.isStatement (block))
402+
assert( parser.isExpression(call))
403+
assert( parser.isStatement (call))
404+
398405
parser.setChild(call, "callee", identifier1)
399406
parser.setChild(declaration, "names", 1, identifier2)
400407

0 commit comments

Comments
 (0)