-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved everything out of redundant ``compiler`` parent directory * Created test case for the README example * Make VarAssign give a list of nodes (either Ident or Index) instead of a list of names * Reimplement deobsfuscating hex escaped strings
- Loading branch information
Showing
16 changed files
with
129 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
---@type NodeKinds | ||
local NODE_KINDS = require("parser/lua").Kinds | ||
|
||
local fmt = string.format | ||
|
||
-- Extends format mode | ||
local Mode = assert( require("codegen/mode-lua/format") ) | ||
|
||
---@param self Transpiler | ||
---@param data table | ||
Mode[NODE_KINDS.Comment] = function(self, data) | ||
local multiline, inner, depth = data[1], data[2], data[3] | ||
|
||
if multiline then | ||
local equals = string.rep("=", depth) | ||
return fmt("--[%s[%s]%s]", equals, inner, equals) | ||
else | ||
return "--" .. inner | ||
end | ||
end | ||
|
||
---@param self Transpiler | ||
---@param data table | ||
Mode[NODE_KINDS.Literal] = function(self, data) | ||
local kind, raw, val = data[1], data[2], data[3] | ||
if kind == "string" then | ||
-- Replace escape sequences with their actual characters | ||
local str = val:gsub("\\x(%x%x)",function (x) return string.char(tonumber(x,16)) end) | ||
return fmt("%q", str) | ||
elseif kind == "number" then | ||
return tostring(val) | ||
else | ||
return raw | ||
end | ||
end | ||
|
||
return Mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
local Lexer = require("compiler/lexer/lua") | ||
local Lexer = require("lexer/lua") | ||
|
||
local lexer = Lexer.new() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--[[ | ||
This is a test to make sure the README.md example still actually parses and compiles properly. | ||
]] | ||
|
||
|
||
local handle = assert( io.open("README.md", "r"), "Could not open README.md" ) | ||
local markdown = handle:read("*a") | ||
handle:close() | ||
|
||
local sources = {} | ||
for src in markdown:gmatch("```lua([^`]+)```") do | ||
sources[#sources + 1] = src:sub(2, -2) | ||
end | ||
|
||
local lexer = require("lexer/lua").new() | ||
local parser = require("parser/lua").new() | ||
local transpiler = require("codegen/lua").new(require("codegen/mode-lua/deobsfuscate")) | ||
|
||
local tokens = assert( lexer:parse(sources[1]) ) | ||
local nodes = assert( parser:parse(tokens) ) | ||
local code = assert( transpiler:process(nodes) ) | ||
|
||
Assert.equal(sources[2], code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters