gloo-lang 0.9.0 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +2 -2
- data/lib/{gloo_lang.rb → gloo-lang.rb} +7 -9
- data/lib/gloo_lang/app/args.rb +112 -0
- data/lib/gloo_lang/app/engine.rb +230 -0
- data/lib/gloo_lang/app/help.rb +156 -0
- data/lib/gloo_lang/app/log.rb +81 -0
- data/lib/gloo_lang/app/mode.rb +27 -0
- data/lib/gloo_lang/app/settings.rb +186 -0
- data/lib/gloo_lang/convert/converter.rb +35 -0
- data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
- data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
- data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
- data/lib/gloo_lang/core/baseo.rb +30 -0
- data/lib/gloo_lang/core/dictionary.rb +181 -0
- data/lib/gloo_lang/core/error.rb +61 -0
- data/lib/gloo_lang/core/event_manager.rb +44 -0
- data/lib/gloo_lang/core/factory.rb +210 -0
- data/lib/gloo_lang/core/gloo_system.rb +266 -0
- data/lib/gloo_lang/core/heap.rb +52 -0
- data/lib/gloo_lang/core/here.rb +36 -0
- data/lib/gloo_lang/core/it.rb +36 -0
- data/lib/gloo_lang/core/literal.rb +30 -0
- data/lib/gloo_lang/core/obj.rb +303 -0
- data/lib/gloo_lang/core/obj_finder.rb +30 -0
- data/lib/gloo_lang/core/op.rb +40 -0
- data/lib/gloo_lang/core/parser.rb +59 -0
- data/lib/gloo_lang/core/pn.rb +188 -0
- data/lib/gloo_lang/core/tokens.rb +165 -0
- data/lib/gloo_lang/core/verb.rb +86 -0
- data/lib/gloo_lang/exec/action.rb +48 -0
- data/lib/gloo_lang/exec/dispatch.rb +40 -0
- data/lib/gloo_lang/exec/exec_env.rb +74 -0
- data/lib/gloo_lang/exec/runner.rb +45 -0
- data/lib/gloo_lang/exec/script.rb +49 -0
- data/lib/gloo_lang/exec/stack.rb +78 -0
- data/lib/gloo_lang/expr/expression.rb +118 -0
- data/lib/gloo_lang/expr/l_boolean.rb +36 -0
- data/lib/gloo_lang/expr/l_decimal.rb +39 -0
- data/lib/gloo_lang/expr/l_integer.rb +37 -0
- data/lib/gloo_lang/expr/l_string.rb +58 -0
- data/lib/gloo_lang/expr/op_div.rb +22 -0
- data/lib/gloo_lang/expr/op_minus.rb +22 -0
- data/lib/gloo_lang/expr/op_mult.rb +22 -0
- data/lib/gloo_lang/expr/op_plus.rb +24 -0
- data/lib/gloo_lang/help/app/application.txt +22 -0
- data/lib/gloo_lang/help/app/configuration.txt +7 -0
- data/lib/gloo_lang/help/app/default_help.txt +14 -0
- data/lib/gloo_lang/help/app/logging.txt +16 -0
- data/lib/gloo_lang/help/core/color.txt +31 -0
- data/lib/gloo_lang/help/core/error.txt +33 -0
- data/lib/gloo_lang/help/core/events.txt +21 -0
- data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
- data/lib/gloo_lang/help/core/here.txt +30 -0
- data/lib/gloo_lang/help/core/it.txt +23 -0
- data/lib/gloo_lang/help/core/ops.txt +16 -0
- data/lib/gloo_lang/help/core/pathname.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
- data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
- data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
- data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
- data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
- data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
- data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
- data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
- data/lib/gloo_lang/help/objs/data/query.txt +37 -0
- data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
- data/lib/gloo_lang/help/objs/data/table.txt +46 -0
- data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
- data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
- data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
- data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
- data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
- data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
- data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
- data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
- data/lib/gloo_lang/help/objs/system/file.txt +48 -0
- data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
- data/lib/gloo_lang/help/objs/system/system.txt +32 -0
- data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
- data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
- data/lib/gloo_lang/help/objs/web/json.txt +34 -0
- data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
- data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
- data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
- data/lib/gloo_lang/help/verbs/alert.txt +33 -0
- data/lib/gloo_lang/help/verbs/beep.txt +25 -0
- data/lib/gloo_lang/help/verbs/cls.txt +24 -0
- data/lib/gloo_lang/help/verbs/context.txt +43 -0
- data/lib/gloo_lang/help/verbs/create.txt +33 -0
- data/lib/gloo_lang/help/verbs/execute.txt +27 -0
- data/lib/gloo_lang/help/verbs/help.txt +34 -0
- data/lib/gloo_lang/help/verbs/if.txt +37 -0
- data/lib/gloo_lang/help/verbs/list.txt +34 -0
- data/lib/gloo_lang/help/verbs/load.txt +38 -0
- data/lib/gloo_lang/help/verbs/move.txt +42 -0
- data/lib/gloo_lang/help/verbs/put.txt +38 -0
- data/lib/gloo_lang/help/verbs/quit.txt +25 -0
- data/lib/gloo_lang/help/verbs/run.txt +41 -0
- data/lib/gloo_lang/help/verbs/save.txt +26 -0
- data/lib/gloo_lang/help/verbs/show.txt +30 -0
- data/lib/gloo_lang/help/verbs/tell.txt +34 -0
- data/lib/gloo_lang/help/verbs/unless.txt +38 -0
- data/lib/gloo_lang/help/verbs/version.txt +32 -0
- data/lib/gloo_lang/help/verbs/wait.txt +29 -0
- data/lib/gloo_lang/objs/basic/alias.rb +78 -0
- data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
- data/lib/gloo_lang/objs/basic/container.rb +76 -0
- data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
- data/lib/gloo_lang/objs/basic/integer.rb +73 -0
- data/lib/gloo_lang/objs/basic/script.rb +99 -0
- data/lib/gloo_lang/objs/basic/string.rb +77 -0
- data/lib/gloo_lang/objs/basic/text.rb +87 -0
- data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
- data/lib/gloo_lang/objs/cli/banner.rb +108 -0
- data/lib/gloo_lang/objs/cli/bar.rb +133 -0
- data/lib/gloo_lang/objs/cli/colorize.rb +73 -0
- data/lib/gloo_lang/objs/cli/confirm.rb +96 -0
- data/lib/gloo_lang/objs/cli/menu.rb +206 -0
- data/lib/gloo_lang/objs/cli/menu_item.rb +95 -0
- data/lib/gloo_lang/objs/cli/pastel.rb +97 -0
- data/lib/gloo_lang/objs/cli/prompt.rb +110 -0
- data/lib/gloo_lang/objs/cli/select.rb +126 -0
- data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
- data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
- data/lib/gloo_lang/objs/data/markdown.rb +84 -0
- data/lib/gloo_lang/objs/data/mysql.rb +192 -0
- data/lib/gloo_lang/objs/data/query.rb +176 -0
- data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
- data/lib/gloo_lang/objs/data/table.rb +140 -0
- data/lib/gloo_lang/objs/dev/git.rb +140 -0
- data/lib/gloo_lang/objs/dev/stats.rb +120 -0
- data/lib/gloo_lang/objs/dt/date.rb +50 -0
- data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
- data/lib/gloo_lang/objs/dt/time.rb +50 -0
- data/lib/gloo_lang/objs/ror/erb.rb +116 -0
- data/lib/gloo_lang/objs/ror/eval.rb +107 -0
- data/lib/gloo_lang/objs/snd/play.rb +48 -0
- data/lib/gloo_lang/objs/snd/say.rb +98 -0
- data/lib/gloo_lang/objs/system/file_handle.rb +138 -0
- data/lib/gloo_lang/objs/system/ssh_exec.rb +126 -0
- data/lib/gloo_lang/objs/system/system.rb +136 -0
- data/lib/gloo_lang/objs/web/http_get.rb +159 -0
- data/lib/gloo_lang/objs/web/http_post.rb +183 -0
- data/lib/gloo_lang/objs/web/json.rb +135 -0
- data/lib/gloo_lang/objs/web/slack.rb +130 -0
- data/lib/gloo_lang/objs/web/teams.rb +117 -0
- data/lib/gloo_lang/objs/web/uri.rb +148 -0
- data/lib/gloo_lang/persist/file_loader.rb +191 -0
- data/lib/gloo_lang/persist/file_saver.rb +49 -0
- data/lib/gloo_lang/persist/file_storage.rb +45 -0
- data/lib/gloo_lang/persist/line_splitter.rb +81 -0
- data/lib/gloo_lang/persist/persist_man.rb +120 -0
- data/lib/gloo_lang/utils/format.rb +21 -0
- data/lib/gloo_lang/utils/stats.rb +205 -0
- data/lib/gloo_lang/utils/words.rb +19 -0
- data/lib/gloo_lang/verbs/alert.rb +79 -0
- data/lib/gloo_lang/verbs/beep.rb +40 -0
- data/lib/gloo_lang/verbs/cls.rb +37 -0
- data/lib/gloo_lang/verbs/context.rb +62 -0
- data/lib/gloo_lang/verbs/create.rb +68 -0
- data/lib/gloo_lang/verbs/execute.rb +56 -0
- data/lib/gloo_lang/verbs/help.rb +264 -0
- data/lib/gloo_lang/verbs/if.rb +92 -0
- data/lib/gloo_lang/verbs/list.rb +98 -0
- data/lib/gloo_lang/verbs/load.rb +45 -0
- data/lib/gloo_lang/verbs/move.rb +89 -0
- data/lib/gloo_lang/verbs/put.rb +94 -0
- data/lib/gloo_lang/verbs/quit.rb +40 -0
- data/lib/gloo_lang/verbs/run.rb +75 -0
- data/lib/gloo_lang/verbs/save.rb +39 -0
- data/lib/gloo_lang/verbs/show.rb +64 -0
- data/lib/gloo_lang/verbs/tell.rb +79 -0
- data/lib/gloo_lang/verbs/unless.rb +92 -0
- data/lib/gloo_lang/verbs/version.rb +37 -0
- data/lib/gloo_lang/verbs/wait.rb +42 -0
- metadata +191 -3
@@ -0,0 +1,78 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A String.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Objs
|
9
|
+
class Alias < GlooLang::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'alias'.freeze
|
12
|
+
KEYWORD_SHORT = 'ln'.freeze
|
13
|
+
ALIAS_REFERENCE = '*'.freeze
|
14
|
+
|
15
|
+
#
|
16
|
+
# The name of the object type.
|
17
|
+
#
|
18
|
+
def self.typename
|
19
|
+
return KEYWORD
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# The short name of the object type.
|
24
|
+
#
|
25
|
+
def self.short_typename
|
26
|
+
return KEYWORD_SHORT
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Set the value with any necessary type conversions.
|
31
|
+
#
|
32
|
+
def set_value( new_value )
|
33
|
+
self.value = new_value.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
# ---------------------------------------------------------------------
|
37
|
+
# Messages
|
38
|
+
# ---------------------------------------------------------------------
|
39
|
+
|
40
|
+
#
|
41
|
+
# Get a list of message names that this object receives.
|
42
|
+
#
|
43
|
+
def self.messages
|
44
|
+
return super + %w[resolve]
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Check to see if the referenced object exists.
|
49
|
+
#
|
50
|
+
def msg_resolve
|
51
|
+
pn = GlooLang::Core::Pn.new( self.value )
|
52
|
+
s = pn.exists?
|
53
|
+
$engine.heap.it.set_to s
|
54
|
+
return s
|
55
|
+
end
|
56
|
+
|
57
|
+
# ---------------------------------------------------------------------
|
58
|
+
# Resolve
|
59
|
+
# ---------------------------------------------------------------------
|
60
|
+
|
61
|
+
#
|
62
|
+
# Is the object an alias If so, then resolve it.
|
63
|
+
# The ref_name is the name used to refer to the object.
|
64
|
+
# If it ends with the * then we won't resolve the alias since
|
65
|
+
# we are trying to refer to the alias itself.
|
66
|
+
#
|
67
|
+
def self.resolve_alias( obj, ref_name = nil )
|
68
|
+
return nil unless obj
|
69
|
+
return obj unless obj.type_display == GlooLang::Objs::Alias.typename
|
70
|
+
return obj if ref_name&.end_with?( ALIAS_REFERENCE )
|
71
|
+
|
72
|
+
ln = GlooLang::Core::Pn.new( obj.value )
|
73
|
+
return ln.resolve
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An object with an boolean value.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Objs
|
9
|
+
class Boolean < GlooLang::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'boolean'.freeze
|
12
|
+
KEYWORD_SHORT = 'bool'.freeze
|
13
|
+
TRUE = 'true'.freeze
|
14
|
+
FALSE = 'false'.freeze
|
15
|
+
|
16
|
+
#
|
17
|
+
# The name of the object type.
|
18
|
+
#
|
19
|
+
def self.typename
|
20
|
+
return KEYWORD
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# The short name of the object type.
|
25
|
+
#
|
26
|
+
def self.short_typename
|
27
|
+
return KEYWORD_SHORT
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Set the value with any necessary type conversions.
|
32
|
+
#
|
33
|
+
def set_value( new_value )
|
34
|
+
self.value = GlooLang::Objs::Boolean.coerse_to_bool( new_value )
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Coerse the new value to a boolean value.
|
39
|
+
#
|
40
|
+
def self.coerse_to_bool( new_value )
|
41
|
+
return false if new_value.nil?
|
42
|
+
|
43
|
+
# I should be able to use this:
|
44
|
+
# if new_value.kind_of?( String )
|
45
|
+
# but it doesn't work. I don't know why.
|
46
|
+
if new_value.class.name == 'String'
|
47
|
+
return true if new_value.strip.downcase == TRUE
|
48
|
+
return false if new_value.strip.downcase == FALSE
|
49
|
+
return true if new_value.strip.downcase == 't'
|
50
|
+
return false if new_value.strip.downcase == 'f'
|
51
|
+
elsif new_value.class.name == 'Integer'
|
52
|
+
return new_value.zero? ? false : true
|
53
|
+
end
|
54
|
+
|
55
|
+
return new_value == true
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Is the given token a boolean?
|
60
|
+
#
|
61
|
+
def self.boolean?( token )
|
62
|
+
return true if token == true
|
63
|
+
return true if token == false
|
64
|
+
|
65
|
+
if token.class.name == 'String'
|
66
|
+
return true if token.strip.downcase == TRUE
|
67
|
+
return true if token.strip.downcase == FALSE
|
68
|
+
end
|
69
|
+
return false
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Get the value for display purposes.
|
74
|
+
#
|
75
|
+
def value_display
|
76
|
+
return value ? TRUE : FALSE
|
77
|
+
end
|
78
|
+
|
79
|
+
# ---------------------------------------------------------------------
|
80
|
+
# Messages
|
81
|
+
# ---------------------------------------------------------------------
|
82
|
+
|
83
|
+
#
|
84
|
+
# Get a list of message names that this object receives.
|
85
|
+
#
|
86
|
+
def self.messages
|
87
|
+
return super + %w[not true false]
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Set the value to the opposite of what it is.
|
92
|
+
#
|
93
|
+
def msg_not
|
94
|
+
v = !value
|
95
|
+
set_value v
|
96
|
+
$engine.heap.it.set_to v
|
97
|
+
return v
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Set the value to true.
|
102
|
+
#
|
103
|
+
def msg_true
|
104
|
+
set_value true
|
105
|
+
$engine.heap.it.set_to true
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Set the value to false.
|
111
|
+
#
|
112
|
+
def msg_false
|
113
|
+
set_value false
|
114
|
+
$engine.heap.it.set_to false
|
115
|
+
return false
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An object that contains a collection of other objects.
|
5
|
+
#
|
6
|
+
require 'tty-table'
|
7
|
+
require 'pastel'
|
8
|
+
|
9
|
+
module GlooLang
|
10
|
+
module Objs
|
11
|
+
class Container < GlooLang::Core::Obj
|
12
|
+
|
13
|
+
KEYWORD = 'container'.freeze
|
14
|
+
KEYWORD_SHORT = 'can'.freeze
|
15
|
+
|
16
|
+
#
|
17
|
+
# The name of the object type.
|
18
|
+
#
|
19
|
+
def self.typename
|
20
|
+
return KEYWORD
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# The short name of the object type.
|
25
|
+
#
|
26
|
+
def self.short_typename
|
27
|
+
return KEYWORD_SHORT
|
28
|
+
end
|
29
|
+
|
30
|
+
# ---------------------------------------------------------------------
|
31
|
+
# Messages
|
32
|
+
# ---------------------------------------------------------------------
|
33
|
+
|
34
|
+
#
|
35
|
+
# Get a list of message names that this object receives.
|
36
|
+
#
|
37
|
+
def self.messages
|
38
|
+
return super + %w[count delete_children show_key_value_table]
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Count the number of children in the container.
|
43
|
+
#
|
44
|
+
def msg_count
|
45
|
+
i = child_count
|
46
|
+
$engine.heap.it.set_to i
|
47
|
+
return i
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Delete all children in the container.
|
52
|
+
#
|
53
|
+
def msg_delete_children
|
54
|
+
self.delete_children
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Show the given table data.
|
59
|
+
#
|
60
|
+
def msg_show_key_value_table
|
61
|
+
data = self.children.map { |o| [ o.name, o.value ] }
|
62
|
+
pastel = ::Pastel.new
|
63
|
+
table = TTY::Table.new rows: data
|
64
|
+
pad = [ 0, 1, 0, 1 ]
|
65
|
+
rendered = table.render( :ascii, indent: 2, padding: pad ) do |r|
|
66
|
+
r.border.style = :blue
|
67
|
+
r.filter = proc do |val, _row_index, col_index|
|
68
|
+
col_index.zero? ? pastel.blue( val ) : pastel.white( val )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
puts "\n #{rendered}\n\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An object with a decimal value.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Objs
|
9
|
+
class Decimal < GlooLang::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'decimal'.freeze
|
12
|
+
KEYWORD_SHORT = 'num'.freeze
|
13
|
+
|
14
|
+
#
|
15
|
+
# The name of the object type.
|
16
|
+
#
|
17
|
+
def self.typename
|
18
|
+
return KEYWORD
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The short name of the object type.
|
23
|
+
#
|
24
|
+
def self.short_typename
|
25
|
+
return KEYWORD_SHORT
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Set the value with any necessary type conversions.
|
30
|
+
#
|
31
|
+
def set_value( new_value )
|
32
|
+
if new_value.nil?
|
33
|
+
self.value = 0.0
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
unless new_value.is_a? Numeric
|
38
|
+
self.value = $engine.converter.convert( new_value, 'Decimal', 0.0 )
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
self.value = new_value.to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
# ---------------------------------------------------------------------
|
46
|
+
# Messages
|
47
|
+
# ---------------------------------------------------------------------
|
48
|
+
|
49
|
+
#
|
50
|
+
# Get a list of message names that this object receives.
|
51
|
+
#
|
52
|
+
def self.messages
|
53
|
+
return super + %w[round]
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Round the value to a whole value.
|
58
|
+
# If a parameter is included in the message,
|
59
|
+
# round to the precision given.
|
60
|
+
#
|
61
|
+
def msg_round
|
62
|
+
data = 0
|
63
|
+
if @params&.token_count&.positive?
|
64
|
+
expr = GlooLang::Expr::Expression.new( @params.tokens )
|
65
|
+
data = expr.evaluate.to_i
|
66
|
+
end
|
67
|
+
|
68
|
+
i = self.value.round( data )
|
69
|
+
set_value i
|
70
|
+
$engine.heap.it.set_to i
|
71
|
+
return i
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An object with an integer value.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Objs
|
9
|
+
class Integer < GlooLang::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'integer'.freeze
|
12
|
+
KEYWORD_SHORT = 'int'.freeze
|
13
|
+
|
14
|
+
#
|
15
|
+
# The name of the object type.
|
16
|
+
#
|
17
|
+
def self.typename
|
18
|
+
return KEYWORD
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The short name of the object type.
|
23
|
+
#
|
24
|
+
def self.short_typename
|
25
|
+
return KEYWORD_SHORT
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Set the value with any necessary type conversions.
|
30
|
+
#
|
31
|
+
def set_value( new_value )
|
32
|
+
unless new_value.is_a? Numeric
|
33
|
+
self.value = $engine.converter.convert( new_value, 'Integer', 0 )
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
self.value = new_value.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
# ---------------------------------------------------------------------
|
41
|
+
# Messages
|
42
|
+
# ---------------------------------------------------------------------
|
43
|
+
|
44
|
+
#
|
45
|
+
# Get a list of message names that this object receives.
|
46
|
+
#
|
47
|
+
def self.messages
|
48
|
+
return super + %w[inc dec]
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Increment the integer
|
53
|
+
#
|
54
|
+
def msg_inc
|
55
|
+
i = value + 1
|
56
|
+
set_value i
|
57
|
+
$engine.heap.it.set_to i
|
58
|
+
return i
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Decrement the integer
|
63
|
+
#
|
64
|
+
def msg_dec
|
65
|
+
i = value - 1
|
66
|
+
set_value i
|
67
|
+
$engine.heap.it.set_to i
|
68
|
+
return i
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A Script.
|
5
|
+
# A set of commands to be run.
|
6
|
+
#
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Objs
|
10
|
+
class Script < GlooLang::Core::Obj
|
11
|
+
|
12
|
+
KEYWORD = 'script'.freeze
|
13
|
+
KEYWORD_SHORT = 'cmd'.freeze
|
14
|
+
|
15
|
+
#
|
16
|
+
# The name of the object type.
|
17
|
+
#
|
18
|
+
def self.typename
|
19
|
+
return KEYWORD
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# The short name of the object type.
|
24
|
+
#
|
25
|
+
def self.short_typename
|
26
|
+
return KEYWORD_SHORT
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Set the value with any necessary type conversions.
|
31
|
+
#
|
32
|
+
def set_value( new_value )
|
33
|
+
self.value = new_value.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Set the value as an array.
|
38
|
+
#
|
39
|
+
def set_array_value( arr )
|
40
|
+
self.value = arr
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Add a line (cmd) to the script.
|
45
|
+
#
|
46
|
+
def add_line( line )
|
47
|
+
if self.value_string?
|
48
|
+
first = self.value
|
49
|
+
self.set_array_value []
|
50
|
+
self.value << first unless first.empty?
|
51
|
+
elsif self.value_is_blank?
|
52
|
+
self.set_array_value []
|
53
|
+
end
|
54
|
+
self.value << line.strip
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Does this object support multi-line values?
|
59
|
+
# Initially only true for scripts.
|
60
|
+
#
|
61
|
+
def multiline_value?
|
62
|
+
return true
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Get the number of lines in this script.
|
67
|
+
#
|
68
|
+
def line_count
|
69
|
+
return self.value.count if self.value_is_array?
|
70
|
+
|
71
|
+
if self.value_string?
|
72
|
+
return self.value.strip.empty? ? 0 : 1
|
73
|
+
end
|
74
|
+
|
75
|
+
return 0
|
76
|
+
end
|
77
|
+
|
78
|
+
# ---------------------------------------------------------------------
|
79
|
+
# Messages
|
80
|
+
# ---------------------------------------------------------------------
|
81
|
+
|
82
|
+
#
|
83
|
+
# Get a list of message names that this object receives.
|
84
|
+
#
|
85
|
+
def self.messages
|
86
|
+
return super + [ 'run' ]
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Send the object the unload message.
|
91
|
+
#
|
92
|
+
def msg_run
|
93
|
+
s = GlooLang::Exec::Script.new self
|
94
|
+
s.run
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A String.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Objs
|
9
|
+
class String < GlooLang::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'string'.freeze
|
12
|
+
KEYWORD_SHORT = 'str'.freeze
|
13
|
+
|
14
|
+
#
|
15
|
+
# The name of the object type.
|
16
|
+
#
|
17
|
+
def self.typename
|
18
|
+
return KEYWORD
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The short name of the object type.
|
23
|
+
#
|
24
|
+
def self.short_typename
|
25
|
+
return KEYWORD_SHORT
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Set the value with any necessary type conversions.
|
30
|
+
#
|
31
|
+
def set_value( new_value )
|
32
|
+
self.value = new_value.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
# ---------------------------------------------------------------------
|
36
|
+
# Messages
|
37
|
+
# ---------------------------------------------------------------------
|
38
|
+
|
39
|
+
#
|
40
|
+
# Get a list of message names that this object receives.
|
41
|
+
#
|
42
|
+
def self.messages
|
43
|
+
return super + %w[up down size]
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Get the size of the string.
|
48
|
+
#
|
49
|
+
def msg_size
|
50
|
+
s = value.size
|
51
|
+
$engine.heap.it.set_to s
|
52
|
+
return s
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Convert string to upper case
|
57
|
+
#
|
58
|
+
def msg_up
|
59
|
+
s = value.upcase
|
60
|
+
set_value s
|
61
|
+
$engine.heap.it.set_to s
|
62
|
+
return s
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Convert string to lower case
|
67
|
+
#
|
68
|
+
def msg_down
|
69
|
+
s = value.downcase
|
70
|
+
set_value s
|
71
|
+
$engine.heap.it.set_to s
|
72
|
+
return s
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A [multiline] block of text.
|
5
|
+
#
|
6
|
+
require 'tty-editor'
|
7
|
+
require 'tty-pager'
|
8
|
+
|
9
|
+
module GlooLang
|
10
|
+
module Objs
|
11
|
+
class Text < GlooLang::Core::Obj
|
12
|
+
|
13
|
+
KEYWORD = 'text'.freeze
|
14
|
+
KEYWORD_SHORT = 'txt'.freeze
|
15
|
+
DEFAULT_TMP_FILE = 'tmp.txt'.freeze
|
16
|
+
|
17
|
+
#
|
18
|
+
# The name of the object type.
|
19
|
+
#
|
20
|
+
def self.typename
|
21
|
+
return KEYWORD
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# The short name of the object type.
|
26
|
+
#
|
27
|
+
def self.short_typename
|
28
|
+
return KEYWORD_SHORT
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Set the value with any necessary type conversions.
|
33
|
+
#
|
34
|
+
def set_value( new_value )
|
35
|
+
self.value = new_value.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Does this object support multi-line values?
|
40
|
+
# Initially only true for scripts.
|
41
|
+
#
|
42
|
+
def multiline_value?
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Get the number of lines of text.
|
48
|
+
#
|
49
|
+
def line_count
|
50
|
+
return value.split( "\n" ).count
|
51
|
+
end
|
52
|
+
|
53
|
+
# ---------------------------------------------------------------------
|
54
|
+
# Messages
|
55
|
+
# ---------------------------------------------------------------------
|
56
|
+
|
57
|
+
#
|
58
|
+
# Get a list of message names that this object receives.
|
59
|
+
#
|
60
|
+
def self.messages
|
61
|
+
return super + %w[edit page]
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Show the contents of the file, paginated.
|
66
|
+
#
|
67
|
+
def msg_page
|
68
|
+
return unless value
|
69
|
+
|
70
|
+
# pager = TTY::Pager::SystemPager.new command: 'less -R'
|
71
|
+
pager = TTY::Pager.new
|
72
|
+
pager.page( value )
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Edit the text in the default editor.
|
77
|
+
#
|
78
|
+
def msg_edit
|
79
|
+
tmp = File.join( $settings.tmp_path, DEFAULT_TMP_FILE )
|
80
|
+
File.open( tmp, 'w' ) { |file| file.write( self.value ) }
|
81
|
+
TTY::Editor.open( tmp )
|
82
|
+
set_value File.read( tmp )
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|