From d535dc57940f6c9558d3b588d53b44a87b2a8ed2 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 14 Jul 2018 14:41:17 -0700 Subject: Fixed up comment generation to old standards --- parser.moon | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'parser.moon') diff --git a/parser.moon b/parser.moon index 78aa042..96f6b6c 100644 --- a/parser.moon +++ b/parser.moon @@ -14,6 +14,7 @@ NOMSU_DEFS = with {} .nl = P("\r")^-1 * P("\n") .ws = S(" \t") .tonumber = tonumber + .table = -> {} .unpack = unpack or table.unpack string_escapes = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r" digit, hex = R('09'), R('09','af','AF') @@ -29,6 +30,10 @@ NOMSU_DEFS = with {} .userdata = Carg(1) + .add_comment = (src,end_pos,start_pos,comment,userdata)-> + userdata.comments[start_pos] = comment + return true + .error = (src,end_pos,start_pos,err_msg,userdata)-> seen_errors = userdata.errors if seen_errors[start_pos] @@ -59,14 +64,8 @@ setmetatable(NOMSU_DEFS, {__index:(key)=> if userdata.source with userdata.source value.source = Source(.filename, .start + start-1, .start + stop-1) - comments = {} - for i=#value,1,-1 - continue unless type(value[i]) == 'table' - if value[i].type == "Comment" - insert comments, remove(value, i) - if #comments > 0 - value.comments = comments setmetatable(value, AST[key]) + value.comments = userdata.comments if value.__init then value\__init! return value @@ -105,7 +104,7 @@ Parser.parse = (nomsu_code, source=nil)-> source or= nomsu_code.source nomsu_code = tostring(nomsu_code) userdata = { - indent: "", errors: {}, :source + errors: {}, :source, comments: {} } tree = NOMSU_PATTERN\match(nomsu_code, nil, userdata) unless tree -- cgit v1.2.3