From b6d3cbd61cd08e39d20a569b7c5ece6bb25897dd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 1 Jan 2019 15:05:58 -0800 Subject: 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. --- parser.moon | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'parser.moon') 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") + -- cgit v1.2.3