simplification
Download

nomsu

The Nomsu programming language

  • language
  • Nomsu
  • Lua
Code 15.2K linesLua 6.9KNomsu 4.2KMoonScript 3.6KPEG 417Makefile 124Bash 24Dotfile 4
Docs 2.2K wordsMarkdown 1.6KGroff 409Text 169
NameModifiedLinesSize
doc/ 206 lines1% of this folder's lines 6.9 KiB1% of this folder's bytes
examples/ 712 lines4% of this folder's lines 25.2 KiB4% of this folder's bytes
lib/ 4.5K lines27% of this folder's lines 162.4 KiB28% of this folder's bytes
test/ 712 lines4% of this folder's lines 27.7 KiB5% of this folder's bytes
.gitignore 4 lines<1% of this folder's lines 46 B<1% of this folder's bytes
LICENSE 20 lines<1% of this folder's lines 1.1 KiB<1% of this folder's bytes
Makefile 138 lines<1% of this folder's lines 6.1 KiB1% of this folder's bytes
README.md 82 lines<1% of this folder's lines 7.4 KiB1% of this folder's bytes
bitops.lua 71 lines<1% of this folder's lines 1.3 KiB<1% of this folder's bytes
bitops.moon 27 lines<1% of this folder's lines 1.3 KiB<1% of this folder's bytes
bootstrap.lua 239 lines1% of this folder's lines 6.8 KiB1% of this folder's bytes
bootstrap.moon 174 lines1% of this folder's lines 6.6 KiB1% of this folder's bytes
code_obj.lua 654 lines4% of this folder's lines 18.2 KiB3% of this folder's bytes
code_obj.moon 352 lines2% of this folder's lines 12.3 KiB2% of this folder's bytes
colors.lua 83 lines<1% of this folder's lines 1.4 KiB<1% of this folder's bytes
colors.moon 25 lines<1% of this folder's lines 1.2 KiB<1% of this folder's bytes
error_handling.lua 466 lines3% of this folder's lines 15.1 KiB3% of this folder's bytes
error_handling.moon 317 lines2% of this folder's lines 14.3 KiB2% of this folder's bytes
files.lua 254 lines2% of this folder's lines 6.4 KiB1% of this folder's bytes
files.moon 173 lines1% of this folder's lines 6.2 KiB1% of this folder's bytes
nomsu * 27 lines<1% of this folder's lines 669 B<1% of this folder's bytes
nomsu.7.peg 276 lines2% of this folder's lines 9.6 KiB2% of this folder's bytes
nomsu.8.peg 250 lines1% of this folder's lines 9.2 KiB2% of this folder's bytes
nomsu.lua 260 lines2% of this folder's lines 8.5 KiB1% of this folder's bytes
nomsu.moon * 197 lines1% of this folder's lines 7.7 KiB1% of this folder's bytes
nomsu_compiler.lua 450 lines3% of this folder's lines 13.9 KiB2% of this folder's bytes
nomsu_compiler.moon 349 lines2% of this folder's lines 14.2 KiB2% of this folder's bytes
nomsu_decompiler.lua 690 lines4% of this folder's lines 22.8 KiB4% of this folder's bytes
nomsu_decompiler.moon 535 lines3% of this folder's lines 24.4 KiB4% of this folder's bytes
nomsu_environment.lua 784 lines5% of this folder's lines 24.8 KiB4% of this folder's bytes
nomsu_environment.moon 524 lines3% of this folder's lines 24.7 KiB4% of this folder's bytes
nomsu_library.lua 140 lines<1% of this folder's lines 3.8 KiB<1% of this folder's bytes
nomsu_library.moon 97 lines<1% of this folder's lines 4.7 KiB<1% of this folder's bytes
nomsu_limits.lua 360 lines2% of this folder's lines 8.3 KiB1% of this folder's bytes
nomsu_limits.moon 242 lines1% of this folder's lines 10.2 KiB2% of this folder's bytes
nomsu_loaders.lua 101 lines<1% of this folder's lines 2.4 KiB<1% of this folder's bytes
nomsu_loaders.moon 52 lines<1% of this folder's lines 2.2 KiB<1% of this folder's bytes
nomsu_random.lua 80 lines<1% of this folder's lines 1.9 KiB<1% of this folder's bytes
nomsu_random.moon 79 lines<1% of this folder's lines 2.7 KiB<1% of this folder's bytes
nomsu_sandbox.lua 467 lines3% of this folder's lines 11.6 KiB2% of this folder's bytes
nomsu_sandbox.moon 251 lines1% of this folder's lines 11.8 KiB2% of this folder's bytes
nomsu_version.lua 5 lines<1% of this folder's lines 25 B<1% of this folder's bytes
nomsu_version.moon 2 lines<1% of this folder's lines 67 B<1% of this folder's bytes
parser.lua 114 lines<1% of this folder's lines 3.2 KiB<1% of this folder's bytes
parser.moon 90 lines<1% of this folder's lines 3.2 KiB<1% of this folder's bytes
pretty_errors.lua 88 lines<1% of this folder's lines 3.4 KiB<1% of this folder's bytes
pretty_errors.moon 70 lines<1% of this folder's lines 3.1 KiB<1% of this folder's bytes
syntax_tree.lua 315 lines2% of this folder's lines 8.4 KiB1% of this folder's bytes
syntax_tree.moon 171 lines1% of this folder's lines 5.9 KiB1% of this folder's bytes
text.lua 257 lines2% of this folder's lines 6.1 KiB1% of this folder's bytes
text.moon 131 lines<1% of this folder's lines 5 KiB<1% of this folder's bytes
values.lua 86 lines<1% of this folder's lines 1.9 KiB<1% of this folder's bytes
values.moon 53 lines<1% of this folder's lines 1.8 KiB<1% of this folder's bytes

README.md

Nomsu

Nomsu (named after Nomic, and its creator, Peter Suber) is a programming language designed to be used for playing games of Nomic, or engaging in other similar activities revolving around natural language rule-making and self modification. More information is available at Nomsu's homepage.

Dependencies

Nomsu's only dependencies are Lua 5.2+ (or Luajit 2.0+, compiled with XCFLAGS=-DLUAJIT_ENABLE_LUA52COMPAT for Lua 5.2 compatibility) and LPEG (luarocks install lpeg). Nomsu's compiler was written in Moonscript, but all of the .moon files have been compiled into lua for convenience, so Moonscript is not a dependency. Optionally, if luafilesystem (Lua version or LuaJIT version) is installed, it will be used. Otherwise Nomsu will fall back to using system commands (find and ls), which is slower and a bit less safe. Nomsu has been tested on Mac and Linux, but not Windows.

Usage

  • To run Nomsu interactively (a REPL), simply run lua nomsu.lua (or luajit nomsu.lua).
  • To run a .nom file with Nomsu code, run lua nomsu.lua your_file.nom.
  • The full usage options are avilable via lua nomsu.lua --help.
  • To embed Nomsu in a Lua program, or to run untrusted Nomsu code in a sandbox, see doc/library.md.

Examples

There's a more complete set of example code in examples/how_do_i.nom, but roughly, Nomsu looks like:

say "Hello"

$my_nums = [5, 23, 42]
for $num in $my_nums:
    say "\$num is one of my nums"

(sing $n bottles of beer) means:
    for $i in $n to 1 by -1:
        say ("
            \$i bottle\("s" if ($i > 1) else "") of beer on the wall,
            \$i bottle\("s" if ($i > 1) else "") of beer!
            Take one down, pass it around...
        ")
    say "No bottles of beer on the wall."

sing 99 bottles of beer

Compiling/installing

If you enjoy Nomsu so much that you'd like to tinker with it or have it in your system path, there is an included Makefile. This is entirely optional, but you can run make to compile any modified .moon or .nom files into .lua files and produce an executable file called nomsu that can be run directly. make test will run the suite of tests. sudo make install will install the compiler on your system. By default, the nomsu executable will be put in /usr/local/bin and all the necessary support files will be put into /usr/local/share/nomsu/* and /usr/local/lib/nomsu/*, but you can change the location during installation or via the PREFIX=/your/path/here flag. The default build options use the system default lua, but this can be changed via make LUA=luajit or make LUA_BIN=/path/to/lua. To uninstall, simply make uninstall and provide the same installation path you did during installation.

File Layout

All .moon files have been precompiled into corresponding .lua files, so you don't need to have Moonscript installed to run the Nomsu compiler.

  • nomsu - A shell script that selects between different installed versions of Nomsu (using the -V flag). You can use this script to, for example, run nomsu -V 1.2 your_script.nom to run with the latest version of Nomsu that matches 1.2.?.?. All flags and arguments are passed along to whichever Nomsu compiler is chosen.
  • nomsu.moon - The source code for the Nomsu command line runner. This handles loading the nomsu environment and compiler and running the REPL.
  • nomsu.*.peg - The Parsing Expression Grammar used to define each version of Nomsu's syntax. The format of this file is a slightly modified version of the format accepted by LPEG's re module.
  • parser.moon - The Nomsu parser. This file can also be imported and used directly for applications that only need to parse Nomsu, not compile it.
  • nomsu_compiler.moon - The actual Nomsu compiler. This file defines a function that transforms a Nomsu syntax tree into runnable Lua code.
  • nomsu_decompiler.moon - This file defines functions that transform Nomsu syntax trees back into Nomsu code. This can be used for auto-formatting.
  • nomsu_environment.moon - This file defines the environment in which Nomsu code runs, including some basic built-in functions.
  • bitops.moon - Bitwise operations for Lua 5.2 and LuaJIT that respect metamethods, used by the bitwise library.
  • bootstrap.moon - This file defines some bootstrapping compile rules.
  • code_obj.moon - Datastructures used for incrementally building generated code, while preserving code source information.
  • values.moon - Helpers for converting Nomsu values to text and comparing them.
  • error_handling.moon - The logic for producing good error messages within Lua that reference the Nomsu source code that led to them.
  • files.moon - A library for interacting with the filesystem.
  • pretty_errors.moon - A simple library for displaying errors in a more visually pleasing/readable way.
  • syntax_tree.moon - Datastructures used for Nomsu Abstract Syntax Trees.
  • text.moon - A library defining some extra functionality for strings.
  • examples/how_do_i.nom - A simple walkthrough of some of the features of Nomsu, written in Nomsu code. This is a good place to start.
  • lib/*/*.nom - Language libraries, including the core language stuff like control flow, operators, and metaprogramming (in lib/core) and optional language libraries for stuff you might want.
  • lib/compatibility/*.nom - Code for automatically upgrading Nomsu code from old versions to the current version. Code from Nomsu 7 or later can be upgraded automatically, and older code has to be upgraded to Nomsu 7 with Nomsu 7 first.
  • lib/tools/*.nom - A set of utilities useful for doing code manipulation actions.
  • Makefile - Rules for building/installing the compiler.
  • LICENSE - The software license (MIT).
  • README.md - This file.

Versioning

When Nomsu is istalled via make install, all of Nomsu's lua files and lib/ files are stored in $PREFIX/share/nomsu/$NOMSU_VERSION and the Nomsu executable is installed to $PREFIX/bin/nomsu$NOMSU_VERSION, along with the file nomsu (the version-selection script), which goes to $PREFIX/bin/nomsu. When make uninstall is run, all those files are deleted (except for nomsu, if there are other versions installed).

To run different versions, use the -V flag, which will select the latest version matching the specified pattern. For example, if you have v1.0.0, v1.0.2, and 1.1.0 installed, then nomsu will run v1.1.0, nomsu -V1.0 will run v1.0.2, and nomsu -V 1.0.0 will run v1.0.0.

Extra

There is a vim plugin for the language available in the Vim Nomsu repository. It is usually kept relatively up-to-date with Nomsu, but occasionally lags behind.