diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-10-30 23:42:04 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-10-30 23:42:36 -0700 |
| commit | ea3197aaffba00318920ed5e1e33ca5f2a5e6c5c (patch) | |
| tree | 2ec4aff13c7a54a3730994525b591ac60528b5ad /lib | |
| parent | e7e84c9eda38c930f5475301de4a449dcf59e8b6 (diff) | |
Fully working version of (action [foo]: baz) -> ((foo) means: baz)
refactor and misc other changes.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/base64.nom | 8 | ||||
| -rw-r--r-- | lib/consolecolor.nom | 5 | ||||
| -rw-r--r-- | lib/file_hash.nom | 10 | ||||
| -rw-r--r-- | lib/object.nom | 24 | ||||
| -rw-r--r-- | lib/os.nom | 28 | ||||
| -rw-r--r-- | lib/training_wheels.nom | 46 | ||||
| -rw-r--r-- | lib/version.nom | 2 |
7 files changed, 62 insertions, 61 deletions
diff --git a/lib/base64.nom b/lib/base64.nom index 8fc4e6b..2091615 100644 --- a/lib/base64.nom +++ b/lib/base64.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.8.8.6 +#!/usr/bin/env nomsu -V4.8.10 # This file defines actions for encoding/decoding base 64, as specified in: https://tools.ietf.org/html/rfc4648 @@ -13,7 +13,7 @@ test: %plain = "foobar".[1, %len - 1] assume (base64 %plain) == %encoded assume (base64 decode %encoded) == %plain -action [base64 %str, base64 encode %str, %str base64]: +externally [base64 %str, base64 encode %str, %str base64] all mean: %chars = [] for %i in 1 to (size of %str) via 3: %bytes = [=lua "\%str:byte(\%i, \(%i + 2))"] @@ -36,8 +36,8 @@ action [base64 %str, base64 encode %str, %str base64]: return (%chars::joined) -action [chr %] (=lua "string.char(\%)") -action [decode base64 %str, %str base64 decoded, base64 decode %str]: +externally (chr %) means (=lua "string.char(\%)") +externally [decode base64 %str, %str base64 decoded, base64 decode %str] all mean: %chars = [] for %i in 1 to (size of %str) via 4: %indices = (%reverse_b64.(%str.%) for % in %i to (%i + 3)) diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom index f4c4df9..e0e032d 100644 --- a/lib/consolecolor.nom +++ b/lib/consolecolor.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.8.8.6 +#!/usr/bin/env nomsu -V4.8.10 # This file defines actions for ANSI console color escape codes. @@ -15,8 +15,7 @@ test: for %name = %colornum in %colors: %colornum = "\%colornum" (=lua "COMPILE_ACTIONS").%name = (..) - [%nomsu, %tree] -> (..) - Lua value "'\\027[\(%colornum)m'" + [%nomsu, %tree] -> (Lua value "'\\027[\(%colornum)m'") (=lua "COMPILE_ACTIONS")."\%name 1" = (..) [%nomsu, %tree, %text] -> (..) Lua value "('\\027[\(%colornum)m'..\(%text as lua expr)..'\\027[0m')" diff --git a/lib/file_hash.nom b/lib/file_hash.nom index 6fdb2f4..6c815f5 100644 --- a/lib/file_hash.nom +++ b/lib/file_hash.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.8.8.6 +#!/usr/bin/env nomsu -V4.8.10 # This file defines some actions for hashing files and looking up files by hash. @@ -26,14 +26,14 @@ test: if %use_sha1: assume ((hash "hello world") == "Kq5sNclPz7QV2+lfQIuc6R7oRu0=") if %use_sha1: - action [hash %]: + externally (hash %) means: %hash = (=lua "\%hashlib.new('sha1'):final(\%)") 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" - action [hash %]: + externally (hash %) means: %bytes = (%::bytes) %hash = (%bytes.1 << 7) for %i in 2 to (size of %bytes): @@ -41,10 +41,10 @@ if %use_sha1: %hash = (%hash ~ (size of %bytes)) return "\%hash" -action [file with hash %hash]: +externally (file with hash %hash) means: for file %filename in ".": %contents = (read file %filename) %file_hash = (hash %contents) if (%file_hash == %hash): return %filename -parse [hash of file %filename] as (hash (read file %filename)) +(hash of file %filename) parses as (hash (read file %filename)) diff --git a/lib/object.nom b/lib/object.nom index bbc6e06..4f45188 100644 --- a/lib/object.nom +++ b/lib/object.nom @@ -1,15 +1,13 @@ -#!/usr/bin/env nomsu -V4.8.8.6 +#!/usr/bin/env nomsu -V4.8.10 # This file contains the implementation of an Object-Oriented programming system. %globals.METAMETHOD_MAP = {..} - "as text": "__tostring", "clean up": "__gc", - "+ 1": "__add", "- 1": "__sub", "* 1": "__mul", "/ 1": "__div", - "-": "__unm", "// 1": "__idiv", "mod 1": "__mod", "^ 1": "__pow", - "& 1": "__band", "| 1": "__bor", "~ 1": "__bxor", "~": "__bnot", - "<< 1": "__bshl", ">> 1": "__bshr", "== 1": "__eq", "< 1": "__lt", - "<= 1": "__le", "set 1 = 2": "__newindex", "size": "__len", - "iterate": "__ipairs", "iterate all": "__pairs", + "as text":"__tostring", "clean up":"__gc", "+ 1":"__add", "- 1":"__sub" + "* 1":"__mul", "/ 1":"__div", "-":"__unm", "// 1":"__idiv", "mod 1":"__mod" + "^ 1":"__pow", "& 1":"__band", "| 1":"__bor", "~ 1":"__bxor", "~":"__bnot" + "<< 1":"__bshl", ">> 1":"__bshr", "== 1":"__eq", "< 1":"__lt", "<= 1":"__le" + "set 1 = 2":"__newindex", size:"__len", iterate:"__ipairs", "iterate all":"__pairs" test: object (Dog): @@ -53,13 +51,13 @@ test: with {%d:Dog {barks:2}}: assume ((%d::bark) == "Bark! Bark!") -compile [my action %actions %body] to: +(my action %actions %body) compiles to: lua> "\ ..local fn_name = \%actions[1].stub:as_lua_id() local \%args = table.map(\%actions[1]:get_args(), function(a) return tostring(nomsu:compile(a)) end) table.insert(\%args, 1, \(\%me as lua id)) local lua = LuaCode(tree.source, "class.", fn_name, " = ", \(..) - compile as (%args -> %body) + what (%args -> %body) compiles to ..) for i=2,#\%actions do local alias = \%actions[i] @@ -79,12 +77,13 @@ compile [my action %actions %body] to: end return lua" -compile [object %classname extends %parent %class_body] to: +(object %classname extends %parent %class_body) compiles to: unless (%classname.type == "Action"): compile error at %classname "Expected this to be an action, not a \(%classname.type)" for % in %classname: unless (% is text): compile error at % "Class names should not have arguments." + return (..) Lua "\ ..do @@ -112,6 +111,5 @@ compile [object %classname extends %parent %class_body] to: end end" -parse [object %classname %class_body] as (..) +(object %classname %class_body) parses as (..) object %classname extends (nil) %class_body - @@ -1,14 +1,14 @@ -#!/usr/bin/env nomsu -V4.8.8.6 +#!/usr/bin/env nomsu -V4.8.10 # This file defines some actions that interact with the operating system and filesystem. test: path of Nomsu file "lib/os.nom" -action [path of Nomsu file %filename]: +externally (path of Nomsu file %filename) means: lua> "for i,f in Files.walk(\%filename) do return f end" barf "Could not find file: \%filename" -action [sh> %cmd]: +externally (sh> %cmd) means: lua> "\ ..local result = io.popen(\%cmd) local contents = result:read("*a") @@ -17,19 +17,19 @@ action [sh> %cmd]: test: read file "lib/os.nom" -action [read file %filename] (=lua "Files.read(\%filename)") +externally (read file %filename) means (=lua "Files.read(\%filename)") test: for file %f in "core": do nothing -compile [for file %f in %path %body] to (..) +(for file %f in %path %body) compiles to (..) Lua "\ ..for i,\(%f as lua expr) in Files.walk(\(%path as lua expr)) do \(%body as lua statements) - \(compile as (===next %f ===)) + \(what (===next %f ===) compiles to) end - \(compile as (===stop %f ===))" + \(what (===stop %f ===) compiles to)" -compile [%expr for file %f in %path] to (..) +(%expr for file %f in %path) compiles to (..) Lua value "\ ..(function() local ret = _List{} @@ -39,10 +39,10 @@ compile [%expr for file %f in %path] to (..) return ret end)()" -action [..] +externally [..] write to file %filename %text, to file %filename write %text write %text to file %filename -..: +..all mean: assume (%filename != "stdin") or barf "Cannot write to stdin" lua> "\ ..local file = io.open(\%filename, 'w') @@ -51,15 +51,17 @@ action [..] test: assume (line number of 3 in "x\ny") == 2 -action [line number of %pos in %str] (=lua "Files.get_line_number(\%str, \%pos)") +externally (line number of %pos in %str) means (..) + =lua "Files.get_line_number(\%str, \%pos)" test: assume (line 2 in "one\ntwo\nthree") == "two" -action [line %line_num in %str] (=lua "Files.get_line(\%str, \%line_num)") +externally (line %line_num in %str) means (..) + =lua "Files.get_line(\%str, \%line_num)" test: assume (source lines of \(this)) -action [source lines of %tree]: +externally (source lines of %tree) means: %source = (%tree.source if (%tree is syntax tree) else %tree) %file = (read file %source.filename) return (..) diff --git a/lib/training_wheels.nom b/lib/training_wheels.nom index 6155069..f16b700 100644 --- a/lib/training_wheels.nom +++ b/lib/training_wheels.nom @@ -1,26 +1,28 @@ -#!/usr/bin/env nomsu -V4.8.8.6 +#!/usr/bin/env nomsu -V4.8.10 # This file contains a set of definitions that bring some familiar language features from other languages into nomsu (e.g. "||" and "continue") -parse [%a === %b] as ((%a 's id) is (%b 's id)) -parse [%a !== %b] as ((%a 's id) is not (%b 's id)) -parse [function %names %body, def %names %body] as (action %names %body) -parse [switch %branch_value %body] as (if %branch_value is %body) -parse [None, Null] as (nil) -parse [True, true] as (yes) -parse [False, false] as (no) -parse [pass] as (do nothing) -parse [%a || %b] as (%a or %b) -parse [%a && %b] as (%a and %b) -parse [continue] as (do next) -parse [break] as (stop) -parse [let %thing = %value in %action] as (with local {%thing:%value}) -parse [print %, println %] as (say %) -parse [error!, panic!, fail!, abort!] as (barf!) -parse [error %, panic %, fail %, abort %] as (barf %) -parse [assert %condition] as (assume %condition) -parse [assert %condition %message] as (assume %condition or barf %message) -parse [%cond ? %if_true %if_false] as (%if_true if %cond else %if_false) -parse [lambda %args %body] as (%args -> %body) -parse [function %name %args %body] as (%name = (%args -> %body)) +(%a === %b) parses as ((%a 's id) is (%b 's id)) +(%a !== %b) parses as ((%a 's id) is not (%b 's id)) +[function %names %body, def %names %body] all parse as (..) + externally %names means %body + +(switch %branch_value %body) parses as (if %branch_value is %body) +[None, Null] all parse as (nil) +[True, true] all parse as (yes) +[False, false] all parse as (no) +(pass) parses as (do nothing) +(%a || %b) parses as (%a or %b) +(%a && %b) parses as (%a and %b) +(continue) parses as (do next) +(break) parses as (stop) +(let %thing = %value in %action) parses as (with local {%thing:%value}) +[print %, println %] all parse as (say %) +[error!, panic!, fail!, abort!] all parse as (barf!) +[error %, panic %, fail %, abort %] all parse as (barf %) +(assert %condition) parses as (assume %condition) +(assert %condition %message) parses as (assume %condition or barf %message) +(%cond ? %if_true %if_false) parses as (%if_true if %cond else %if_false) +(lambda %args %body) parses as (%args -> %body) +(function %name %args %body) parses as (%name = (%args -> %body)) diff --git a/lib/version.nom b/lib/version.nom index afb9e14..2f4003f 100644 --- a/lib/version.nom +++ b/lib/version.nom @@ -1,3 +1,3 @@ -#!/usr/bin/env nomsu -V4.8.8.6 +#!/usr/bin/env nomsu -V4.8.10 # This file sets the current library version. lua> "NOMSU_LIB_VERSION = 6" |
