aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/operators.nom3
-rw-r--r--nomsu.lua4
-rwxr-xr-xnomsu.moon6
3 files changed, 7 insertions, 6 deletions
diff --git a/lib/operators.nom b/lib/operators.nom
index c15298f..17d7e34 100644
--- a/lib/operators.nom
+++ b/lib/operators.nom
@@ -13,10 +13,9 @@ compile [nop, pass] to code: ""
# Ternary operator
compile [%if_expr if %condition else %else_expr] to: ".."
- |(function(nomsu, vars)
- # TODO: fix compiler bug that breaks this code if comments immediately follow ".."
#.. Note: this uses a function instead of (condition and if_expr or else_expr)
because that breaks if %if_expr is falsey.
+ |(function(nomsu, vars)
| if \(%condition) then;
| return \(%if_expr);
| else;
diff --git a/nomsu.lua b/nomsu.lua
index 36eeeba..61d4195 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -128,12 +128,12 @@ local nomsu = [=[ file <- ({ {| shebang?
list_line <- (inline_list_item comma)* ((inline_list_item %ws? ",") / (functioncall / expression))
inline_list_item <- inline_functioncall / inline_expression
- block_comment <- "#.." [^%nl]* indent [^%nl]* (%nl ((%ws? (!. / &%nl)) / (!%dedented [^%nl]*)))*
+ block_comment <- "#.." [^%nl]* (%nl (%ws? &%nl))* %nl %indented [^%nl]+ (%nl ((%ws? (!. / &%nl)) / (!%dedented [^%nl]+)))*
line_comment <- "#" [^%nl]*
eol <- %ws? line_comment? (!. / &%nl)
ignored_line <- (%nodented (block_comment / line_comment)) / (%ws? (!. / &%nl))
- indent <- eol (%nl ignored_line)* %nl %indented
+ indent <- eol (%nl ignored_line)* %nl %indented ((block_comment/line_comment) (%nl ignored_line)* nodent)?
nodent <- eol (%nl ignored_line)* %nl %nodented
dedent <- eol (%nl ignored_line)* (((!.) &%dedented) / (&(%nl %dedented)))
tok_gap <- %ws / %prev_edge / &("[" / "\" / [.,:;{("#%'])
diff --git a/nomsu.moon b/nomsu.moon
index e6afe7f..ccf3a3c 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -27,8 +27,10 @@ colored = setmetatable({}, {__index:(_,color)-> ((msg)-> colors[color]..msg..col
-- provide way to run precompiled nomsu -> lua code from nomsu
-- better scoping?
-- better error reporting
+-- fix propagation of filename for error reporting
-- add line numbers of function calls
-- type checking?
+-- Fix compiler bug that breaks when file ends with a block comment
lpeg.setmaxstack 10000 -- whoa
{:P,:V,:S,:Cg,:C,:Cp,:B,:Cmt} = lpeg
@@ -130,12 +132,12 @@ nomsu = [=[
list_line <- (inline_list_item comma)* ((inline_list_item %ws? ",") / (functioncall / expression))
inline_list_item <- inline_functioncall / inline_expression
- block_comment <- "#.." [^%nl]* indent [^%nl]* (%nl ((%ws? (!. / &%nl)) / (!%dedented [^%nl]*)))*
+ block_comment <- "#.." [^%nl]* (%nl (%ws? &%nl))* %nl %indented [^%nl]+ (%nl ((%ws? (!. / &%nl)) / (!%dedented [^%nl]+)))*
line_comment <- "#" [^%nl]*
eol <- %ws? line_comment? (!. / &%nl)
ignored_line <- (%nodented (block_comment / line_comment)) / (%ws? (!. / &%nl))
- indent <- eol (%nl ignored_line)* %nl %indented
+ indent <- eol (%nl ignored_line)* %nl %indented ((block_comment/line_comment) (%nl ignored_line)* nodent)?
nodent <- eol (%nl ignored_line)* %nl %nodented
dedent <- eol (%nl ignored_line)* (((!.) &%dedented) / (&(%nl %dedented)))
tok_gap <- %ws / %prev_edge / &("[" / "\" / [.,:;{("#%'])