aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-09-10 16:26:08 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-09-10 16:26:27 -0700
commit7c6047254e5aa7ce5a0667b14676b22a7447f956 (patch)
treef98478e6c77257610e43dc45447cd23e91bdaaae
parentc859eac2beb20889e162ca28f889cc02ac592266 (diff)
Upgraded to 3.8 (text method changes) and fixed some bugs in
tree_to_nomsu.
-rw-r--r--compatibility/2.3.nom2
-rw-r--r--compatibility/2.4.nom2
-rw-r--r--compatibility/2.5.5.5.nom2
-rw-r--r--compatibility/2.5.nom2
-rw-r--r--compatibility/2.nom2
-rw-r--r--compatibility/3.5.5.6.nom2
-rw-r--r--compatibility/3.6.nom2
-rw-r--r--compatibility/3.7.nom2
-rw-r--r--compatibility/3.nom2
-rw-r--r--compatibility/compatibility.nom14
-rw-r--r--core/collections.nom2
-rw-r--r--core/control_flow.nom2
-rw-r--r--core/coroutines.nom2
-rw-r--r--core/errors.nom6
-rw-r--r--core/id.nom29
-rw-r--r--core/io.nom2
-rw-r--r--core/math.nom10
-rw-r--r--core/metaprogramming.nom5
-rw-r--r--core/operators.nom2
-rw-r--r--core/scopes.nom2
-rw-r--r--core/text.nom26
-rw-r--r--examples/how_do_i.nom4
-rw-r--r--lib/base64.nom6
-rw-r--r--lib/consolecolor.nom2
-rw-r--r--lib/file_hash.nom7
-rw-r--r--lib/object.nom6
-rw-r--r--lib/os.nom4
-rw-r--r--lib/training_wheels.nom2
-rw-r--r--lib/version.nom2
-rw-r--r--nomsu_compiler.lua15
-rw-r--r--nomsu_compiler.moon10
-rwxr-xr-xtools/autoformat.nom4
-rwxr-xr-xtools/find_action.nom4
-rwxr-xr-xtools/parse.nom4
-rwxr-xr-xtools/replace.nom4
-rwxr-xr-xtools/test.nom8
-rwxr-xr-xtools/upgrade.nom4
37 files changed, 101 insertions, 105 deletions
diff --git a/compatibility/2.3.nom b/compatibility/2.3.nom
index 4df7850..2381010 100644
--- a/compatibility/2.3.nom
+++ b/compatibility/2.3.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <2.3 to Nomsu 2.3
diff --git a/compatibility/2.4.nom b/compatibility/2.4.nom
index 741b7eb..b50fec3 100644
--- a/compatibility/2.4.nom
+++ b/compatibility/2.4.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <2.4 to Nomsu 2.4
diff --git a/compatibility/2.5.5.5.nom b/compatibility/2.5.5.5.nom
index b086a9d..b242e57 100644
--- a/compatibility/2.5.5.5.nom
+++ b/compatibility/2.5.5.5.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <2.5.5.5 to Nomsu 2.5.5.5
diff --git a/compatibility/2.5.nom b/compatibility/2.5.nom
index 27473e7..e55915d 100644
--- a/compatibility/2.5.nom
+++ b/compatibility/2.5.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <2.5 to Nomsu 2.5
diff --git a/compatibility/2.nom b/compatibility/2.nom
index 06e3bff..3f37cb4 100644
--- a/compatibility/2.nom
+++ b/compatibility/2.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu 1 to Nomsu 2
diff --git a/compatibility/3.5.5.6.nom b/compatibility/3.5.5.6.nom
index 892725f..b46144e 100644
--- a/compatibility/3.5.5.6.nom
+++ b/compatibility/3.5.5.6.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <3.5.5.6 to Nomsu 3.5.5.6
diff --git a/compatibility/3.6.nom b/compatibility/3.6.nom
index c6afc75..07ad7a5 100644
--- a/compatibility/3.6.nom
+++ b/compatibility/3.6.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <3.6 to 3.6
diff --git a/compatibility/3.7.nom b/compatibility/3.7.nom
index dda2b5a..ca49e3f 100644
--- a/compatibility/3.7.nom
+++ b/compatibility/3.7.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <3.7 to 3.7
diff --git a/compatibility/3.nom b/compatibility/3.nom
index d1599cc..8f20f1a 100644
--- a/compatibility/3.nom
+++ b/compatibility/3.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines upgrades from Nomsu <=2 to Nomsu 3
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom
index 7f186ea..2093aff 100644
--- a/compatibility/compatibility.nom
+++ b/compatibility/compatibility.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains code for defining ways to upgrade code between different versions
of Nomsu.
@@ -26,7 +26,7 @@ compile [upgrade action %actions to %version as %body] to:
if (%action.%i.type is "Var"):
%replacements.(%action.%i.1) = "\(\%tree as lua id)[\%i]"
- %needs_mangle = (no)
+ define mangler
local action [make tree %t]:
when:
(%t is "Var" syntax tree):
@@ -34,10 +34,7 @@ compile [upgrade action %actions to %version as %body] to:
return %replacements.(%t.1)
..else:
external %needs_mangle = (yes)
- return ".."
- \(%t.type){source=\(quote "\(%t.source)"), \(..)
- quote "\(%t.1) \000\(=lua "string.format('%X', __MANGLE_INDEX)")"
- ..}
+ return "\(%t.type){source=\(quote "\(%t.source)"), \(quote (mangle %t.1))}"
(%t is syntax tree):
%args = []
@@ -47,7 +44,7 @@ compile [upgrade action %actions to %version as %body] to:
..else:
%args::add "\(%k)=\(make tree %v)"
- return "\(%t.type){\(%args joined with ", ")}"
+ return "\(%t.type){\(%args::joined with ", ")}"
else: return (quote %t)
@@ -58,8 +55,7 @@ compile [upgrade action %actions to %version as %body] to:
upgrade_action_1_to_2_via_3(\(quote %action.stub), \(%version as lua expr), function(\(..)
\%tree as lua id
..)
- \("__MANGLE_INDEX = (__MANGLE_INDEX or 0) + 1\n " if (%needs_mangle) else "")\
- ..return \%retval
+ return \%retval
end)
return %lua
diff --git a/core/collections.nom b/core/collections.nom
index 2af7605..bc58c7b 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains code that supports manipulating and using collections like lists
and dictionaries.
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 0c38485..b26b870 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains compile-time actions that define basic control flow structures
like "if" statements and loops.
diff --git a/core/coroutines.nom b/core/coroutines.nom
index 753a2ef..d7d1db4 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines the code that creates and manipulates coroutines
diff --git a/core/errors.nom b/core/errors.nom
index 638b487..53f88be 100644
--- a/core/errors.nom
+++ b/core/errors.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains basic error reporting code
@@ -27,7 +27,9 @@ compile [assume %a == %b] to:
do
local \(mangle "a"), \(mangle "b") = \(%a as lua expr), \(%b as lua expr)
if \(mangle "a") ~= \(mangle "b") then
- error(\(quote "\%assumption").."\\n"..tostring(\(mangle "a")).." != "..tostring(\(mangle "b")), 0)
+ error(\(quote "\%assumption").."\\n"..tostring(\(mangle "a")).." != "..tostring(\(..)
+ mangle "b"
+ ..), 0)
end
end
diff --git a/core/id.nom b/core/id.nom
index 8a213d4..9f41cfb 100644
--- a/core/id.nom
+++ b/core/id.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
A simple UUID function based on RFC 4122: http://www.ietf.org/rfc/rfc4122.txt
@@ -10,14 +10,16 @@ use "core/control_flow.nom"
%NaN_surrogate = {}
%nil_surrogate = {}
%obj_by_id = {}
-set %obj_by_id's metatable to {__mode: "v"}
+set %obj_by_id's metatable to {__mode:"v"}
%id_by_obj = {}
-set %id_by_obj's metatable to {..}
- __mode: "k"
+set %id_by_obj 's metatable to {..}
+ __mode:"k"
__index: (..)
[%self, %key] ->:
- if (%key == (nil)): return %self.%nil_surrogate
- if (%key != %key): return %self.%NaN_surrogate
+ if (%key == (nil)):
+ return %self.%nil_surrogate
+ if (%key != %key):
+ return %self.%NaN_surrogate
--- %retry ---
%id = (uuid)
if (%obj_by_id.%id != (nil)): go to %retry
@@ -28,16 +30,18 @@ set %id_by_obj's metatable to {..}
action [uuid]:
# Set all the other bits to randomly (or pseudo-randomly) chosen values.
%bytes = [..]
- randint (2^(4*8)), # time-low
- randint (2^(2*8)), # time-mid
- randint (2^(2*8 - 4)), # time-high-and-version
- randint (2^(1*8 - 2)), # clock-seq-and-reserved
- randint (2^(1*8)), # clock-seq-low
- randint (2^(3*8)), randint (2^(3*8)), # node
+ # time-low, time-mid, time-high-and-version
+ randint (2 ^ (4 * 8)), randint (2 ^ (2 * 8)), randint (2 ^ (2 * 8 - 4))
+ # clock-seq-and-reserved, clock-seq-low
+ randint (2 ^ (1 * 8 - 2)), randint (2 ^ (1 * 8)), randint (2 ^ (3 * 8))
+ # node
+ randint (2 ^ (3 * 8))
+
# Set the four most significant bits (bits 12 through 15) of the
# time_hi_and_version field to the 4-bit version number from
# Section 4.1.3.
%bytes.3 += 0x4000
+
# Set the two most significant bits (bits 6 and 7) of the
# clock_seq_hi_and_reserved to zero and one, respectively.
%bytes.4 += 0xC0
@@ -52,5 +56,4 @@ test:
seed random with 0
assume ((id of %x) != (id of []))
seed random
-
action [id of %, %'s id, %' id] %id_by_obj.%
diff --git a/core/io.nom b/core/io.nom
index e47554f..d656419 100644
--- a/core/io.nom
+++ b/core/io.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains basic input/output code
diff --git a/core/math.nom b/core/math.nom
index 6a205b6..439b698 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines some common math literals and functions
@@ -73,27 +73,27 @@ compile [all of %items, all %items] to:
unless (%items.type is "List"):
return (Lua value "utils.all(\(%items as lua expr))")
%clauses = ((% as lua expr) for % in %items)
- return (Lua value "(\(%clauses joined with " and "))")
+ return (Lua value "(\(%clauses::joined with " and "))")
parse [not all of %items, not all %items] as (not (all of %items))
compile [any of %items, any %items] to:
unless (%items.type is "List"):
return (Lua value "utils.any(\(%items as lua expr))")
%clauses = ((% as lua expr) for % in %items)
- return (Lua value "(\(%clauses joined with " or "))")
+ return (Lua value "(\(%clauses::joined with " or "))")
parse [none of %items, none %items] as (not (any of %items))
compile [sum of %items, sum %items] to:
unless (%items.type is "List"):
return (Lua value "utils.sum(\(%items as lua expr))")
%clauses = ((% as lua expr) for % in %items)
- return (Lua value "(\(%clauses joined with " + "))")
+ return (Lua value "(\(%clauses::joined with " + "))")
compile [product of %items, product %items] to:
unless (%items.type is "List"):
return (Lua value "utils.product(\(%items as lua expr))")
%clauses = ((% as lua expr) for % in %items)
- return (Lua value "(\(%clauses joined with " * "))")
+ return (Lua value "(\(%clauses::joined with " * "))")
action [avg of %items, average of %items] (=lua "(utils.sum(\%items)/#\%items)")
compile [min of %items, smallest of %items, lowest of %items] to (..)
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index c978bf8..836b5a2 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -1,9 +1,9 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This File contains actions for making actions and compile-time actions and some helper
functions to make that easier.
-lua> "NOMSU_CORE_VERSION = 7"
+lua> "NOMSU_CORE_VERSION = 8"
lua> ".."
do
local mangle_index = 0
@@ -18,6 +18,7 @@ lua> ".."
COMPILE_ACTIONS["define mangler"] = function(nomsu, tree)
return LuaCode(tree.source, "local mangle_1 = mangler()")
end
+
lua> ".."
COMPILE_ACTIONS["1 -> 2"] = function(nomsu, tree, \%args, \%body)
local lua = LuaCode.Value(tree.source, "(function(")
diff --git a/core/operators.nom b/core/operators.nom
index 9395d9d..3d18275 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains definitions of operators like "+" and "and".
diff --git a/core/scopes.nom b/core/scopes.nom
index 6ee2939..6cc79c0 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains definitions pertaining to variable scoping
diff --git a/core/text.nom b/core/text.nom
index bd9335a..da9d550 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains some definitions of text escape sequences, including ANSI console
color codes.
@@ -26,36 +26,12 @@ test:
assume ("asdf"::uppercase) == "ASDF"
assume ("asdf"::with "s" -> "X") == "aXdf"
assume ("one\ntwo\n"::lines) == ["one", "two", ""]
-
parse [アクション %spec %body] as (action %spec %body)
test:
%こんにちは = "こんにちは"
アクション [% と言う] "\(%)世界"
assume (%こんにちは と言う) == "こんにちは世界"
-# Text functions
-parse [%texts joined with %glue] as (%texts::joined with %glue)
-parse [%texts joined, joined %texts] as (%texts::joined)
-parse [byte %i of %text] as (%text::byte %i)
-parse [bytes %start to %stop of %text] as (%text::bytes %start to %stop)
-parse [bytes of %text] as (%text::bytes)
-parse [capitalized %text, %text capitalized] as (%text::capitalized)
-parse [uppercase %text, %text uppercase] as (%text::uppercase)
-parse [..]
- %text with %sub instead of %patt, %text with %patt replaced by %sub
- %text s/ %patt / %sub
-..as (%text::with %patt -> %sub)
-parse [%text matches %pattern] as (%text::matches %pattern)
-parse [%text matching %pattern] as ((%text::matching %pattern).1)
-
-compile [for %match in %text matching %patt %body] to (..)
- Lua ".."
- for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(%patt as lua expr)) do
- \(%body as lua statements)
- \(compile as (===next %match ===))
- end
- \(compile as (===stop %match ===))
-
compile [%expr for %match in %text matching %patt] to (..)
Lua value ".."
(function()
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom
index 1f1b683..cc9901a 100644
--- a/examples/how_do_i.nom
+++ b/examples/how_do_i.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
# How do I...
# Write a comment? Put a # and go till the end of the line
# How do I write a multi-line comment?
@@ -190,7 +190,7 @@ action [..]
I think %worse_things are worse than %better_things
I like %better_things more than %worse_things
..:
- say "\(%better_things capitalized) rule and \%worse_things drool!"
+ say "\(%better_things::capitalized) rule and \%worse_things drool!"
I like "dogs" more than "cats"
I think "chihuahuas" are worse than "corgis"
diff --git a/lib/base64.nom b/lib/base64.nom
index 92ce7c4..366ac3e 100644
--- a/lib/base64.nom
+++ b/lib/base64.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines actions for encoding/decoding base 64, as specified in:
https://tools.ietf.org/html/rfc4648
@@ -39,7 +39,7 @@ action [base64 %str, base64 encode %str, %str base64]:
%chars::add "="
%chars::add "="
- return (%chars joined)
+ return (%chars::joined)
action [chr %] (=lua "string.char(\%)")
action [decode base64 %str, %str base64 decoded, base64 decode %str]:
@@ -52,4 +52,4 @@ action [decode base64 %str, %str base64 decoded, base64 decode %str]:
if (%str.(%i + 3) == "="): stop
%chars::add (chr (((%indices.3 & 3) << 6) + %indices.4))
- return (%chars joined)
+ return (%chars::joined)
diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom
index 7809f86..c86e6d1 100644
--- a/lib/consolecolor.nom
+++ b/lib/consolecolor.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines actions for ANSI console color escape codes.
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index 35b8340..5553b35 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines some actions for hashing files and looking up files by hash.
@@ -31,9 +31,10 @@ if %use_sha1:
return (base64 %hash)
..else:
# TODO: remove warning?
- say "\027[31;1mWARNING: OpenSSL module not found. Defaulting to a non-cryptographically secure hash function.\027[0m"
+ say ".."
+ \027[31;1mWARNING: OpenSSL module not found. Defaulting to a non-cryptographically secure hash function.\027[0m
action [hash %]:
- %bytes = (bytes of %)
+ %bytes = (%::bytes)
%hash = (%bytes.1 << 7)
for %i in 2 to (size of %bytes):
%hash = ((1000003 * %hash) ~ %bytes.%i)
diff --git a/lib/object.nom b/lib/object.nom
index 81632c2..897657c 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains the implementation of an Object-Oriented programming system.
@@ -8,7 +8,7 @@ test:
my action [set up]: %me.barks or= 0
my action [bark, woof]:
%barks = ("Bark!" for % in 1 to %me.barks)
- return (%barks joined with " ")
+ return (%barks::joined with " ")
my action [get pissed off]: %me.barks += 1
@@ -31,7 +31,7 @@ test:
my action [sploot] "splooted"
my action [bark, woof]:
%barks = ("Yip!" for % in 1 to %me.barks)
- return (%barks joined with " ")
+ return (%barks::joined with " ")
%corg = (new Corgi)
assume (%corg.barks == 0)
diff --git a/lib/os.nom b/lib/os.nom
index 4edccb9..2c9addf 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file defines some actions that interact with the operating system and filesystem.
@@ -66,4 +66,4 @@ action [source lines of %tree]:
(..)
(line % in %file) for % in (line number of %source.start in %file) to (..)
line number of %source.stop in %file
- ..joined with "\n"
+ ..::joined with "\n"
diff --git a/lib/training_wheels.nom b/lib/training_wheels.nom
index e98392a..8e197c4 100644
--- a/lib/training_wheels.nom
+++ b/lib/training_wheels.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
This file contains a set of definitions that bring some familiar language features
from other languages into nomsu (e.g. "||" and "continue")
diff --git a/lib/version.nom b/lib/version.nom
index 12e691a..3c876b8 100644
--- a/lib/version.nom
+++ b/lib/version.nom
@@ -1,3 +1,3 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
# This file sets the current library version.
lua> "NOMSU_LIB_VERSION = 6"
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 215617f..a53de1a 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -963,8 +963,15 @@ do
end
local space = MAX_LINE - pos
local inline
+ local check
+ check = function(prefix, nomsu, tree)
+ if type(tree) == 'number' then
+ require('ldt').breakpoint()
+ end
+ return coroutine.yield(prefix, nomsu, tree)
+ end
for prefix, nomsu, tree in coroutine.wrap(function()
- inline = self:tree_to_inline_nomsu(t, false, coroutine.yield)
+ inline = self:tree_to_inline_nomsu(t, false, check)
end) do
local len = #tostring(nomsu)
if prefix + len > MAX_LINE then
@@ -1083,7 +1090,11 @@ do
nomsu:append(pop_comments(tree.source.stop, '\n'))
return nomsu
elseif "EscapedNomsu" == _exp_0 then
- return NomsuCode(tree.source, "\\", recurse(tree[1], 1))
+ local val_nomsu = recurse(tree[1], 1)
+ if tree[1].type == "Action" and not val_nomsu:is_multiline() then
+ val_nomsu:parenthesize()
+ end
+ return NomsuCode(tree.source, "\\", val_nomsu)
elseif "Block" == _exp_0 then
local nomsu = NomsuCode(tree.source, pop_comments(tree.source.start))
for i, line in ipairs(tree) do
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 7a637f4..ba911ce 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -621,7 +621,10 @@ with NomsuCompiler
if type(pos) != 'number' then pos = #tostring(pos)\match("[ ]*([^\n]*)$")
space = MAX_LINE - pos
local inline
- for prefix, nomsu, tree in coroutine.wrap(-> inline = @tree_to_inline_nomsu(t, false, coroutine.yield))
+ check = (prefix,nomsu,tree)->
+ if type(tree) == 'number' then require('ldt').breakpoint!
+ coroutine.yield(prefix,nomsu,tree)
+ for prefix, nomsu, tree in coroutine.wrap(-> inline = @tree_to_inline_nomsu(t, false, check))
len = #tostring(nomsu)
break if prefix+len > MAX_LINE
break if tree.type == "Block" and (#tree > 1 or len > 20)
@@ -700,7 +703,10 @@ with NomsuCompiler
return nomsu
when "EscapedNomsu"
- return NomsuCode tree.source, "\\", recurse(tree[1], 1)
+ val_nomsu = recurse(tree[1], 1)
+ if tree[1].type == "Action" and not val_nomsu\is_multiline!
+ val_nomsu\parenthesize!
+ return NomsuCode tree.source, "\\", val_nomsu
when "Block"
nomsu = NomsuCode(tree.source, pop_comments(tree.source.start))
diff --git a/tools/autoformat.nom b/tools/autoformat.nom
index dcccc21..42e7dca 100755
--- a/tools/autoformat.nom
+++ b/tools/autoformat.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
Auto-format Nomsu code. Usage:
nomsu tools/autoformat.nom [-i] file1 file2 directory1 ...
@@ -15,7 +15,7 @@ if (%args.1 is "-i"):
for %path in %args:
for file %filename in %path:
- unless (%filename matches "%.nom$"): do next %filename
+ unless (%filename::matches "%.nom$"): do next %filename
%formatted = ".."
#!/usr/bin/env nomsu -V\(Nomsu version)
\((parse (read file %filename) from %filename) as nomsu)
diff --git a/tools/find_action.nom b/tools/find_action.nom
index 7067959..4918966 100755
--- a/tools/find_action.nom
+++ b/tools/find_action.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
Find an action by its stub. Usage:
nomsu tools/find_action.nom "foo %" file1 file2 directory1 ...
@@ -12,7 +12,7 @@ say "Looking for stub: \%stub..."
%files = ((command line args).% for % in 2 to (size of (command line args)))
for %path in %files:
for file %filename in %path:
- unless (%filename matches "%.nom$") (do next %filename)
+ unless (%filename::matches "%.nom$") (do next %filename)
%file = (read file %filename)
%tree = (parse %file from %filename)
for %t in recursive %tree:
diff --git a/tools/parse.nom b/tools/parse.nom
index 0622e27..ee4a722 100755
--- a/tools/parse.nom
+++ b/tools/parse.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
Tool to print out a parse tree of files in an easy-to-read format. Usage:
nomsu tools/parse.nom file1 file2 directory1 ...
@@ -32,5 +32,5 @@ action [print tree %t at indent %indent]:
for %path in (=lua "arg"):
for file %filename in %path:
- unless (%filename matches "%.nom$"): do next %filename
+ unless (%filename::matches "%.nom$"): do next %filename
print tree (parse (read file %filename) from %filename) at indent ""
diff --git a/tools/replace.nom b/tools/replace.nom
index 76617cf..a0de4cc 100755
--- a/tools/replace.nom
+++ b/tools/replace.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
Tool to find and replace one tree with another.
nomsu tools/replace.nom [-i] tree_to_replace replacement file1 file2 directory1 ...
@@ -21,7 +21,7 @@ if ((size of %args) < 3):
%replacement = (parse (%args::remove index 1))
for %path in %args:
for file %filename in %path:
- unless (any [%filename matches "%.nom$", %filename == "-", %filename == "stdin"]):
+ unless (any [%filename::matches "%.nom$", %filename == "-", %filename == "stdin"]):
do next %filename
%tree = (parse (read file %filename) from %filename)
%tree2 = (%tree with %pattern ~> %replacement)
diff --git a/tools/test.nom b/tools/test.nom
index 07f8c7d..5c42ec9 100755
--- a/tools/test.nom
+++ b/tools/test.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
Tool to run all tests in a file (i.e. the code block inside a call to 'test %'). Usage:
nomsu tools/test.nom file1 file2 directory1 ...
@@ -14,13 +14,13 @@ if (%args.1 == "-v"):
# Make sure all the files get run
for %path in (command line args):
for file %filename in %path:
- if (%filename matches "%.nom$"): use %filename
+ if (%filename::matches "%.nom$"): use %filename
for %path in (command line args): use %path
%tests = ((=lua "Source:from_string(\%s)") = %t for %s = %t in (tests))
for %path in (command line args):
for file %filename in %path:
- unless (%filename matches "%.nom$"): do next %filename
+ unless (%filename::matches "%.nom$"): do next %filename
%file_tests = []
for %src = %test in %tests:
if (%src.filename == %filename):
@@ -32,7 +32,7 @@ for %path in (command line args):
if %verbose: say ""
for % in %file_tests:
if %verbose:
- say " \(yellow (%.test with "\n" replaced by "\n "))"
+ say " \(yellow (%.test::with "\n" -> "\n "))"
run %.test
if %verbose: say (green "PASS")
diff --git a/tools/upgrade.nom b/tools/upgrade.nom
index 15f9b8c..d85465e 100755
--- a/tools/upgrade.nom
+++ b/tools/upgrade.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.7.5.6
+#!/usr/bin/env nomsu -V3.8.7.6
#
Tool to automatically update code from old versions of Nomsu. Usage:
nomsu tools/upgrade.nom [-i] file1 file2 directory1 ...
@@ -21,7 +21,7 @@ if (%args.1 is "-t"):
for %path in %args:
for file %filename in %path:
- unless (%filename matches "%.nom$"): do next %filename
+ unless (%filename::matches "%.nom$"): do next %filename
%tree = (parse (read file %filename) from %filename)
%uptree = (%tree upgraded)
%text = ".."