Fixed up some edge cases with parsing and comments.

This commit is contained in:
Bruce Hill 2018-07-14 14:52:28 -07:00
parent d535dc5794
commit c9ff0ff04b
4 changed files with 14 additions and 10 deletions

View File

@ -149,6 +149,8 @@ action [%var as lua identifier, %var as lua id]
elseif \%var.type == 'Action' then return "A"..string.as_lua_id(\%var.stub) elseif \%var.type == 'Action' then return "A"..string.as_lua_id(\%var.stub)
end end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compile [% is syntax tree] to compile [% is syntax tree] to
Lua value "AST.is_syntax_tree(\(% as lua expr))" Lua value "AST.is_syntax_tree(\(% as lua expr))"

View File

@ -4,7 +4,7 @@ file (File):
comment? blank_lines? comment? blank_lines?
(chunk (nl_nodent chunk_delimeter nl_nodent chunk)*)? (chunk (nl_nodent chunk_delimeter nl_nodent chunk)*)?
blank_lines? blank_lines?
(!! .+ -> "Parse error" !!)? %ws* (!! .+ -> "Parse error" !!)?
nodent: =curr_indent !(" ") nodent: =curr_indent !(" ")
indent: =curr_indent " " indent: =curr_indent " "
@ -45,7 +45,7 @@ indented_expression:
indented_text / indented_nomsu / indented_list / indented_dict / ({| indented_text / indented_nomsu / indented_list / indented_dict / ({|
("(..)")? nl_indent ("(..)")? nl_indent
(block / action / expression) (nl_nodent comment)* (block / action / expression) (nl_nodent comment)*
(!! [^%nl]+ -> "Unexpected character while parsing indented expression" !!)? (eol / (!! [^%nl]+ -> "Unexpected character while parsing indented expression" !!))
|} -> unpack) |} -> unpack)
expression: expression:
inline_expression inline_expression
@ -121,7 +121,7 @@ inline_list (List):
(inline_list_item (%ws* ',' %ws* inline_list_item)* (%ws* ',')?)? %ws* (inline_list_item (%ws* ',' %ws* inline_list_item)* (%ws* ',')?)? %ws*
("]" / (","? ( ("]" / (","? (
(!! eol -> "Line ended before finding a closing ]-bracket" !!) (!! eol -> "Line ended before finding a closing ]-bracket" !!)
/(!! [^%nl]+ -> "Unexpected character while parsing List" !!)? /(!! [^%nl]+ -> "Unexpected character while parsing List" !!)
))) )))
indented_list (List): indented_list (List):
"[..]" eol nl_indent "[..]" eol nl_indent

View File

@ -725,11 +725,13 @@ do
local _accum_0 = { } local _accum_0 = { }
local _len_0 = 1 local _len_0 = 1
for p, c in pairs(tree.comments or { }) do for p, c in pairs(tree.comments or { }) do
_accum_0[_len_0] = { if tree.source.start <= p and p <= tree.source.stop then
comment = c, _accum_0[_len_0] = {
pos = p comment = c,
} pos = p
_len_0 = _len_0 + 1 }
_len_0 = _len_0 + 1
end
end end
comments = _accum_0 comments = _accum_0
end end

View File

@ -484,7 +484,7 @@ with NomsuCompiler
.tree_to_nomsu = (tree, options)=> .tree_to_nomsu = (tree, options)=>
options or= {} options or= {}
unless options.pop_comments 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 table.sort comments, (a,b)-> a.pos < b.pos
comment_i = 1 comment_i = 1
options.pop_comments = (pos)-> options.pop_comments = (pos)->