aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-14 14:52:28 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-14 14:53:03 -0700
commitc9ff0ff04b2d1922bcfe5b1106b9979c29b167a2 (patch)
tree76616ba5dddc1d4b11c88fa16460ae673e2969a0
parentd535dc57940f6c9558d3b588d53b44a87b2a8ed2 (diff)
Fixed up some edge cases with parsing and comments.
-rw-r--r--core/metaprogramming.nom4
-rw-r--r--nomsu.peg6
-rw-r--r--nomsu_compiler.lua12
-rw-r--r--nomsu_compiler.moon2
4 files changed, 14 insertions, 10 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 631a869..d445737 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -148,13 +148,15 @@ action [%var as lua identifier, %var as lua id]
elseif \%var.type == 'Var' then return string.as_lua_id(\%var[1])
elseif \%var.type == 'Action' then return "A"..string.as_lua_id(\%var.stub)
end
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compile [% is syntax tree] to
Lua value "AST.is_syntax_tree(\(% as lua expr))"
compile [% is %kind syntax tree] to
Lua value "AST.is_syntax_tree(\(% as lua expr), \(%kind as lua expr))"
-
+
compile [%tree with %t -> %replacement] to
Lua value ".."
\(%tree as lua expr):map(function(\(%t as lua expr))
diff --git a/nomsu.peg b/nomsu.peg
index 565e8b4..d06c1ff 100644
--- a/nomsu.peg
+++ b/nomsu.peg
@@ -4,7 +4,7 @@ file (File):
comment? blank_lines?
(chunk (nl_nodent chunk_delimeter nl_nodent chunk)*)?
blank_lines?
- (!! .+ -> "Parse error" !!)?
+ %ws* (!! .+ -> "Parse error" !!)?
nodent: =curr_indent !(" ")
indent: =curr_indent " "
@@ -45,7 +45,7 @@ indented_expression:
indented_text / indented_nomsu / indented_list / indented_dict / ({|
("(..)")? nl_indent
(block / action / expression) (nl_nodent comment)*
- (!! [^%nl]+ -> "Unexpected character while parsing indented expression" !!)?
+ (eol / (!! [^%nl]+ -> "Unexpected character while parsing indented expression" !!))
|} -> unpack)
expression:
inline_expression
@@ -121,7 +121,7 @@ inline_list (List):
(inline_list_item (%ws* ',' %ws* inline_list_item)* (%ws* ',')?)? %ws*
("]" / (","? (
(!! eol -> "Line ended before finding a closing ]-bracket" !!)
- /(!! [^%nl]+ -> "Unexpected character while parsing List" !!)?
+ /(!! [^%nl]+ -> "Unexpected character while parsing List" !!)
)))
indented_list (List):
"[..]" eol nl_indent
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 6dbe4c4..788d9a0 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -725,11 +725,13 @@ do
local _accum_0 = { }
local _len_0 = 1
for p, c in pairs(tree.comments or { }) do
- _accum_0[_len_0] = {
- comment = c,
- pos = p
- }
- _len_0 = _len_0 + 1
+ if tree.source.start <= p and p <= tree.source.stop then
+ _accum_0[_len_0] = {
+ comment = c,
+ pos = p
+ }
+ _len_0 = _len_0 + 1
+ end
end
comments = _accum_0
end
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 0b330c8..22fa54d 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -484,7 +484,7 @@ with NomsuCompiler
.tree_to_nomsu = (tree, options)=>
options or= {}
unless options.pop_comments
- comments = [{comment:c, pos:p} for p,c in pairs(tree.comments or {})]
+ comments = [{comment:c, pos:p} for p,c in pairs(tree.comments or {}) when tree.source.start <= p and p <= tree.source.stop]
table.sort comments, (a,b)-> a.pos < b.pos
comment_i = 1
options.pop_comments = (pos)->