aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compatibility/4.10.12.7.nom2
-rw-r--r--nomsu.4.peg4
-rw-r--r--nomsu_decompiler.lua12
-rw-r--r--nomsu_decompiler.moon9
4 files changed, 22 insertions, 5 deletions
diff --git a/compatibility/4.10.12.7.nom b/compatibility/4.10.12.7.nom
index c314b68..4c363ab 100644
--- a/compatibility/4.10.12.7.nom
+++ b/compatibility/4.10.12.7.nom
@@ -27,6 +27,8 @@ upgrade action (%k = %v for %i in %start to %stop via %step) to "4.10.12.7" as (
{:for %i in %start to %stop by %step: add %k = %v}
upgrade action (% as lua statements) to "4.10.12.7" as (% as lua)
+upgrade action (compile error at %pos %err hint %hint) to "4.10.12.7" as (..)
+ compile error at %pos %err %hint
upgrade %tree to "4.10.12.7" as:
if (%tree.type == "FileChunks"):
diff --git a/nomsu.4.peg b/nomsu.4.peg
index e7fc09a..b2e636f 100644
--- a/nomsu.4.peg
+++ b/nomsu.4.peg
@@ -173,7 +173,9 @@ indented_plain_text (Text):
text_interpolation:
inline_text_interpolation / ("\" indented_expression (blank_lines =curr_indent "..")?)
-number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / "0x" [0-9a-fA-F]+ / ([0-9]+)))-> tonumber)
+number (Number):
+ (&("-"? "0x" [0-9a-fA-F]+) {:hex: '' -> 'yes' :})?
+ (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / "0x" [0-9a-fA-F]+ / ([0-9]+)))-> tonumber)
-- Variables can be nameless (i.e. just %) and can only contain identifier chars.
-- This ensures you don't get weird parsings of `%x+%y` or `%'s thing`.
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua
index 46b769e..4655211 100644
--- a/nomsu_decompiler.lua
+++ b/nomsu_decompiler.lua
@@ -12,7 +12,7 @@ do
end
local re = require('re')
local MAX_LINE = 80
-local GOLDEN_RATIO = ((1 + math.sqrt(5)) / 2)
+local GOLDEN_RATIO = ((math.sqrt(5) - 1) / 2)
local utf8_char_patt = (R("\194\223") * R("\128\191") + R("\224\239") * R("\128\191") * R("\128\191") + R("\240\244") * R("\128\191") * R("\128\191") * R("\128\191"))
local operator_patt = S("'`~!@$^&*+=|<>?/-") ^ 1 * -1
local identifier_patt = (R("az", "AZ", "09") + P("_") + utf8_char_patt) ^ 1 * -1
@@ -179,7 +179,15 @@ tree_to_inline_nomsu = function(tree)
end
return nomsu
elseif "Number" == _exp_0 then
- return NomsuCode:from(tree.source, tostring(tree[1]))
+ local s
+ if tree.hex and tree[1] < 0 then
+ s = ("-0x%X"):format(-tree[1])
+ elseif tree.hex then
+ s = ("0x%X"):format(tree[1])
+ else
+ s = tostring(tree[1])
+ end
+ return NomsuCode:from(tree.source, s)
elseif "Var" == _exp_0 then
return NomsuCode:from(tree.source, "%", tree[1])
elseif "FileChunks" == _exp_0 then
diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon
index 99dce3e..5b72823 100644
--- a/nomsu_decompiler.moon
+++ b/nomsu_decompiler.moon
@@ -4,7 +4,7 @@
re = require 're'
MAX_LINE = 80
-GOLDEN_RATIO = ((1+math.sqrt(5))/2)
+GOLDEN_RATIO = ((math.sqrt(5)-1)/2)
-- Parsing helper functions
utf8_char_patt = (
@@ -130,7 +130,12 @@ tree_to_inline_nomsu = (tree)->
return nomsu
when "Number"
- return NomsuCode\from(tree.source, tostring(tree[1]))
+ s = if tree.hex and tree[1] < 0
+ ("-0x%X")\format(-tree[1])
+ elseif tree.hex
+ ("0x%X")\format(tree[1])
+ else tostring(tree[1])
+ return NomsuCode\from(tree.source, s)
when "Var"
return NomsuCode\from(tree.source, "%", tree[1])