diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-09 17:32:48 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-09 17:33:04 -0800 |
| commit | ed70165294a6b846a9b0d513689dea03539755f7 (patch) | |
| tree | 5f81723db4638e322d2b9d1a8d07000b2c5cb59d | |
| parent | e96ae0c78dc511d361d37bc69259d18a68648b8f (diff) | |
Better handling of shebangs and comments at the top of a file.
| -rw-r--r-- | compatibility/compatibility.nom | 1 | ||||
| -rw-r--r-- | nomsu.4.peg | 4 | ||||
| -rw-r--r-- | nomsu_decompiler.lua | 3 | ||||
| -rw-r--r-- | nomsu_decompiler.moon | 2 | ||||
| -rwxr-xr-x | tools/upgrade.nom | 4 |
5 files changed, 9 insertions, 5 deletions
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom index 09eacc2..1df91f1 100644 --- a/compatibility/compatibility.nom +++ b/compatibility/compatibility.nom @@ -93,6 +93,7 @@ externally [..] set %with_upgraded_args 's metatable to (%tree 's metatable) %tree = (call %UPGRADES.%ver with [%with_upgraded_args, %end_version]) + %tree.shebang = "#!/usr/bin/env nomsu -V\%end_version" return %tree externally (%tree upgraded from %start_version) means (..) diff --git a/nomsu.4.peg b/nomsu.4.peg index e0a5781..bbff67d 100644 --- a/nomsu.4.peg +++ b/nomsu.4.peg @@ -6,13 +6,13 @@ file: {:curr_indent: %nil :} !. -shebang: "#!" (!"nomsu" [^%nl])* "nomsu" ws+ "-V" ws* {:version: [0-9.]+ :} [^%nl]* +shebang: "#!" (!"nomsu" [^%nl])* "nomsu" ws+ "-V" ws* {:version: [0-9.]+ :} [^%nl]* (%nl / !.) eof: !. file_chunks (FileChunks): {:curr_indent: ' '* :} - shebang? comment? blank_lines? + {:shebang: shebang :}? (top_block (nl_nodent section_division top_block)*) blank_lines? ws* unexpected_chunk? diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua index b1e02f7..142229a 100644 --- a/nomsu_decompiler.lua +++ b/nomsu_decompiler.lua @@ -223,6 +223,9 @@ tree_to_nomsu = function(tree) end local _exp_0 = tree.type if "FileChunks" == _exp_0 then + if tree.shebang then + nomsu:append(tree.shebang, "\n") + end local should_clump should_clump = function(prev_line, line) if prev_line.type == "Action" and line.type == "Action" then diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon index 75eae6d..380bbca 100644 --- a/nomsu_decompiler.moon +++ b/nomsu_decompiler.moon @@ -172,6 +172,8 @@ tree_to_nomsu = (tree)-> switch tree.type when "FileChunks" + if tree.shebang + nomsu\append tree.shebang, "\n" should_clump = (prev_line, line)-> if prev_line.type == "Action" and line.type == "Action" if prev_line.stub == "use" then return line.stub == "use" diff --git a/tools/upgrade.nom b/tools/upgrade.nom index a937e46..5133c76 100755 --- a/tools/upgrade.nom +++ b/tools/upgrade.nom @@ -45,9 +45,7 @@ for %path in %args: %tree = (%code parsed) %uptree = (..) %tree upgraded from (%start_version or (%tree.version or (Nomsu version))) to %version - %text = "\ - ..#!/usr/bin/env nomsu -V\%version - \(%uptree as nomsu)" + %text = (%uptree as nomsu) when: %inplace: |
