Skip to content

Commit

Permalink
Add convenience functions to build AST nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
franko committed Feb 25, 2016
1 parent 639fe24 commit 7f3bb9c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lang/lua-ast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ local function ident(name, line)
return build("Identifier", { name = name, line = line })
end

local function literal(value, line)
return build("Literal", { value = value, line = line })
end

local function field(obj, name, line)
return build("MemberExpression", { object = obj, property = ident(name), computed = false, line = line })
end

local function logical_binop(op, left, right, line)
return build("LogicalExpression", { operator = op, left = left, right = right, line = line })
end

local function binop(op, left, right, line)
return build("BinaryExpression", { operator = op, left = left, right = right, line = line })
end

local function empty_table(line)
return build("Table", { keyvals = { }, line = line })
end

local function does_multi_return(expr)
local k = expr.kind
return k == "CallExpression" or k == "SendExpression" or k == "Vararg"
Expand Down

0 comments on commit 7f3bb9c

Please sign in to comment.