MoonScript is an actively used programming language created in 2011.

8Years Old 2,458Users 0Jobs
  • MoonScript ranks in the top 50% of languages
  • the MoonScript website
  • MoonScript on github
  • MoonScript first appeared in 2011
  • file extensions for MoonScript include moon
  • tryitonline has an online MoonScript repl
  • I have 56 facts about MoonScript. what would you like to know? email me and let me know how I can help.

Example code from Linguist:

types = require "moonscript.types"
util = require "moonscript.util"
data = require "moonscript.data"

import reversed, unpack from util
import ntype, mtype, build, smart_node, is_slice, value_is_singular from types
import insert from table
import NameProxy, LocalName from require "moonscript.transform.names"

destructure = require "moonscript.transform.destructure"

local implicitly_return

class Run
  new: (@fn) =>
    self[1] = "run"

  call: (state) =>
    self.fn state

-- transform the last stm is a list of stms
-- will puke on group
apply_to_last = (stms, fn) ->
  -- find last (real) exp
  last_exp_id = 0
  for i = #stms, 1, -1
    stm = stms[i]
    if stm and mtype(stm) != Run
      last_exp_id = i
      break

  return for i, stm in ipairs stms
    if i == last_exp_id
      fn stm
    else
      stm

-- is a body a sindle expression/statement
is_singular = (body) ->
  return false if #body != 1
  if "group" == ntype body
    is_singular body[2]
  else
    true

find_assigns = (body, out={}) ->
  for thing in *body
    switch thing[1]
      when "group"
        find_assigns thing[2], out
      when "assign"
        table.insert out, thing[2] -- extract names
  out

hoist_declarations = (body) ->
  assigns = {}

  -- hoist the plain old assigns
  for names in *find_assigns body
    for name in *names
      table.insert assigns, name if type(name) == "string"

  -- insert after runs
  idx = 1
  while mtype(body[idx]) == Run do idx += 1

  table.insert body, idx, {"declare", assigns}

expand_elseif_assign = (ifstm) ->
  for i = 4, #ifstm
    case = ifstm[i]
    if ntype(case) == "elseif" and ntype(case[2]) == "assign"
      split = { unpack ifstm, 1, i - 1 }
      insert split, {
        "else", {
          {"if", case[2], case[3], unpack ifstm, i + 1}
        }
      }
      return split

  ifstm

constructor_name = "new"

with_continue_listener = (body) ->
  continue_name = nil
  {
    Run =>
      @listen "continue", ->
        unless continue_name

Trending Repos

repo stars description

Last updated December 4th, 2019

Edit MoonScript