From b0904c170cae82d2b0947f058e7192bce07f0593 Mon Sep 17 00:00:00 2001 From: nymphium Date: Thu, 13 Aug 2015 18:02:30 +0900 Subject: [PATCH 1/9] added Lua5.3's new operators --- moonscript/compile/value.lua | 3 +++ moonscript/compile/value.moon | 3 +++ moonscript/parse.lua | 6 +++--- moonscript/parse.moon | 5 +++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/moonscript/compile/value.lua b/moonscript/compile/value.lua index 8f8e8f2..c71a45b 100644 --- a/moonscript/compile/value.lua +++ b/moonscript/compile/value.lua @@ -276,6 +276,9 @@ return { number = function(self, node) return node[2] end, + bitnot = function(self, node) + return self:line("~", self:value(node[2])) + end, length = function(self, node) return self:line("#", self:value(node[2])) end, diff --git a/moonscript/compile/value.moon b/moonscript/compile/value.moon index 515fed8..d1c9fae 100644 --- a/moonscript/compile/value.moon +++ b/moonscript/compile/value.moon @@ -166,6 +166,9 @@ string_chars = { number: (node) => node[2] + bitnot: (node) => + @line "~", @value node[2] + length: (node) => @line "#", @value node[2] diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 1ec4f11..920668b 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -145,12 +145,12 @@ local build_grammar = wrap_env(debug_grammar, function(root) CompClause = CompFor + CompForEach + key("when") * Exp / mark("when"), Assign = sym("=") * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark("assign"), Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=")) / trim) * Exp / mark("update"), - CharOperators = Space * C(S("+-*/%^><")), - WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op(".."), + CharOperators = Space * C(S("+-*/%^><|&")), + WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op("..") + op("<<") + op(">>") + op("//"), BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0, Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName, Exp = Ct(Value * (BinaryOperator * Value) ^ 0) / flatten_or_mark("exp"), - SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num, + SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + sym("~") * Exp / mark("bitnot") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num, ChainValue = StringChain + ((Chain + DotChain + Callable) * Ct(InvokeArgs ^ -1)) / flatten_func, Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue), SliceValue = SimpleValue + ChainValue, diff --git a/moonscript/parse.moon b/moonscript/parse.moon index 0dd07a0..ce4b221 100644 --- a/moonscript/parse.moon +++ b/moonscript/parse.moon @@ -179,8 +179,8 @@ build_grammar = wrap_env debug_grammar, (root) -> Assign: sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign" Update: ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=") / trim) * Exp / mark"update" - CharOperators: Space * C(S"+-*/%^><") - WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + CharOperators: Space * C(S"+-*/%^><|&") + WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<<" + op">>" + op"//" BinaryOperator: (WordOperators + CharOperators) * SpaceBreak^0 Assignable: Cmt(DotChain + Chain, check_assignable) + Name + SelfName @@ -195,6 +195,7 @@ build_grammar = wrap_env debug_grammar, (root) -> Cmt(Do, check_do) + sym"-" * -SomeSpace * Exp / mark"minus" + sym"#" * Exp / mark"length" + + sym"~" * Exp / mark"bitnot" + key"not" * Exp / mark"not" + TblComprehension + TableLit + From db523926d3ec9ceddc7eaa4e0d72ec72f41fb7e7 Mon Sep 17 00:00:00 2001 From: nymphium Date: Thu, 13 Aug 2015 18:06:03 +0900 Subject: [PATCH 2/9] make it choice /usr/bin/lua, not lua5.1 --- Makefile | 4 ++-- moon/init.moon | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a374fb3..c620a2e 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,9 @@ global: sudo luarocks make moonscript-dev-1.rockspec compile: - lua5.1 bin/moonc moon/ moonscript/ + lua bin/moonc moon/ moonscript/ echo "#!/usr/bin/env lua" > bin/moon - lua5.1 bin/moonc -p bin/moon.moon >> bin/moon + lua bin/moonc -p bin/moon.moon >> bin/moon echo "-- vim: set filetype=lua:" >> bin/moon watch: diff --git a/moon/init.moon b/moon/init.moon index ef07bba..5817bc5 100644 --- a/moon/init.moon +++ b/moon/init.moon @@ -41,7 +41,7 @@ debug = setmetatable { -- run a function with scope injected before its function environment run_with_scope = (fn, scope, ...) -> - old_env = getfenv fn + old_env = util.getfenv fn env = setmetatable {}, { __index: (name) => val = scope[name] @@ -50,7 +50,7 @@ run_with_scope = (fn, scope, ...) -> else old_env[name] } - setfenv fn, env + util.setfenv fn, env fn ... -- wrap obj such that calls to methods do not need a reference to self From 0d330c8416614c3337bfb9c321f1482ab5ab8093 Mon Sep 17 00:00:00 2001 From: nymphium Date: Fri, 21 Aug 2015 21:24:31 +0900 Subject: [PATCH 3/9] LUA=lua5.1 as default, and detect luarocks and LUA_{C,}PATH --- Makefile | 25 ++++++++++++++++++++----- moonscript/parse.moon | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c620a2e..d4fb094 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,18 @@ +LUA ?= lua5.1 +LUAROCKS ?= luarocks + +ifneq ($(LUA),lua) + LUA_VERSION = $(shell echo $(LUA) | sed -e "s/lua\(.*\)/\1/") + LUAROCKS = luarocks-$(LUA_VERSION) + LUA_PATH_MAKE = $(shell echo "${LUA_PATH}" | sed -e "s/[0-9]\.[0-9]/$(LUA_VERSION)/g") + LUA_CPATH_MAKE = $(shell echo "${LUA_CPATH}" | sed -e "s/[0-9]\.[0-9]/$(LUA_VERSION)/g") +endif + +ifeq ($(LUA),luajit) + LUAROCKS = luarocks-5.1 +endif + + .PHONY: test local compile watch lint test_safe test: @@ -7,15 +22,15 @@ test_safe: busted -p "_spec.lua$$" local: compile - luarocks make --local moonscript-dev-1.rockspec + LUA_PATH=$(LUA_PATH_MAKE) LUA_CPATH=$(LUA_CPATH_MAKE) $(LUAROCKS) make --local moonscript-dev-1.rockspec global: - sudo luarocks make moonscript-dev-1.rockspec + sudo LUA_PATH=$(LUA_PATH_MAKE) LUA_CPATH=$(LUA_CPATH_MAKE) $(LUAROCKS) make moonscript-dev-1.rockspec -compile: - lua bin/moonc moon/ moonscript/ +compile: init + LUA_PATH=$(LUA_PATH_MAKE) LUA_CPATH=$(LUA_CPATH_MAKE) $(LUA) bin/moonc moon/ moonscript/ echo "#!/usr/bin/env lua" > bin/moon - lua bin/moonc -p bin/moon.moon >> bin/moon + $(LUA) bin/moonc -p bin/moon.moon >> bin/moon echo "-- vim: set filetype=lua:" >> bin/moon watch: diff --git a/moonscript/parse.moon b/moonscript/parse.moon index 0dd07a0..24581a5 100644 --- a/moonscript/parse.moon +++ b/moonscript/parse.moon @@ -291,7 +291,7 @@ build_grammar = wrap_env debug_grammar, (root) -> op"*" + op"^" + Ct(NameList) * (sym"=" * Ct(ExpListLow))^-1) / mark"export" - KeyValue: (sym":" * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym"[" * Exp * sym"]" + DoubleString + SingleString) * symx":" * (Exp + TableBlock + SpaceBreak^1 * Exp)) + KeyValue: (sym":" * -SomeSpace * Name * lpeg.Cp!) / self_assign + Ct((KeyName + sym"[" * Exp * sym"]" + DoubleString + SingleString) * symx":" * (Exp + TableBlock + SpaceBreak^1 * Exp)) KeyValueList: KeyValue * (sym"," * KeyValue)^0 KeyValueLine: CheckIndent * KeyValueList * sym","^-1 From a569774536a9e010ef50d7ab424a480b1fc51a46 Mon Sep 17 00:00:00 2001 From: nymphium Date: Wed, 9 Dec 2015 03:46:25 +0900 Subject: [PATCH 4/9] fix #191 benchmark failed --- moonscript/cmd/moonc.lua | 2 +- moonscript/cmd/moonc.moon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/moonscript/cmd/moonc.lua b/moonscript/cmd/moonc.lua index eae8638..5460099 100644 --- a/moonscript/cmd/moonc.lua +++ b/moonscript/cmd/moonc.lua @@ -102,7 +102,7 @@ compile_file_text = function(text, opts) "Compile time\t" .. format_time(compile_time), "" }, "\n")) - return nil + return true end return code end diff --git a/moonscript/cmd/moonc.moon b/moonscript/cmd/moonc.moon index a680eaa..b2e92e6 100644 --- a/moonscript/cmd/moonc.moon +++ b/moonscript/cmd/moonc.moon @@ -105,7 +105,7 @@ compile_file_text = (text, opts={}) -> "Compile time\t" .. format_time(compile_time), "" }, "\n" - return nil + return true code From 47d94d5bb64aebd11b15c15f4e068cbd21992e33 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sun, 27 Dec 2015 21:02:57 -0800 Subject: [PATCH 5/9] update preamble syntax --- docs/api.md | 11 ++++++----- docs/command_line.md | 11 ++++++----- docs/reference.md | 11 ++++++----- docs/standard_lib.md | 11 ++++++----- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/docs/api.md b/docs/api.md index 367891a..a0aa7f5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,8 +1,9 @@ -target: reference/api -template: reference -title: Compiler API -short_name: api --- +{ + target: "reference/api" + template: "reference" + title: "Compiler API" + short_name: "api" +} # MoonScript Compiler API diff --git a/docs/command_line.md b/docs/command_line.md index aac3e7b..047a0dd 100644 --- a/docs/command_line.md +++ b/docs/command_line.md @@ -1,8 +1,9 @@ -target: reference/command_line -template: reference -title: Command Line Tools -short_name: command_line --- +{ + target: "reference/command_line" + template: "reference" + title: "Command Line Tools" + short_name: "command_line" +} # Command Line Tools diff --git a/docs/reference.md b/docs/reference.md index 3a8e987..960930a 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1,8 +1,9 @@ -target: reference/index -template: reference -title: Language Guide -short_name: lang --- +{ + target: "reference/index" + template: "reference" + title: "Language Guide" + short_name: "lang" +} MoonScript is a programming language that compiles to [Lua](http://www.lua.org). This guide expects the reader to have basic diff --git a/docs/standard_lib.md b/docs/standard_lib.md index 42cb7d4..3a86a7b 100644 --- a/docs/standard_lib.md +++ b/docs/standard_lib.md @@ -1,8 +1,9 @@ -target: reference/standard_lib -template: reference -title: Standard Library -short_name: stdlib --- +{ + target: "reference/standard_lib" + template: "reference" + title: "Standard Library" + short_name: "stdlib" +} The MoonScript installation comes with a small kernel of functions that can be used to perform various common things. From bbf5af654f63f052630ac700bba4f3d266feee90 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sun, 27 Dec 2015 22:14:55 -0800 Subject: [PATCH 6/9] some style changes --- bin/moonc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bin/moonc b/bin/moonc index 2d70767..68a0284 100755 --- a/bin/moonc +++ b/bin/moonc @@ -264,16 +264,17 @@ local function create_watcher(files) end end --- build function to check for lint or compile in watch -local check_compile_or_lint -if opts.l then - local lint = require "moonscript.cmd.lint" - check_compile_or_lint = lint.lint_file -else - check_compile_or_lint = compile_and_write -end if opts.w then + -- build function to check for lint or compile in watch + local handle_file + if opts.l then + local lint = require "moonscript.cmd.lint" + handle_file = lint.lint_file + else + handle_file = compile_and_write + end + local watcher = create_watcher(files) -- catches interrupt error for ctl-c local protected = function() @@ -292,7 +293,7 @@ if opts.w then target = opts.o end - local success, err = check_compile_or_lint(fname, target) + local success, err = handle_file(fname, target) if opts.l then if success then io.stderr:write(success .. "\n\n") @@ -313,9 +314,10 @@ if opts.w then io.stderr:write("\nQuitting...\n") elseif opts.l then + local lint = require "moonscript.cmd.lint" for _, tuple in pairs(files) do local fname = tuple[1] - local res, err = check_compile_or_lint(fname) + local res, err = lint.lint_file(fname) if res then io.stderr:write(res .. "\n\n") elseif err then From c5917c78b93fb7dfec5364cafd60ab66f7525d19 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sun, 27 Dec 2015 22:30:37 -0800 Subject: [PATCH 7/9] misc --- moonscript/parse.moon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonscript/parse.moon b/moonscript/parse.moon index 0c6bc82..556f81d 100644 --- a/moonscript/parse.moon +++ b/moonscript/parse.moon @@ -282,7 +282,7 @@ build_grammar = wrap_env debug_grammar, (root) -> op"*" + op"^" + Ct(NameList) * (sym"=" * Ct(ExpListLow))^-1) / mark"export" - KeyValue: (sym":" * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym"[" * Exp * sym"]" + DoubleString + SingleString) * symx":" * (Exp + TableBlock + SpaceBreak^1 * Exp)) + KeyValue: (sym":" * -SomeSpace * Name * lpeg.Cp!) / self_assign + Ct((KeyName + sym"[" * Exp * sym"]" + DoubleString + SingleString) * symx":" * (Exp + TableBlock + SpaceBreak^1 * Exp)) KeyValueList: KeyValue * (sym"," * KeyValue)^0 KeyValueLine: CheckIndent * KeyValueList * sym","^-1 From fc77603156f75682cb059e3e244d58ab3c550175 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sun, 27 Dec 2015 23:02:06 -0800 Subject: [PATCH 8/9] parser supports lulpeg, fixes #109 --- moonscript/parse.lua | 10 +++++----- moonscript/parse.moon | 14 ++++++-------- moonscript/parse/literals.lua | 7 ++++++- moonscript/parse/literals.moon | 6 +++++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 072e4ef..6e75c29 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -15,10 +15,10 @@ local wrap_env wrap_env = require("moonscript.parse.env").wrap_env local R, S, V, P, C, Ct, Cmt, Cg, Cb, Cc R, S, V, P, C, Ct, Cmt, Cg, Cb, Cc = lpeg.R, lpeg.S, lpeg.V, lpeg.P, lpeg.C, lpeg.Ct, lpeg.Cmt, lpeg.Cg, lpeg.Cb, lpeg.Cc -local White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, _Name +local White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, L, _Name do local _obj_0 = require("moonscript.parse.literals") - White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, _Name = _obj_0.White, _obj_0.Break, _obj_0.Stop, _obj_0.Comment, _obj_0.Space, _obj_0.SomeSpace, _obj_0.SpaceBreak, _obj_0.EmptyLine, _obj_0.AlphaNum, _obj_0.Num, _obj_0.Shebang, _obj_0.Name + White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, L, _Name = _obj_0.White, _obj_0.Break, _obj_0.Stop, _obj_0.Comment, _obj_0.Space, _obj_0.SomeSpace, _obj_0.SpaceBreak, _obj_0.EmptyLine, _obj_0.AlphaNum, _obj_0.Num, _obj_0.Shebang, _obj_0.L, _obj_0.Name end local SpaceName = Space * _Name Num = Space * (Num / function(v) @@ -110,10 +110,10 @@ local build_grammar = wrap_env(debug_grammar, function(root) File = Shebang ^ -1 * (Block + Ct("")), Block = Ct(Line * (Break ^ 1 * Line) ^ 0), CheckIndent = Cmt(Indent, check_indent), - Line = (CheckIndent * Statement + Space * #Stop), + Line = (CheckIndent * Statement + Space * L(Stop)), Statement = pos(Import + While + With + For + ForEach + Switch + Return + Local + Export + BreakLoop + Ct(ExpList) * (Update + Assign) ^ -1 / format_assign) * Space * ((key("if") * Exp * (key("else") * Exp) ^ -1 * Space / mark("if") + key("unless") * Exp / mark("unless") + CompInner / mark("comprehension")) * Space) ^ -1 / wrap_decorator, Body = Space ^ -1 * Break * EmptyLine ^ 0 * InBlock + Ct(Statement), - Advance = #Cmt(Indent, advance_indent), + Advance = L(Cmt(Indent, advance_indent)), PushIndent = Cmt(Indent, push_indent), PreventIndent = Cmt(Cc(-1), push_indent), PopIndent = Cmt("", pop_indent), @@ -170,7 +170,7 @@ local build_grammar = wrap_env(debug_grammar, function(root) ColonChainItem = symx("\\") * _Name / mark("colon"), ColonChain = ColonChainItem * (Invoke * ChainItems ^ -1) ^ -1, Slice = symx("[") * (SliceValue + Cc(1)) * sym(",") * (SliceValue + Cc("")) * (sym(",") * SliceValue) ^ -1 * sym("]") / mark("slice"), - Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + #P("[") * LuaString / wrap_func_arg, + Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + L(P("[")) * LuaString / wrap_func_arg, TableValue = KeyValue + Ct(Exp), TableLit = sym("{") * Ct(TableValueList ^ -1 * sym(",") ^ -1 * (SpaceBreak * TableLitLine * (sym(",") ^ -1 * SpaceBreak * TableLitLine) ^ 0 * sym(",") ^ -1) ^ -1) * White * sym("}") / mark("table"), TableValueList = TableValue * (sym(",") * TableValue) ^ 0, diff --git a/moonscript/parse.moon b/moonscript/parse.moon index c87cffa..87225a4 100644 --- a/moonscript/parse.moon +++ b/moonscript/parse.moon @@ -3,11 +3,10 @@ lpeg = require "lpeg" lpeg.setmaxstack 10000 -- whoa - err_msg = "Failed to parse:%s\n [%d] >> %s" import Stack from require "moonscript.data" -import trim, pos_to_line, get_line from require"moonscript.util" +import trim, pos_to_line, get_line from require "moonscript.util" import unpack from require "moonscript.util" import wrap_env from require "moonscript.parse.env" @@ -17,11 +16,10 @@ import wrap_env from require "moonscript.parse.env" { :White, :Break, :Stop, :Comment, :Space, :SomeSpace, :SpaceBreak, :EmptyLine, - :AlphaNum, :Num, :Shebang + :AlphaNum, :Num, :Shebang, :L Name: _Name } = require "moonscript.parse.literals" - SpaceName = Space * _Name Num = Space * (Num / (v) -> {"number", v}) @@ -110,7 +108,7 @@ build_grammar = wrap_env debug_grammar, (root) -> File: Shebang^-1 * (Block + Ct"") Block: Ct(Line * (Break^1 * Line)^0) CheckIndent: Cmt(Indent, check_indent), -- validates line is in correct indent - Line: (CheckIndent * Statement + Space * #Stop) + Line: (CheckIndent * Statement + Space * L(Stop)) Statement: pos( Import + While + With + For + ForEach + Switch + Return + @@ -123,9 +121,9 @@ build_grammar = wrap_env debug_grammar, (root) -> CompInner / mark"comprehension" ) * Space)^-1 / wrap_decorator - Body: Space^-1 * Break * EmptyLine^0 * InBlock + Ct(Statement), -- either a statement, or an indented block + Body: Space^-1 * Break * EmptyLine^0 * InBlock + Ct(Statement) -- either a statement, or an indented block - Advance: #Cmt(Indent, advance_indent), -- Advances the indent, gives back whitespace for CheckIndent + Advance: L Cmt(Indent, advance_indent) -- Advances the indent, gives back whitespace for CheckIndent PushIndent: Cmt(Indent, push_indent) PreventIndent: Cmt(Cc(-1), push_indent) PopIndent: Cmt("", pop_indent) @@ -252,7 +250,7 @@ build_grammar = wrap_env debug_grammar, (root) -> Invoke: FnArgs / mark"call" + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + - #P"[" * LuaString / wrap_func_arg + L(P"[") * LuaString / wrap_func_arg TableValue: KeyValue + Ct(Exp) diff --git a/moonscript/parse/literals.lua b/moonscript/parse/literals.lua index 61d6e2b..1ad5aeb 100644 --- a/moonscript/parse/literals.lua +++ b/moonscript/parse/literals.lua @@ -5,11 +5,15 @@ do local _obj_0 = require("lpeg") S, P, R, C = _obj_0.S, _obj_0.P, _obj_0.R, _obj_0.C end +local lpeg = require("lpeg") +local L = lpeg.luversion and lpeg.L or function(v) + return #v +end local White = S(" \t\r\n") ^ 0 local plain_space = S(" \t") ^ 0 local Break = P("\r") ^ -1 * P("\n") local Stop = Break + -1 -local Comment = P("--") * (1 - S("\r\n")) ^ 0 * #Stop +local Comment = P("--") * (1 - S("\r\n")) ^ 0 * L(Stop) local Space = plain_space * Comment ^ -1 local SomeSpace = S(" \t") ^ 1 * Comment ^ -1 local SpaceBreak = Space * Break @@ -19,6 +23,7 @@ local Name = C(R("az", "AZ", "__") * AlphaNum ^ 0) local Num = P("0x") * R("09", "af", "AF") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) ^ -1 + R("09") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) + (R("09") ^ 1 * (P(".") * R("09") ^ 1) ^ -1 + P(".") * R("09") ^ 1) * (S("eE") * P("-") ^ -1 * R("09") ^ 1) ^ -1 local Shebang = P("#!") * P(1 - Stop) ^ 0 return safe_module("moonscript.parse.literals", { + L = L, White = White, Break = Break, Stop = Stop, diff --git a/moonscript/parse/literals.moon b/moonscript/parse/literals.moon index 8f0d8cd..5a4980f 100644 --- a/moonscript/parse/literals.moon +++ b/moonscript/parse/literals.moon @@ -2,13 +2,16 @@ import safe_module from require "moonscript.util" import S, P, R, C from require "lpeg" +lpeg = require "lpeg" +L = lpeg.luversion and lpeg.L or (v) -> #v + White = S" \t\r\n"^0 plain_space = S" \t"^0 Break = P"\r"^-1 * P"\n" Stop = Break + -1 -Comment = P"--" * (1 - S"\r\n")^0 * #Stop +Comment = P"--" * (1 - S"\r\n")^0 * L(Stop) Space = plain_space * Comment^-1 SomeSpace = S" \t"^1 * Comment^-1 @@ -29,6 +32,7 @@ Num = P"0x" * R("09", "af", "AF")^1 * (S"uU"^-1 * S"lL"^2)^-1 + Shebang = P"#!" * P(1 - Stop)^0 safe_module "moonscript.parse.literals", { + :L :White, :Break, :Stop, :Comment, :Space, :SomeSpace, :SpaceBreak, :EmptyLine, :AlphaNum, :Name, :Num, :Shebang } From 1058593a3ee258296d976c10b82a26e0a449b37a Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Mon, 28 Dec 2015 02:12:50 -0800 Subject: [PATCH 9/9] remove scite extras, link to edit plugins fixes #198 --- README.md | 7 ++ extra/scintillua/README.md | 36 ------- extra/scintillua/lexers/moonscript.lua | 124 ------------------------ extra/scintillua/lexers/themes/moon.lua | 61 ------------ extra/scintillua/moonscript.properties | 11 --- 5 files changed, 7 insertions(+), 232 deletions(-) delete mode 100644 extra/scintillua/README.md delete mode 100644 extra/scintillua/lexers/moonscript.lua delete mode 100644 extra/scintillua/lexers/themes/moon.lua delete mode 100644 extra/scintillua/moonscript.properties diff --git a/README.md b/README.md index 871b86a..b282f75 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,13 @@ busted Writing specs is a bit more complicated. Check out [the spec writing guide](spec/README.md). + +## Editor Support + +* [Vim](https://github.com/leafo/moonscript-vim) +* [Textadept](https://github.com/leafo/moonscript-textadept) +* [Sublime/Textmate](https://github.com/leafo/moonscript-tmbundle) + ## License (MIT) Copyright (C) 2015 by Leaf Corcoran diff --git a/extra/scintillua/README.md b/extra/scintillua/README.md deleted file mode 100644 index ffeb980..0000000 --- a/extra/scintillua/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# MoonScript for [scintillua][1] - -MoonScript syntax file for [SciTE][2] written in Lua for [scintillua][1]. - -## Windows Binary - -Windows users can get a all-included package ready for MoonScript Development: - - - -If you already have a ScITE installation, or are on another platform, follow -the directions below. - -## Installation - -Install SciTE, then [install scintillua][1]. - -Put `moonscript.properties` in in your ScITE installation folder or user -properties folder. - -Copy the entire contents of the `lexers` folder in this repository into your -scintillua `lexers` folder. - -In your `lexers` folder edit `lpeg.properties`, add to the end: - - file.patterns.moonscript=*.moon - lexer.$(file.patterns.moonscript)=lpeg_moonscript - -Optionally, enable the Moon theme, find `lexer.peg.color.theme` in the same -file and change it to: - - lexer.lpeg.color.theme=moon - - [1]: http://foicica.com/scintillua/ "scintillua" - [2]: http://www.scintilla.org/SciTE.html "SciTE" - diff --git a/extra/scintillua/lexers/moonscript.lua b/extra/scintillua/lexers/moonscript.lua deleted file mode 100644 index 7a9e54b..0000000 --- a/extra/scintillua/lexers/moonscript.lua +++ /dev/null @@ -1,124 +0,0 @@ --- Copyright 2006-2011 Mitchell mitchellcaladbolg.net. See LICENSE. --- Moonscript lexer by leaf corcoran - -local l = lexer -local token, word_match = l.token, l.word_match -local P, S, R = lpeg.P, lpeg.S, lpeg.R - -local M = { _NAME = 'moonscript' } - --- Whitespace. -local ws = token(l.WHITESPACE, l.space^1) - -local longstring = #('[[' + ('[' * P('=')^0 * '[')) -local longstring = longstring * P(function(input, index) - local level = input:match('^%[(=*)%[', index) - if level then - local _, stop = input:find(']'..level..']', index, true) - return stop and stop + 1 or #input + 1 - end -end) - --- Comments. -local line_comment = '--' * l.nonnewline^0 -local block_comment = '--' * longstring -local comment = token(l.COMMENT, block_comment + line_comment) - --- Strings. -local sq_str = l.delimited_range("'", '\\', true) -local dq_str = l.delimited_range('"', '\\', true) -local string = token(l.STRING, sq_str + dq_str + longstring) - --- Numbers. -local number = token(l.NUMBER, l.float + l.integer) - --- Keywords. -local keyword = token(l.KEYWORD, word_match { - 'return', 'break', 'for', 'while', - 'if', 'else', 'elseif', 'then', 'export', - 'import', 'from', 'with', 'in', 'and', - 'or', 'not', 'class', 'extends', 'super', 'do', - 'using', 'switch', 'when', -}) - -local special = token("special", word_match { "true", "false", "nil" }) - --- Functions. -local builtin = token(l.FUNCTION, word_match({ - "_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load", - "loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require", - "select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall", - - "coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield", - - "debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable", - "debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable", - "debug.setupvalue","debug.traceback", - - "io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin", - "io.stdout","io.tmpfile","io.type","io.write", - - "math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg", - "math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max", - "math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh", - "math.sqrt","math.tan","math.tanh", - - "os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale", - "os.time","os.tmpname", - - "package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload", - "package.seeall", - - "string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub", - "string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper", - - "table.concat","table.insert","table.maxn","table.remove","table.sort" -}, "%.")) - --- Identifiers. -local identifier = token(l.IDENTIFIER, l.word) - -local fndef = token("fndef", P"->" + P"=>") -local err = token(l.ERROR, word_match { "function", "end" }) - --- Operators. -local symbol = token("symbol", S("(){}[]")) -local operator = token(l.OPERATOR, '~=' + S('+-*!\\/%^#=<>;:,.')) - --- self ref -local self_var = token("self_ref", "@" * l.word + "self") - -local proper_ident = token("proper_ident", R("AZ") * l.word) - -local tbl_key = token("tbl_key", l.word * ":" + ":" * l.word ) - -M._rules = { - { 'whitespace', ws }, - { 'error', err }, - { 'self', self_var }, - { 'special', special }, - { 'keyword', keyword }, - { 'builtin', builtin }, - { 'identifier', proper_ident + tbl_key + identifier }, - { 'comment', comment }, - { 'number', number }, - { 'string', string }, - { 'fndef', fndef }, - { 'symbol', symbol }, - { 'operator', operator }, - { 'any_char', l.any_char }, -} - -local style_special = { fore = l.colors.light_blue } -local style_fndef = { fore = l.colors.green } - -M._tokenstyles = { - { 'self_ref', style_special }, - { 'proper_ident', l.style_class }, - { 'fndef', style_fndef }, - { 'symbol', style_fndef }, - { 'special', style_special }, - { 'tbl_key', { fore = l.colors.red } }, -} - -return M diff --git a/extra/scintillua/lexers/themes/moon.lua b/extra/scintillua/lexers/themes/moon.lua deleted file mode 100644 index db8d7b2..0000000 --- a/extra/scintillua/lexers/themes/moon.lua +++ /dev/null @@ -1,61 +0,0 @@ --- Copyright 2006-2011 Mitchell mitchellcaladbolg.net. See LICENSE. --- moon lexer theme for Scintillua. - -module('lexer', package.seeall) - -colors = { - green = color('9F', 'FF', '98'), -- - blue = color('94', '95', 'FF'), -- - light_blue = color('98', 'D9', 'FF'), -- - red = color('FF', '98', '98'), -- - bright_red = color("F9", "26", "32"), -- - yellow = color('FF', 'E8', '98'), -- - teal = color('4D', '99', '99'), - white = color('FF', 'FF', 'FF'), -- - black = color('2E', '2E', '2E'), -- - grey = color('92', '92', '92'), -- - purple = color('CB', '98', 'FF'), -- - orange = color('FF', '92', '00'), -- - pink = color("ED", "4E", "78"), -- -} - -style_nothing = style { } -style_char = style { fore = colors.red, bold = true } -style_class = style { fore = colors.light_blue, bold = true } -style_comment = style { fore = colors.grey, } -style_constant = style { fore = colors.teal, bold = true } -style_definition = style { fore = colors.red, bold = true } -style_error = style { fore = colors.white, back = colors.bright_red, bold = true} -style_function = style { fore = colors.orange, bold = true } -style_keyword = style { fore = colors.purple, bold = true } -style_number = style { fore = colors.blue } -style_operator = style { fore = colors.red, bold = true } -style_string = style { fore = colors.yellow, bold = true } -style_preproc = style { fore = colors.light_blue } -style_tag = style { fore = colors.teal, bold = true } -style_type = style { fore = colors.green } -style_variable = style { fore = colors.white, italic = true } -style_embedded = style_tag..{ back = color('44', '44', '44') } -style_identifier = style_nothing - --- Default styles. -local font_face = '!Bitstream Vera Sans Mono' -local font_size = 12 -if WIN32 then - font_face = not GTK and 'Courier New' or '!Courier New' -elseif OSX then - font_face = '!Monaco' - font_size = 12 -end -style_default = style{ - font = font_face, - size = font_size, - fore = colors.white, - back = colors.black -} -style_line_number = style { fore = colors.black, back = colors.grey } -style_bracelight = style { fore = color('66', '99', 'FF'), bold = true } -style_bracebad = style { fore = color('FF', '66', '99'), bold = true } -style_controlchar = style_nothing -style_indentguide = style { fore = colors.grey, back = colors.white } -style_calltip = style { fore = colors.white, back = color('44', '44', '44') } diff --git a/extra/scintillua/moonscript.properties b/extra/scintillua/moonscript.properties deleted file mode 100644 index feff933..0000000 --- a/extra/scintillua/moonscript.properties +++ /dev/null @@ -1,11 +0,0 @@ - -file.patterns.moon=*.moon -shbang.moon=moon -filter.moon=MoonScript (moon)|$(file.patterns.moon)| - -command.compile.*.moon=moonc "$(FileNameExt)" -command.go.*.moon=moon "$(FileNameExt)" - -tabsize=2 -indent.size=2 -use.tabs=0 \ No newline at end of file