aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nomsu.4.peg3
-rw-r--r--nomsu_compiler.lua34
-rw-r--r--nomsu_compiler.moon17
-rw-r--r--string2.lua3
-rw-r--r--string2.moon1
5 files changed, 31 insertions, 27 deletions
diff --git a/nomsu.4.peg b/nomsu.4.peg
index 8d8296e..b0ce3da 100644
--- a/nomsu.4.peg
+++ b/nomsu.4.peg
@@ -147,7 +147,7 @@ indented_text (Text):
cool_quote:
- '"' !(%nl+ !(=curr_indent))
+ '"' &([^%nl] / %nl+ =curr_indent)
cool_indented_text (Text):
'"'
_inline_text*
@@ -155,6 +155,7 @@ cool_indented_text (Text):
/ disallowed_interpolation? {%nl+} {:curr_indent: indent :})
(indented_cool_plain_text / text_interpolation / {~ %nl+ (=curr_indent -> "") ~})*
('"' eol / missing_quote_err)
+ {:curr_indent: %nil :}
indented_cool_plain_text (Text):
{~ ((("\" blank_lines =curr_indent "..") -> "") / (!text_interpolation ((!("\n") escaped_char) / ('\\' -> '\') / '\')) / (cool_quote / [^%nl"\])+)+
(%nl+ (=curr_indent -> ""))* ~}
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index b71eab0..c7b7dc6 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -184,13 +184,7 @@ do
local find_errors
find_errors = function(t)
if t.type == "Error" then
- return coroutine.yield(pretty_error({
- error = t.error,
- hint = t.hint,
- source = t:get_source_code(),
- start = t.source.start,
- stop = t.source.stop
- }))
+ return coroutine.yield(t)
else
for k, v in pairs(t) do
local _continue_0 = false
@@ -234,7 +228,24 @@ do
table.insert(errs, "\027[31;1m +" .. tostring(num_errs - #errs) .. " additional errors...\027[0m\n")
end
if #errs > 0 then
- error(table.concat(errs, '\n\n'), 0)
+ local err_strings
+ do
+ local _accum_0 = { }
+ local _len_0 = 1
+ for _index_0 = 1, #errs do
+ local t = errs[_index_0]
+ _accum_0[_len_0] = pretty_error({
+ error = t.error,
+ hint = t.hint,
+ source = t:get_source_code(),
+ start = t.source.start,
+ stop = t.source.stop
+ })
+ _len_0 = _len_0 + 1
+ end
+ err_strings = _accum_0
+ end
+ error(table.concat(err_strings, '\n\n'), 0)
end
return tree
end
@@ -1305,7 +1316,7 @@ do
end
end
nomsu:append(interp_nomsu)
- if interp_nomsu:is_multiline() and i < #tree then
+ if interp_nomsu:is_multiline() then
nomsu:append("\n..")
end
end
@@ -1313,10 +1324,7 @@ do
end
local nomsu = NomsuCode(tree.source)
add_text(nomsu, tree)
- if nomsu:is_multiline() and nomsu:match("\n$") then
- nomsu:append('\\("")')
- end
- return NomsuCode(tree.source, '".."\n ', nomsu)
+ return NomsuCode(tree.source, '"\\\n ..', nomsu, '"')
elseif "List" == _exp_0 or "Dict" == _exp_0 then
assert(#tree > 0)
local nomsu = NomsuCode(tree.source, pop_comments(tree[1].source.start))
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 9fcf796..b5168a5 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -105,10 +105,7 @@ with NomsuCompiler
pretty_error = require("pretty_errors")
find_errors = (t)->
if t.type == "Error"
- coroutine.yield pretty_error{
- error:t.error, hint:t.hint, source:t\get_source_code!
- start:t.source.start, stop:t.source.stop
- }
+ coroutine.yield t
else
for k,v in pairs(t)
continue unless AST.is_syntax_tree(v)
@@ -120,7 +117,11 @@ with NomsuCompiler
errs = [errs[i] for i=1,3]
table.insert(errs, "\027[31;1m +#{num_errs-#errs} additional errors...\027[0m\n")
if #errs > 0
- error(table.concat(errs, '\n\n'), 0)
+ err_strings = [pretty_error{
+ error:t.error, hint:t.hint, source:t\get_source_code!
+ start:t.source.start, stop:t.source.stop
+ } for t in *errs]
+ error(table.concat(err_strings, '\n\n'), 0)
return tree
.can_optimize = -> false
@@ -833,13 +834,11 @@ with NomsuCompiler
elseif bit.type != "List" and bit.type != "Dict"
interp_nomsu\parenthesize!
nomsu\append interp_nomsu
- if interp_nomsu\is_multiline! and i < #tree
+ if interp_nomsu\is_multiline!
nomsu\append "\n.."
nomsu = NomsuCode(tree.source)
add_text(nomsu, tree)
- if nomsu\is_multiline! and nomsu\match("\n$")
- nomsu\append '\\("")' -- Need to specify where the text ends
- return NomsuCode(tree.source, '".."\n ', nomsu)
+ return NomsuCode(tree.source, '"\\\n ..', nomsu, '"')
when "List", "Dict"
assert #tree > 0
diff --git a/string2.lua b/string2.lua
index 80883d9..fe33bb9 100644
--- a/string2.lua
+++ b/string2.lua
@@ -67,9 +67,6 @@ local string2 = {
end,
line_at = function(self, pos)
assert(type(pos) == 'number', "Invalid string position")
- if pos < 1 or pos > #self then
- return
- end
for i, line, start, stop in isplit(self, '\n') do
if stop + 1 >= pos then
return line, i, (pos - start + 1)
diff --git a/string2.moon b/string2.moon
index 2273cff..4e62e92 100644
--- a/string2.moon
+++ b/string2.moon
@@ -24,7 +24,6 @@ string2 = {
line_at: (pos)=>
assert(type(pos) == 'number', "Invalid string position")
- return if pos < 1 or pos > #@
for i, line, start, stop in isplit(@, '\n')
if stop+1 >= pos
return line, i, (pos-start+1)