Finally fixed the bullshit way that string literals were converted to lua.
This commit is contained in:
parent
c7994cf720
commit
ca5896b7bd
@ -16,13 +16,22 @@ lua> ".."
|
|||||||
rule [escaped parse %shorthand as %longhand] =:
|
rule [escaped parse %shorthand as %longhand] =:
|
||||||
lua> ".."
|
lua> ".."
|
||||||
|local aliases = nomsu:get_stubs(nomsu:typecheck(vars, "shorthand", "List").value);
|
|local aliases = nomsu:get_stubs(nomsu:typecheck(vars, "shorthand", "List").value);
|
||||||
|if #vars.longhand.value ~= 1 then;
|
|local template = nomsu:typecheck(vars, "longhand", "Thunk").value;
|
||||||
| nomsu:error("Expected only 1 line to parse to, but got "..tostring(#vars.longhand.value));
|
|
||||||
|end;
|
|
||||||
|local template = nomsu:typecheck(vars, "longhand", "Thunk").value[1];
|
|
||||||
|local function parsing_as(nomsu, vars)
|
|local function parsing_as(nomsu, vars)
|
||||||
| local replacement = nomsu:replaced_vars(template, vars);
|
# Single expression/statement
|
||||||
| return nomsu:tree_to_lua(replacement);
|
| if #template == 1 then;
|
||||||
|
| local replacement = nomsu:replaced_vars(template[1], vars);
|
||||||
|
| return nomsu:tree_to_lua(replacement);
|
||||||
|
| end
|
||||||
|
# Multiple statements
|
||||||
|
| local lua_bits = {};
|
||||||
|
| for _,bit in ipairs(template) do;
|
||||||
|
| bit = nomsu:replaced_vars(bit, vars);
|
||||||
|
| local expr, statement = nomsu:tree_to_lua(bit);
|
||||||
|
| if statement then; table.insert(lua_bits, statement); end;
|
||||||
|
| if expr then; table.insert(lua_bits, "ret = "..expr..";"); end;
|
||||||
|
| end;
|
||||||
|
| return nil, table.concat(lua_bits, "\\n");
|
||||||
|end;
|
|end;
|
||||||
|nomsu:defmacro(aliases, parsing_as, template.src);
|
|nomsu:defmacro(aliases, parsing_as, template.src);
|
||||||
escaped parse \[parse %shorthand as %longhand] as \: escaped parse \%shorthand as \%longhand
|
escaped parse \[parse %shorthand as %longhand] as \: escaped parse \%shorthand as \%longhand
|
||||||
@ -56,10 +65,10 @@ compile [repr %obj] to:
|
|||||||
compile [type %obj, type of %obj] to:
|
compile [type %obj, type of %obj] to:
|
||||||
"type(\(%obj as lua))"
|
"type(\(%obj as lua))"
|
||||||
|
|
||||||
parse [lua do> %block] as: lua> ".."
|
parse [lua do> %block] as:
|
||||||
|do;
|
lua> "do;"
|
||||||
| \(%block)
|
lua> %block
|
||||||
|end;
|
lua> "end;"
|
||||||
rule [%tree as lua statement] =:
|
rule [%tree as lua statement] =:
|
||||||
lua do> ".."
|
lua do> ".."
|
||||||
|local _,statement = nomsu:tree_to_lua(\(%tree));
|
|local _,statement = nomsu:tree_to_lua(\(%tree));
|
||||||
|
22
nomsu.moon
22
nomsu.moon
@ -600,18 +600,28 @@ end)]])\format(concat(lua_bits, "\n"))
|
|||||||
|
|
||||||
initialize_core: =>
|
initialize_core: =>
|
||||||
-- Sets up some core functionality
|
-- Sets up some core functionality
|
||||||
|
nomsu_string_as_lua = (code)=>
|
||||||
|
concat_parts = {}
|
||||||
|
for bit in *code.value
|
||||||
|
if type(bit) == "string"
|
||||||
|
insert concat_parts, bit
|
||||||
|
else
|
||||||
|
expr, statement = @tree_to_lua bit
|
||||||
|
if statement
|
||||||
|
@error "Cannot use [[#{bit.src}]] as a string interpolation value, since it's not an expression."
|
||||||
|
insert concat_parts, expr
|
||||||
|
return concat(concat_parts)
|
||||||
|
|
||||||
-- Uses named local functions to help out callstack readability
|
-- Uses named local functions to help out callstack readability
|
||||||
lua_code = (vars)=>
|
lua_code = (vars)=>
|
||||||
inner_vars = setmetatable({}, {__index:(_,key)-> "vars[#{repr(key)}]"})
|
lua = nomsu_string_as_lua(@, vars.code)
|
||||||
lua = @tree_to_value(vars.code, inner_vars)
|
|
||||||
return nil, lua
|
return nil, lua
|
||||||
@defmacro "lua > %code", lua_code
|
@defmacro "lua> %code", lua_code
|
||||||
|
|
||||||
lua_value = (vars)=>
|
lua_value = (vars)=>
|
||||||
inner_vars = setmetatable({}, {__index:(_,key)-> "vars[#{repr(key)}]"})
|
lua = nomsu_string_as_lua(@, vars.code)
|
||||||
lua = @tree_to_value(vars.code, inner_vars)
|
|
||||||
return lua, nil
|
return lua, nil
|
||||||
@defmacro "= lua %code", lua_value
|
@defmacro "=lua %code", lua_value
|
||||||
|
|
||||||
run_file = (vars)=>
|
run_file = (vars)=>
|
||||||
if vars.filename\match(".*%.lua")
|
if vars.filename\match(".*%.lua")
|
||||||
|
Loading…
Reference in New Issue
Block a user