diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-14 14:41:17 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-14 14:41:32 -0700 |
| commit | d535dc57940f6c9558d3b588d53b44a87b2a8ed2 (patch) | |
| tree | f0c8ecfcc65d302bbbfa3a867f60a56f3263310c /parser.moon | |
| parent | 01a4f36398bfe66a7286a83fdd797c8b20541681 (diff) | |
Fixed up comment generation to old standards
Diffstat (limited to 'parser.moon')
| -rw-r--r-- | parser.moon | 15 |
1 files changed, 7 insertions, 8 deletions
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 |
