aboutsummaryrefslogtreecommitdiff
path: root/parser.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-01 15:05:58 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-01 15:07:10 -0800
commitb6d3cbd61cd08e39d20a569b7c5ece6bb25897dd (patch)
treeccf3930b7a2834ffad1a10a9d91f0042542dec34 /parser.moon
parent0760d4fb6495c4aa4f74038457acede5063f514a (diff)
Misc changes, including text indented interpolations are now indented
relative to the text, not the opening '("', code objects can now remove all free vars, the REPL uses global vars. Error API is changing a bit.
Diffstat (limited to 'parser.moon')
-rw-r--r--parser.moon7
1 files changed, 7 insertions, 0 deletions
diff --git a/parser.moon b/parser.moon
index 122b58c..3f36953 100644
--- a/parser.moon
+++ b/parser.moon
@@ -25,6 +25,13 @@ DEFS = with {}
.unpack = unpack or table.unpack
.nil = Cc(nil)
.userdata = Carg(1)
+ -- Always match and capture the indentation (spaces only) of the current line
+ -- i.e. the leading space of the chunk of non-newline characters leading up to s[i]
+ .indentation = lpeg.Cmt P(0),
+ (s, i)->
+ sub = string.sub
+ while i > 1 and sub(s,i-1,i-1) != '\n' do i -= 1
+ return true, (s\match("^ *", i))
.utf8_char = (
R("\194\223")*R("\128\191") +
R("\224\239")*R("\128\191")*R("\128\191") +