aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-17 23:37:20 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-17 23:37:26 -0700
commit88df5c72a317cc011f221627a2c3082078237cc1 (patch)
treea0e983d6aa356dbcd7ec2f71378c3b796e960ac3
parentaf441330ff7cfdc466281ce135ca7231ec54c499 (diff)
Updating lib to v2
-rw-r--r--lib/consolecolor.nom18
-rw-r--r--lib/file_hash.nom14
-rw-r--r--lib/object.nom42
-rw-r--r--lib/os.nom38
-rw-r--r--lib/training_wheels.nom65
-rw-r--r--lib/version.nom4
6 files changed, 89 insertions, 92 deletions
diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom
index 3e325d6..a320b03 100644
--- a/lib/consolecolor.nom
+++ b/lib/consolecolor.nom
@@ -1,20 +1,20 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.2.4.3
#
This file defines actions for ANSI console color escape codes.
use "core"
-test: bright: "\(green)Color test passed."
+test: bright "\(green)Color test passed."
%colors <- {..}
- normal:0, "reset color":0, bright:1, bold:1, dim:2, italic:3, underscore:4
- "slow blink":5, "fast blink": 6, reverse:7, inverse:7, inverted:7, hidden:8
+ normal: 0, "reset color": 0, bright: 1, bold: 1, dim: 2, italic: 3, underscore: 4
+ "slow blink": 5, "fast blink": 6, reverse: 7, inverse: 7, inverted: 7, hidden: 8
# There's some other codes, but they're not currently implemented
- black:30, red:31, green:32, yellow:33, blue:34, magenta:35, cyan:36, white:37
- "on black":40, "on red":41, "on green":42, "on yellow":43, "on blue":44
- "on magenta":45, "on cyan":46, "on white":47
+ black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36
+ white: 37, "on black": 40, "on red": 41, "on green": 42, "on yellow": 43
+ "on blue": 44, "on magenta": 45, "on cyan": 46, "on white": 47
-for %name = %colornum in %colors
- with {%escapecode: "\27[\(%colornum)m"}
+for %name = %colornum in %colors:
+ with {%escapecode: "\27[\(%colornum)m"}:
run ".."
#!/usr/bin/env nomsu -V1
compile [\%name] to: Lua value (quote \(quote %escapecode))
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index 9882481..542b2f2 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -1,10 +1,10 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.2.4.3
#
This file defines some actions for hashing files and looking up files by hash.
use "core"
-action [file with hash %hash]
+action [file with hash %hash]:
lua> ".."
local Hash = require("openssl.digest")
for filename in io.popen('find -L . -not -path "*/\\\\.*" -type f -name "*.nom"'):lines() do
@@ -18,11 +18,11 @@ action [file with hash %hash]
end
end
-action [hash %, sha1 %]
+action [hash %, sha1 %]:
%hashlib <- (=lua "require('openssl.digest')")
%hash <- (=lua "\%hashlib.new('sha1'):final(\%)")
- return: =lua "\%hash:gsub('.', function(c) return string.format('%02x', string.byte(c)) end)"
-
-parse [hash of file %filename] as
- sha1: =lua "io.open(\%filename):read('*a')"
+ return (..)
+ =lua "\%hash:gsub('.', function(c) return string.format('%02x', string.byte(c)) end)"
+parse [hash of file %filename] as (..)
+ sha1 (=lua "io.open(\%filename):read('*a')")
diff --git a/lib/object.nom b/lib/object.nom
index 45f7551..d41557b 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -1,37 +1,35 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.2.4.3
#
This file contains the implementation of an Object-Oriented programming system.
use "core"
-compile [@, me] to: Lua value "self"
-
-compile [method %actions %body] to
- %lua <- (compile as: action %actions %body)
+compile [@, me] to (Lua value "self")
+compile [method %actions %body] to:
+ %lua <- (compile as (action %actions %body))
add free vars ((% as lua id) for % in %actions) to %lua
declare locals in %lua
- for % in %actions
+ for % in %actions:
to %lua write "\nclass.\(% as lua id) = \(% as lua id)"
- return
+
+ return (..)
Lua ".."
- do -- Method: \(%actions.1.stub)
+ do -- Method: \(%actions.(1).stub)
\%lua
end
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-parse [as %instance %body] as
- result of
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+parse [as %instance %body] as (..)
+ result of:
%old_self <- (me)
(me) <- %instance
- try
- %body
- ..and if it barfs %msg
+ try %body and if it barfs %msg:
(me) <- %old_self
barf %msg
- ..or if it succeeds
- (me) <- %old_self
+ ..or if it succeeds: (me) <- %old_self
-compile [object %classname extends %parent %class_body] to
+compile [object %classname extends %parent %class_body] to (..)
Lua ".."
do
local class = {name=\(%classname as lua expr)}
@@ -51,11 +49,13 @@ compile [object %classname extends %parent %class_body] to
_ENV["A"..string.as_lua_id("class "..class.name)] = function() return class end
class.__index = class
class.class = class
-
+
\(%class_body as lua statements)
-
+
class.__tostring = class["A"..string.as_lua_id("as text")]
end
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-parse [object %classname %class_body] as: object %classname extends (nil) %class_body
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+parse [object %classname %class_body] as (..)
+ object %classname extends (nil) %class_body
diff --git a/lib/os.nom b/lib/os.nom
index 0644ec8..8c6a153 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -1,33 +1,29 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.2.4.3
#
This file defines some actions that interact with the operating system and filesystem.
use "core"
-
-action [path of Nomsu file %filename]
- lua> ".."
- for i,f in files.walk(\%filename) do return f end
+action [path of Nomsu file %filename]:
+ lua> "for i,f in files.walk(\%filename) do return f end"
barf "Could not find file: \%filename"
-action [sh> %cmd]
+action [sh> %cmd]:
lua> ".."
local result = io.popen(\%cmd)
local contents = result:read("*a")
result:close()
return contents
-action [read file %filename]
- =lua "files.read(\%filename)"
-
-compile [for file %f in %path %body] to
+action [read file %filename] (=lua "files.read(\%filename)")
+compile [for file %f in %path %body] to (..)
Lua ".."
for i,\(%f as lua expr) in files.walk(\(%path as lua expr)) do
\(%body as lua statements)
- \(compile as: === next %f ===)
+ \(compile as (===next %f ===))
end
- \(compile as: === stop %f ===)
+ \(compile as (===stop %f ===))
-compile [%expr for file %f in %path] to
+compile [%expr for file %f in %path] to (..)
Lua value ".."
(function()
local ret = list{}
@@ -37,14 +33,14 @@ compile [%expr for file %f in %path] to
return ret
end)()
-action [write to file %filename %text, to file %filename write %text, write %text to file %filename]
- lua> ".."
- local file = io.open(\%filename, 'w')
- file:write(\%text)
- file:close()
+action [..]
+ write to file %filename %text, to file %filename write %text
+ write %text to file %filename
+..:
+ lua> "local file = io.open(\%filename, 'w')\nfile:write(\%text)\nfile:close()"
-action [line number of %pos in %str]
+action [line number of %pos in %str] (..)
=lua "files.get_line_number(\%str, \%pos)"
-
-action [line %line_num in %str]
+
+action [line %line_num in %str] (..)
=lua "files.get_line(\%str, \%line_num)"
diff --git a/lib/training_wheels.nom b/lib/training_wheels.nom
index 970265c..ea13ac0 100644
--- a/lib/training_wheels.nom
+++ b/lib/training_wheels.nom
@@ -1,45 +1,46 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.2.4.3
#
This file contains a set of definitions that bring some familiar language features
from other languages into nomsu (e.g. "==" and "continue")
use "core"
-parse [%a = %b] as: %a <- %b
-parse [%a == %b] as: %a is %b
-parse [%a ~= %b, %a != %b, %a <> %b] as: %a is not %b
-parse [%a === %b] as: (%a's id) is (%b's id)
-parse [%a !== %b] as: (%a's id) is not (%b's id)
-parse [%a mod %b] as: %a wrapped around %b
-parse [function %names %body, def %names %body] as: action %names %body
-parse [switch %branch_value %body] as: when %branch_value = ? %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 [%thing <- %value] %action
-parse [print %] as: say %
-parse [error!, panic!, fail!, abort!] as: barf!
-parse [error %, panic %, fail %, abort %] as: barf %
-parse [assert %condition %message] as: assume %condition or barf %message
-parse [%cond ? %if_true %if_false] as: %if_true if %cond else %if_false
-compile [function %args %body, lambda %args %body] to
- %lua <-: Lua value "(function("
- for %i = %arg in %args.value
- if: %i > 1
- to %lua write ", "
- to %lua write: %arg as lua expr
+parse [%a = %b] as (%a <- %b)
+parse [%a == %b] as (%a is %b)
+parse [%a ~= %b, %a != %b, %a <> %b] as (%a is not %b)
+parse [%a === %b] as ((%a 's id) is (%b 's id))
+parse [%a !== %b] as ((%a 's id) is not (%b 's id))
+parse [%a mod %b] as (%a wrapped around %b)
+parse [function %names %body, def %names %body] as (action %names %body)
+parse [switch %branch_value %body] as (when %branch_value = ? %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 [%thing <- %value] %action)
+parse [print %] as (say %)
+parse [error!, panic!, fail!, abort!] as (barf!)
+parse [error %, panic %, fail %, abort %] as (barf %)
+parse [assert %condition %message] as (assume %condition or barf %message)
+parse [%cond ? %if_true %if_false] as (%if_true if %cond else %if_false)
+compile [function %args %body, lambda %args %body] to:
+ %lua <- (Lua value "(function(")
+ for %i = %arg in %args.value:
+ if (%i > 1): to %lua write ", "
+ to %lua write (%arg as lua expr)
+
to %lua write ")\n "
- %body <-: %body as lua
+ %body <- (%body as lua)
lua> "\%body:convert_to_statements('return ');"
for % in %args.value: lua> "\%body:remove_free_vars(\%);"
to %lua write %body
to %lua write "\nend)"
return %lua
-parse [function %name %args %body] as: %name <- (function %args %body)
-compile [call %fn %args] to
+
+parse [function %name %args %body] as (%name <- (function %args %body))
+compile [call %fn %args] to (..)
Lua value "\(%fn as lua expr)(unpack(\(%args as lua expr)))"
diff --git a/lib/version.nom b/lib/version.nom
index f90a39c..24ba7a0 100644
--- a/lib/version.nom
+++ b/lib/version.nom
@@ -1,3 +1,3 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.2.4.3
# This file sets the current library version.
-lua> "NOMSU_LIB_VERSION = 3"
+lua> "NOMSU_LIB_VERSION = 3" \ No newline at end of file