Switching to use 'unpack' for indentation grouping.

This commit is contained in:
Bruce Hill 2018-07-13 09:56:12 -07:00
parent 295a25a3ed
commit 84c0058e69
3 changed files with 4 additions and 42 deletions

View File

@ -45,12 +45,11 @@ noindex_inline_expression:
) )
inline_expression: index_chain / noindex_inline_expression inline_expression: index_chain / noindex_inline_expression
indented_expression: indented_expression:
indented_text / indented_nomsu / indented_list / indented_dict / {| indented_text / indented_nomsu / indented_list / indented_dict / ({|
("(..)" / ":")? nl_indent (comment nl_nodent)* ("(..)" / ":")? nl_indent (comment nl_nodent)*
(block / action / expression) (block / action / expression)
(!! [^%nl]+ -> "Unexpected character while parsing indented expression" !!)? (!! [^%nl]+ -> "Unexpected character while parsing indented expression" !!)?
{:is_halfblock: ''->'yep' :} |} -> unpack)
|}
expression: expression:
inline_expression inline_expression
/ (":" %ws* / (":" %ws*

View File

@ -26,6 +26,7 @@ do
_with_0.nl = P("\r") ^ -1 * P("\n") _with_0.nl = P("\r") ^ -1 * P("\n")
_with_0.ws = S(" \t") _with_0.ws = S(" \t")
_with_0.tonumber = tonumber _with_0.tonumber = tonumber
_with_0.unpack = unpack or table.unpack
local string_escapes = { local string_escapes = {
n = "\n", n = "\n",
t = "\t", t = "\t",
@ -91,34 +92,6 @@ setmetatable(NOMSU_DEFS, {
value.source = Source(_with_0.filename, _with_0.start + start - 1, _with_0.start + stop - 1) value.source = Source(_with_0.filename, _with_0.start + start - 1, _with_0.start + stop - 1)
end end
end end
while true do
local found = false
for i = #value, 1, -1 do
local _continue_0 = false
repeat
if not (type(value[i]) == 'table') then
_continue_0 = true
break
end
if value[i].is_halfblock then
found = true
local hb = remove(value, i)
for _index_0 = 1, #hb do
local v = hb[_index_0]
insert(value, i, v)
i = i + 1
end
end
_continue_0 = true
until true
if not _continue_0 then
break
end
end
if not (found) then
break
end
end
local comments = { } local comments = { }
for i = #value, 1, -1 do for i = #value, 1, -1 do
local _continue_0 = false local _continue_0 = false

View File

@ -14,6 +14,7 @@ NOMSU_DEFS = with {}
.nl = P("\r")^-1 * P("\n") .nl = P("\r")^-1 * P("\n")
.ws = S(" \t") .ws = S(" \t")
.tonumber = tonumber .tonumber = tonumber
.unpack = unpack or table.unpack
string_escapes = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r" string_escapes = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r"
digit, hex = R('09'), R('09','af','AF') digit, hex = R('09'), R('09','af','AF')
.escaped_char = (P("\\")*S("xX")*C(hex*hex)) / => string.char(tonumber(@, 16)) .escaped_char = (P("\\")*S("xX")*C(hex*hex)) / => string.char(tonumber(@, 16))
@ -58,17 +59,6 @@ setmetatable(NOMSU_DEFS, {__index:(key)=>
if userdata.source if userdata.source
with userdata.source with userdata.source
value.source = Source(.filename, .start + start-1, .start + stop-1) value.source = Source(.filename, .start + start-1, .start + stop-1)
while true
found = false
for i=#value,1,-1
continue unless type(value[i]) == 'table'
if value[i].is_halfblock
found = true
hb = remove(value, i)
for v in *hb
insert value, i, v
i += 1
break unless found
comments = {} comments = {}
for i=#value,1,-1 for i=#value,1,-1
continue unless type(value[i]) == 'table' continue unless type(value[i]) == 'table'