Updated to the point of actually compiling.
This commit is contained in:
parent
17dfd24864
commit
3f31b09e74
@ -163,20 +163,23 @@ object (Lua Code) extends (Code):
|
|||||||
%statements::add %suffix
|
%statements::add %suffix
|
||||||
return %statements
|
return %statements
|
||||||
|
|
||||||
action [Lua Code from %source {%bits:[]}]:
|
action [Lua Code from %source %bits]:
|
||||||
if (%bits is text): %bits = [%bits]
|
if (%bits is text): %bits = [%bits]
|
||||||
if (%source is a "Syntax Tree"): %source = %source.source
|
if (%source is a "Syntax Tree"): %source = %source.source
|
||||||
return (..)
|
return (..)
|
||||||
Lua Code {source:%source, bits:%bits, is_value:(no), free_vars:[]}
|
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 (%bits is text): %bits = [%bits]
|
||||||
if (%source is a "Syntax Tree"): %source = %source.source
|
if (%source is a "Syntax Tree"): %source = %source.source
|
||||||
return (..)
|
return (..)
|
||||||
Lua Code {source:%source, bits:%bits, is_value:(yes), free_vars:[]}
|
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):
|
object (Nomsu Code) extends (Code):
|
||||||
action [Nomsu Code from %source {%bits:[]}]:
|
action [Nomsu Code from %source %bits]:
|
||||||
if (%bits is text): %bits = [%bits]
|
if (%bits is text): %bits = [%bits]
|
||||||
if (%source is a "Syntax Tree"): %source = %source.source
|
if (%source is a "Syntax Tree"): %source = %source.source
|
||||||
return (..)
|
return (..)
|
||||||
Nomsu Code {source:%source, bits:%bits}
|
Nomsu Code {source:%source, bits:%bits}
|
||||||
|
action [Nomsu Code from %source] (Nomsu Code from %source [])
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# This file contains the code to convert syntax trees to Lua code
|
# 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]:
|
action [compile %tree using %compile_actions]:
|
||||||
assume (%tree is a "Syntax Tree")
|
assume (%tree is a "Syntax Tree")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# This file contains the code to convert syntax trees to Nomsu code
|
# This file contains the code to convert syntax trees to Nomsu code
|
||||||
use "nomnom/code_obj.nom"
|
#use "nomnom/code_obj.nom"
|
||||||
use "nomnom/parser.nom"
|
#use "nomnom/parser.nom"
|
||||||
|
|
||||||
# TODO: maybe re-implement the fancy coroutine checker that aborts early if nomsu gets too long
|
# TODO: maybe re-implement the fancy coroutine checker that aborts early if nomsu gets too long
|
||||||
action [decompile %tree inline]:
|
action [decompile %tree inline]:
|
||||||
@ -55,9 +55,9 @@ action [decompile %tree inline]:
|
|||||||
%nomsu = (Nomsu Code from %tree ["\""])
|
%nomsu = (Nomsu Code from %tree ["\""])
|
||||||
for %text in recursive %tree:
|
for %text in recursive %tree:
|
||||||
for %bit in %text at %i:
|
for %bit in %text at %i:
|
||||||
if:
|
if (%bit is text):
|
||||||
(%bit is text):
|
%nomsu::add %bit
|
||||||
%nomsu::add %bit
|
..else:
|
||||||
if %bit.type is:
|
if %bit.type is:
|
||||||
"Text":
|
"Text":
|
||||||
recurse %text on %bit
|
recurse %text on %bit
|
||||||
@ -143,7 +143,7 @@ action [decompile %tree]:
|
|||||||
# For concision:
|
# For concision:
|
||||||
local action [recurse on %t]:
|
local action [recurse on %t]:
|
||||||
%space = (%MAX_LINE - (%nomsu::trailing line length))
|
%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:
|
for %subtree in recursive %tree:
|
||||||
if %subtree.type is:
|
if %subtree.type is:
|
||||||
"Block":
|
"Block":
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
use "lib/os.nom"
|
use "lib/os.nom"
|
||||||
|
|
||||||
%_SPOOFED_FILES = {}
|
%_SPOOFED_FILES = {}
|
||||||
%_FILE_CACHE = ({} with fallback %_SPOOFED_FILES)
|
%_FILE_CACHE = ({} with fallback % -> %_SPOOFED_FILES.%)
|
||||||
%_BROWSE_CACHE = {}
|
%_BROWSE_CACHE = {}
|
||||||
|
|
||||||
# Create a fake file and put it in the cache
|
# Create a fake file and put it in the cache
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
# This file contains the parser, which converts text into abstract syntax trees
|
# This file contains the parser, which converts text into abstract syntax trees
|
||||||
use "nomonom/ast.nom"
|
#use "nomonom/ast.nom"
|
||||||
|
|
||||||
%lpeg = (=lua "require('lpeg')")
|
%lpeg = (=lua "require('lpeg')")
|
||||||
%re = (=lua "require('re')")
|
%re = (=lua "require('re')")
|
||||||
call %lpeg.setmaxstack with [20_000]
|
call %lpeg.setmaxstack with [20000]
|
||||||
set {..}
|
set {..}
|
||||||
(action (P 1)): %lpeg.P, (action (R 1)): %lpeg.R, (action (Carg 1)): %lpeg.Carg,
|
(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 (Cc 1)): %lpeg.Cc, (action (lpeg re pattern 1)): %re.compile,
|
||||||
(action (lpeg re pattern 1 using 2)): %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))
|
%id_patt = (((P "") - (R "09")) * ((%defs.utf8_char + (R "az") + (R "AZ") + (P "_") + (R "09"))^1 * -1))
|
||||||
%operator_patt = ((S "'`~!@$^&*+=|<>?/-")^1 * -1)
|
%operator_patt = ((S "'`~!@$^&*+=|<>?/-")^1 * -1)
|
||||||
%text_methods = (""'s metatable).__index
|
%text_methods = (""'s metatable).__methods
|
||||||
%text_methods.(action (is a nomsu identifier)) = (..)
|
%text_methods.("is a nomsu identifier"::as lua id) = (..)
|
||||||
[%str] -> (call %id_patt.match with [%id_patt, %str])
|
[%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.("is a nomsu id"::as lua id) = %text_methods.("is a nomsu identifier"::as lua id)
|
||||||
%text_methods.(action (is a nomsu operator)) = (..)
|
%text_methods.("is a nomsu operator"::as lua id) = (..)
|
||||||
[%str] -> (call %operator_patt.match with [%operator_patt, %str])
|
[%str] -> (call %operator_patt.match with [%operator_patt, %str])
|
||||||
|
|
||||||
%peg_tidier = (..)
|
%peg_tidier = (..)
|
||||||
|
@ -8,8 +8,9 @@ local action [boxed %text]:
|
|||||||
%max_line = (..)
|
%max_line = (..)
|
||||||
max of ((visible size of %line) for %line in (%text::lines))
|
max of ((visible size of %line) for %line in (%text::lines))
|
||||||
%ret = (..)
|
%ret = (..)
|
||||||
"\n\%text"::with "\n([^\n]*)" as % -> (..)
|
"\n\%text"::with "\n([^\n]*)" -> (..)
|
||||||
"\n\%\(" "::* (%max_line - (visible size of %))) \027[0m"
|
[%] -> (..)
|
||||||
|
"\n\%\(" "::* (%max_line - (visible size of %))) \027[0m"
|
||||||
return %ret.[2,-1]
|
return %ret.[2,-1]
|
||||||
|
|
||||||
action [%err as a pretty error]:
|
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 ")"
|
..\027[47;31;1m\((" \(%err.error)"::wrapped to %box_width)::with "\n" -> "\n\027[47;31;1m ")"
|
||||||
if %err.hint:
|
if %err.hint:
|
||||||
err_text += "\n\027[47;30m\((" Suggestion: \(%err.hint)"::wrapped to %box_width)::with "\n" -> "\n\027[47;30m ")"
|
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):
|
for %i in (%err_linenum_end + 1) to (%err_linenum_end + %context):
|
||||||
%line = (%err_code::line %i)
|
%line = (%err_code::line %i)
|
||||||
|
Loading…
Reference in New Issue
Block a user