From 3f31b09e7404e1ea374bbeb230bf34664b641efb Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 26 Sep 2018 14:00:05 -0700 Subject: [PATCH] Updated to the point of actually compiling. --- nomnom/code_obj.nom | 9 ++++++--- nomnom/compile.nom | 2 +- nomnom/decompile.nom | 12 ++++++------ nomnom/files.nom | 2 +- nomnom/parser.nom | 13 +++++++------ nomnom/pretty_errors.nom | 7 ++++--- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/nomnom/code_obj.nom b/nomnom/code_obj.nom index 057748f..cc7bc04 100644 --- a/nomnom/code_obj.nom +++ b/nomnom/code_obj.nom @@ -163,20 +163,23 @@ object (Lua Code) extends (Code): %statements::add %suffix return %statements - action [Lua Code from %source {%bits:[]}]: + action [Lua Code from %source %bits]: if (%bits is text): %bits = [%bits] if (%source is a "Syntax Tree"): %source = %source.source return (..) Lua Code {source:%source, bits:%bits, is_value:(no), free_vars:[]} - action [Lua Value from %tree {%bits:[]}]: + action [Lua Code from %source] (Lua Code from %source []) + action [Lua Value from %tree %bits]: if (%bits is text): %bits = [%bits] if (%source is a "Syntax Tree"): %source = %source.source return (..) Lua Code {source:%source, bits:%bits, is_value:(yes), free_vars:[]} + action [Lua Value from %tree] (Lua Value from %tree []) object (Nomsu Code) extends (Code): - action [Nomsu Code from %source {%bits:[]}]: + action [Nomsu Code from %source %bits]: if (%bits is text): %bits = [%bits] if (%source is a "Syntax Tree"): %source = %source.source return (..) Nomsu Code {source:%source, bits:%bits} + action [Nomsu Code from %source] (Nomsu Code from %source []) diff --git a/nomnom/compile.nom b/nomnom/compile.nom index 43e6d84..cbe775a 100644 --- a/nomnom/compile.nom +++ b/nomnom/compile.nom @@ -1,6 +1,6 @@ # This file contains the code to convert syntax trees to Lua code -use "nomnom/code_obj.nom" +#use "nomnom/code_obj.nom" action [compile %tree using %compile_actions]: assume (%tree is a "Syntax Tree") diff --git a/nomnom/decompile.nom b/nomnom/decompile.nom index 0d8d4d2..478b09e 100644 --- a/nomnom/decompile.nom +++ b/nomnom/decompile.nom @@ -1,6 +1,6 @@ # This file contains the code to convert syntax trees to Nomsu code -use "nomnom/code_obj.nom" -use "nomnom/parser.nom" +#use "nomnom/code_obj.nom" +#use "nomnom/parser.nom" # TODO: maybe re-implement the fancy coroutine checker that aborts early if nomsu gets too long action [decompile %tree inline]: @@ -55,9 +55,9 @@ action [decompile %tree inline]: %nomsu = (Nomsu Code from %tree ["\""]) for %text in recursive %tree: for %bit in %text at %i: - if: - (%bit is text): - %nomsu::add %bit + if (%bit is text): + %nomsu::add %bit + ..else: if %bit.type is: "Text": recurse %text on %bit @@ -143,7 +143,7 @@ action [decompile %tree]: # For concision: local action [recurse on %t]: %space = (%MAX_LINE - (%nomsu::trailing line length)) - if (%space <= 0): go to (Indented) + if (%space <= 0): go to (Use Indented) for %subtree in recursive %tree: if %subtree.type is: "Block": diff --git a/nomnom/files.nom b/nomnom/files.nom index a17ec85..e4b5aa2 100644 --- a/nomnom/files.nom +++ b/nomnom/files.nom @@ -2,7 +2,7 @@ use "lib/os.nom" %_SPOOFED_FILES = {} -%_FILE_CACHE = ({} with fallback %_SPOOFED_FILES) +%_FILE_CACHE = ({} with fallback % -> %_SPOOFED_FILES.%) %_BROWSE_CACHE = {} # Create a fake file and put it in the cache diff --git a/nomnom/parser.nom b/nomnom/parser.nom index 1f460bd..dc98c24 100644 --- a/nomnom/parser.nom +++ b/nomnom/parser.nom @@ -1,11 +1,12 @@ # This file contains the parser, which converts text into abstract syntax trees -use "nomonom/ast.nom" +#use "nomonom/ast.nom" %lpeg = (=lua "require('lpeg')") %re = (=lua "require('re')") -call %lpeg.setmaxstack with [20_000] +call %lpeg.setmaxstack with [20000] set {..} (action (P 1)): %lpeg.P, (action (R 1)): %lpeg.R, (action (Carg 1)): %lpeg.Carg, + (action (S 1)): %lpeg.S, (action (Cc 1)): %lpeg.Cc, (action (lpeg re pattern 1)): %re.compile, (action (lpeg re pattern 1 using 2)): %re.compile @@ -43,11 +44,11 @@ set {..} %id_patt = (((P "") - (R "09")) * ((%defs.utf8_char + (R "az") + (R "AZ") + (P "_") + (R "09"))^1 * -1)) %operator_patt = ((S "'`~!@$^&*+=|<>?/-")^1 * -1) -%text_methods = (""'s metatable).__index -%text_methods.(action (is a nomsu identifier)) = (..) +%text_methods = (""'s metatable).__methods +%text_methods.("is a nomsu identifier"::as lua id) = (..) [%str] -> (call %id_patt.match with [%id_patt, %str]) -%text_methods.(action (is a nomsu id)) = %text_methods.(action (is a nomsu identifier)) -%text_methods.(action (is a nomsu operator)) = (..) +%text_methods.("is a nomsu id"::as lua id) = %text_methods.("is a nomsu identifier"::as lua id) +%text_methods.("is a nomsu operator"::as lua id) = (..) [%str] -> (call %operator_patt.match with [%operator_patt, %str]) %peg_tidier = (..) diff --git a/nomnom/pretty_errors.nom b/nomnom/pretty_errors.nom index 732f3b9..ffc6fd1 100644 --- a/nomnom/pretty_errors.nom +++ b/nomnom/pretty_errors.nom @@ -8,8 +8,9 @@ local action [boxed %text]: %max_line = (..) max of ((visible size of %line) for %line in (%text::lines)) %ret = (..) - "\n\%text"::with "\n([^\n]*)" as % -> (..) - "\n\%\(" "::* (%max_line - (visible size of %))) \027[0m" + "\n\%text"::with "\n([^\n]*)" -> (..) + [%] -> (..) + "\n\%\(" "::* (%max_line - (visible size of %))) \027[0m" return %ret.[2,-1] action [%err as a pretty error]: @@ -66,7 +67,7 @@ action [%err as a pretty error]: ..\027[47;31;1m\((" \(%err.error)"::wrapped to %box_width)::with "\n" -> "\n\027[47;31;1m ")" if %err.hint: err_text += "\n\027[47;30m\((" Suggestion: \(%err.hint)"::wrapped to %box_width)::with "\n" -> "\n\027[47;30m ")" - %err_msg += "\n\027[33;1m \((%err_text boxed) with "\n" -> "\n ")" + %err_msg += "\n\027[33;1m \((%err_text boxed)::with "\n" -> "\n ")" for %i in (%err_linenum_end + 1) to (%err_linenum_end + %context): %line = (%err_code::line %i)