gloo 0.5.4 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/gloo/app/args.rb +48 -6
- data/lib/gloo/app/engine.rb +60 -38
- data/lib/gloo/app/help.rb +137 -16
- data/lib/gloo/app/info.rb +3 -1
- data/lib/gloo/app/log.rb +23 -0
- data/lib/gloo/app/mode.rb +2 -0
- data/lib/gloo/app/settings.rb +98 -47
- data/lib/gloo/convert/converter.rb +35 -0
- data/lib/gloo/convert/string_to_datetime.rb +1 -1
- data/lib/gloo/convert/string_to_decimal.rb +1 -1
- data/lib/gloo/convert/string_to_integer.rb +1 -1
- data/lib/gloo/core/dictionary.rb +99 -22
- data/lib/gloo/core/error.rb +19 -8
- data/lib/gloo/core/event_manager.rb +4 -0
- data/lib/gloo/core/factory.rb +11 -0
- data/lib/gloo/core/gloo_system.rb +1 -1
- data/lib/gloo/core/heap.rb +11 -3
- data/lib/gloo/core/here.rb +36 -0
- data/lib/gloo/core/it.rb +6 -0
- data/lib/gloo/core/literal.rb +5 -0
- data/lib/gloo/core/obj.rb +22 -0
- data/lib/gloo/core/op.rb +7 -0
- data/lib/gloo/core/parser.rb +6 -0
- data/lib/gloo/core/pn.rb +38 -0
- data/lib/gloo/core/tokens.rb +66 -22
- data/lib/gloo/core/verb.rb +12 -0
- data/lib/gloo/exec/action.rb +48 -0
- data/lib/gloo/exec/dispatch.rb +15 -5
- data/lib/gloo/exec/exec_env.rb +74 -0
- data/lib/gloo/exec/runner.rb +4 -2
- data/lib/gloo/{core → exec}/script.rb +21 -9
- data/lib/gloo/exec/stack.rb +78 -0
- data/lib/gloo/expr/expression.rb +26 -4
- data/lib/gloo/expr/l_boolean.rb +6 -0
- data/lib/gloo/expr/l_decimal.rb +5 -0
- data/lib/gloo/expr/l_integer.rb +7 -0
- data/lib/gloo/expr/l_string.rb +7 -0
- data/lib/gloo/expr/op_div.rb +2 -0
- data/lib/gloo/expr/op_minus.rb +2 -0
- data/lib/gloo/expr/op_mult.rb +2 -0
- data/lib/gloo/expr/op_plus.rb +2 -0
- data/lib/gloo/help/app/application.txt +22 -0
- data/lib/gloo/help/app/configuration.txt +7 -0
- data/lib/gloo/help/app/default_help.txt +14 -0
- data/lib/gloo/help/app/logging.txt +16 -0
- data/lib/gloo/help/core/color.txt +31 -0
- data/lib/gloo/help/core/error.txt +33 -0
- data/lib/gloo/help/core/events.txt +21 -0
- data/lib/gloo/help/core/gloo_system.txt +54 -0
- data/lib/gloo/help/core/here.txt +30 -0
- data/lib/gloo/help/core/it.txt +23 -0
- data/lib/gloo/help/core/ops.txt +16 -0
- data/lib/gloo/help/core/pathname.txt +29 -0
- data/lib/gloo/help/objs/basic/alias.txt +36 -0
- data/lib/gloo/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo/help/objs/basic/container.txt +33 -0
- data/lib/gloo/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo/help/objs/basic/integer.txt +27 -0
- data/lib/gloo/help/objs/basic/script.txt +29 -0
- data/lib/gloo/help/objs/basic/string.txt +28 -0
- data/lib/gloo/help/objs/basic/text.txt +27 -0
- data/lib/gloo/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo/help/objs/cli/banner.txt +49 -0
- data/lib/gloo/help/objs/cli/bar.txt +34 -0
- data/lib/gloo/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo/help/objs/cli/menu.txt +44 -0
- data/lib/gloo/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo/help/objs/cli/select.txt +34 -0
- data/lib/gloo/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo/help/objs/data/markdown.txt +25 -0
- data/lib/gloo/help/objs/data/table.txt +46 -0
- data/lib/gloo/help/objs/dev/git_repo.txt +35 -0
- data/lib/gloo/help/objs/dt/date.txt +23 -0
- data/lib/gloo/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo/help/objs/dt/time.txt +23 -0
- data/lib/gloo/help/objs/ror/erb.txt +37 -0
- data/lib/gloo/help/objs/ror/eval.txt +24 -0
- data/lib/gloo/help/objs/snd/play.txt +23 -0
- data/lib/gloo/help/objs/snd/say.txt +28 -0
- data/lib/gloo/help/objs/system/file.txt +41 -0
- data/lib/gloo/help/objs/system/system.txt +32 -0
- data/lib/gloo/help/objs/web/http_get.txt +35 -0
- data/lib/gloo/help/objs/web/http_post.txt +32 -0
- data/lib/gloo/help/objs/web/json.txt +34 -0
- data/lib/gloo/help/objs/web/slack.txt +33 -0
- data/lib/gloo/help/objs/web/teams.txt +30 -0
- data/lib/gloo/help/objs/web/uri.txt +37 -0
- data/lib/gloo/help/verbs/alert.txt +33 -0
- data/lib/gloo/help/verbs/beep.txt +25 -0
- data/lib/gloo/help/verbs/cls.txt +24 -0
- data/lib/gloo/help/verbs/context.txt +43 -0
- data/lib/gloo/help/verbs/create.txt +33 -0
- data/lib/gloo/help/verbs/execute.txt +27 -0
- data/lib/gloo/help/verbs/help.txt +34 -0
- data/lib/gloo/help/verbs/if.txt +37 -0
- data/lib/gloo/help/verbs/list.txt +34 -0
- data/lib/gloo/help/verbs/load.txt +38 -0
- data/lib/gloo/help/verbs/move.txt +42 -0
- data/lib/gloo/help/verbs/put.txt +38 -0
- data/lib/gloo/help/verbs/quit.txt +25 -0
- data/lib/gloo/help/verbs/run.txt +41 -0
- data/lib/gloo/help/verbs/save.txt +26 -0
- data/lib/gloo/help/verbs/show.txt +30 -0
- data/lib/gloo/help/verbs/tell.txt +34 -0
- data/lib/gloo/help/verbs/unless.txt +38 -0
- data/lib/gloo/help/verbs/version.txt +32 -0
- data/lib/gloo/help/verbs/wait.txt +29 -0
- data/lib/gloo/objs/basic/alias.rb +0 -33
- data/lib/gloo/objs/basic/boolean.rb +6 -27
- data/lib/gloo/objs/basic/container.rb +0 -33
- data/lib/gloo/objs/basic/decimal.rb +8 -28
- data/lib/gloo/objs/basic/integer.rb +5 -26
- data/lib/gloo/objs/basic/script.rb +1 -27
- data/lib/gloo/objs/basic/string.rb +6 -26
- data/lib/gloo/objs/basic/text.rb +0 -25
- data/lib/gloo/objs/basic/untyped.rb +0 -26
- data/lib/gloo/objs/cli/banner.rb +0 -29
- data/lib/gloo/objs/cli/bar.rb +0 -29
- data/lib/gloo/objs/cli/colorize.rb +4 -34
- data/lib/gloo/objs/cli/confirm.rb +6 -36
- data/lib/gloo/objs/cli/menu.rb +6 -36
- data/lib/gloo/objs/cli/menu_item.rb +0 -33
- data/lib/gloo/objs/cli/pastel.rb +4 -27
- data/lib/gloo/objs/cli/prompt.rb +4 -28
- data/lib/gloo/objs/cli/select.rb +4 -31
- data/lib/gloo/objs/ctrl/each.rb +33 -33
- data/lib/gloo/objs/ctrl/repeat.rb +8 -29
- data/lib/gloo/objs/data/markdown.rb +0 -25
- data/lib/gloo/objs/data/table.rb +4 -32
- data/lib/gloo/objs/dev/git.rb +12 -30
- data/lib/gloo/objs/dt/date.rb +3 -25
- data/lib/gloo/objs/dt/datetime.rb +4 -26
- data/lib/gloo/objs/dt/time.rb +3 -25
- data/lib/gloo/objs/ror/erb.rb +11 -45
- data/lib/gloo/objs/ror/eval.rb +11 -38
- data/lib/gloo/objs/snd/play.rb +2 -25
- data/lib/gloo/objs/snd/say.rb +9 -31
- data/lib/gloo/objs/system/file_handle.rb +0 -38
- data/lib/gloo/objs/system/system.rb +16 -46
- data/lib/gloo/objs/web/http_get.rb +57 -83
- data/lib/gloo/objs/web/http_post.rb +8 -31
- data/lib/gloo/objs/web/json.rb +11 -31
- data/lib/gloo/objs/web/slack.rb +7 -34
- data/lib/gloo/objs/web/teams.rb +13 -48
- data/lib/gloo/objs/web/uri.rb +0 -29
- data/lib/gloo/persist/file_loader.rb +8 -0
- data/lib/gloo/persist/file_saver.rb +6 -0
- data/lib/gloo/persist/file_storage.rb +2 -0
- data/lib/gloo/persist/line_splitter.rb +2 -0
- data/lib/gloo/persist/persist_man.rb +6 -0
- data/lib/gloo/verbs/alert.rb +30 -44
- data/lib/gloo/verbs/beep.rb +0 -30
- data/lib/gloo/verbs/cls.rb +0 -30
- data/lib/gloo/verbs/context.rb +9 -39
- data/lib/gloo/verbs/create.rb +17 -32
- data/lib/gloo/verbs/execute.rb +52 -0
- data/lib/gloo/verbs/help.rb +151 -115
- data/lib/gloo/verbs/if.rb +46 -44
- data/lib/gloo/verbs/list.rb +36 -54
- data/lib/gloo/verbs/load.rb +8 -37
- data/lib/gloo/verbs/move.rb +12 -51
- data/lib/gloo/verbs/put.rb +28 -52
- data/lib/gloo/verbs/quit.rb +0 -31
- data/lib/gloo/verbs/run.rb +23 -39
- data/lib/gloo/verbs/save.rb +0 -33
- data/lib/gloo/verbs/show.rb +6 -31
- data/lib/gloo/verbs/tell.rb +31 -31
- data/lib/gloo/verbs/unless.rb +47 -46
- data/lib/gloo/verbs/version.rb +0 -30
- data/lib/gloo/verbs/wait.rb +0 -31
- metadata +79 -3
data/lib/gloo/verbs/if.rb
CHANGED
@@ -11,31 +11,18 @@ module Gloo
|
|
11
11
|
KEYWORD = 'if'.freeze
|
12
12
|
KEYWORD_SHORT = 'if'.freeze
|
13
13
|
THEN = 'then'.freeze
|
14
|
+
MISSING_EXPR_ERR = 'Missing Expression!'.freeze
|
14
15
|
|
15
16
|
#
|
16
17
|
# Run the verb.
|
17
18
|
#
|
18
19
|
def run
|
19
|
-
value =
|
20
|
-
if value.
|
21
|
-
# The first token is the verb, so we drop it.
|
22
|
-
value = value[ 1..-1 ]
|
23
|
-
end
|
20
|
+
value = value_tokens
|
21
|
+
return if value.nil?
|
24
22
|
|
25
|
-
evals_true
|
26
|
-
if value.count.positive?
|
27
|
-
expr = Gloo::Expr::Expression.new( value )
|
28
|
-
result = expr.evaluate
|
29
|
-
evals_true = true if result == true
|
30
|
-
evals_true = true if result.is_a?( Numeric ) && result != 0
|
31
|
-
end
|
32
|
-
return unless evals_true
|
23
|
+
return unless evals_true( value )
|
33
24
|
|
34
|
-
|
35
|
-
i = $engine.parser.parse_immediate cmd
|
36
|
-
return unless i
|
37
|
-
|
38
|
-
i.run
|
25
|
+
run_then
|
39
26
|
end
|
40
27
|
|
41
28
|
#
|
@@ -53,36 +40,51 @@ module Gloo
|
|
53
40
|
end
|
54
41
|
|
55
42
|
# ---------------------------------------------------------------------
|
56
|
-
#
|
43
|
+
# Private functions
|
57
44
|
# ---------------------------------------------------------------------
|
58
45
|
|
46
|
+
private
|
47
|
+
|
59
48
|
#
|
60
|
-
# Get
|
49
|
+
# Get the list of tokens that represent the parameters
|
50
|
+
# of the if command.
|
61
51
|
#
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
52
|
+
def value_tokens
|
53
|
+
value = @tokens.before_token( THEN )
|
54
|
+
if value && value.count > 1
|
55
|
+
# The first token is the verb, so we drop it.
|
56
|
+
value = value[ 1..-1 ]
|
57
|
+
else
|
58
|
+
$engine.err MISSING_EXPR_ERR
|
59
|
+
end
|
60
|
+
|
61
|
+
return value
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Does the given value evalute to true?
|
66
|
+
#
|
67
|
+
def evals_true( value )
|
68
|
+
eval_result = false
|
69
|
+
if value.count.positive?
|
70
|
+
expr = Gloo::Expr::Expression.new( value )
|
71
|
+
result = expr.evaluate
|
72
|
+
eval_result = true if result == true
|
73
|
+
eval_result = true if result.is_a?( Numeric ) && result != 0
|
74
|
+
end
|
75
|
+
|
76
|
+
return eval_result
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Run the 'then' command.
|
81
|
+
#
|
82
|
+
def run_then
|
83
|
+
cmd = @tokens.expr_after( THEN )
|
84
|
+
i = $engine.parser.parse_immediate cmd
|
85
|
+
return unless i
|
86
|
+
|
87
|
+
i.run
|
86
88
|
end
|
87
89
|
|
88
90
|
end
|
data/lib/gloo/verbs/list.rb
CHANGED
@@ -10,6 +10,7 @@ module Gloo
|
|
10
10
|
|
11
11
|
KEYWORD = 'list'.freeze
|
12
12
|
KEYWORD_SHORT = '.'.freeze
|
13
|
+
TARGET_MISSING_ERR = 'Object does not exist: '.freeze
|
13
14
|
|
14
15
|
#
|
15
16
|
# Run the verb.
|
@@ -19,30 +20,44 @@ module Gloo
|
|
19
20
|
target = self.determine_target
|
20
21
|
obj = target.resolve
|
21
22
|
if obj
|
22
|
-
|
23
|
+
show_target( obj, levels )
|
23
24
|
else
|
24
|
-
$
|
25
|
+
$engine.err "#{TARGET_MISSING_ERR} #{target}"
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
#
|
29
|
-
def determine_levels
|
30
|
-
# Check settings for the default value.
|
31
|
-
levels = $settings.list_indent
|
32
|
-
return levels if levels
|
33
|
-
|
34
|
-
# Last chance: use the default
|
35
|
-
return 1
|
36
|
-
end
|
37
|
-
|
29
|
+
#
|
38
30
|
# Determine the target object for the show command.
|
31
|
+
#
|
39
32
|
def determine_target
|
40
33
|
return $engine.heap.context if @tokens.token_count == 1
|
41
34
|
|
42
35
|
return Gloo::Core::Pn.new( @tokens.second )
|
43
36
|
end
|
44
37
|
|
38
|
+
#
|
39
|
+
# Get the Verb's keyword.
|
40
|
+
#
|
41
|
+
def self.keyword
|
42
|
+
return KEYWORD
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Get the Verb's keyword shortcut.
|
47
|
+
#
|
48
|
+
def self.keyword_shortcut
|
49
|
+
return KEYWORD_SHORT
|
50
|
+
end
|
51
|
+
|
52
|
+
# ---------------------------------------------------------------------
|
53
|
+
# Private functions
|
54
|
+
# ---------------------------------------------------------------------
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
#
|
45
59
|
# Show the target object.
|
60
|
+
#
|
46
61
|
def show_target( obj, levels, indent = '' )
|
47
62
|
show_obj( obj, indent )
|
48
63
|
return if levels.zero?
|
@@ -52,7 +67,9 @@ module Gloo
|
|
52
67
|
end
|
53
68
|
end
|
54
69
|
|
70
|
+
#
|
55
71
|
# Show object in standard format.
|
72
|
+
#
|
56
73
|
def show_obj( obj, indent = ' ' )
|
57
74
|
if obj.multiline_value? && obj.value_is_array?
|
58
75
|
$log.show "#{indent}#{obj.name} [#{obj.type_display}] :"
|
@@ -65,50 +82,15 @@ module Gloo
|
|
65
82
|
end
|
66
83
|
|
67
84
|
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
def self.keyword
|
71
|
-
return KEYWORD
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# Get the Verb's keyword shortcut.
|
76
|
-
#
|
77
|
-
def self.keyword_shortcut
|
78
|
-
return KEYWORD_SHORT
|
79
|
-
end
|
80
|
-
|
81
|
-
# ---------------------------------------------------------------------
|
82
|
-
# Help
|
83
|
-
# ---------------------------------------------------------------------
|
84
|
-
|
85
|
-
#
|
86
|
-
# Get help for this verb.
|
85
|
+
# Determine how many levels to show.
|
87
86
|
#
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
SHORTCUT: .
|
93
|
-
|
94
|
-
DESCRIPTION
|
95
|
-
List out objects (and children) at the current context.
|
96
|
-
When a path is provided, it will be listed instead of the
|
97
|
-
current context.
|
98
|
-
|
99
|
-
SYNTAX
|
100
|
-
list <path.to.object>
|
101
|
-
|
102
|
-
PARAMETERS
|
103
|
-
path.to.object - Optional path to object that will be listed.
|
104
|
-
When no path is provided, the current context is used.
|
105
|
-
|
106
|
-
RESULT
|
107
|
-
Object and children are listed out in the CLI.
|
87
|
+
def determine_levels
|
88
|
+
# Check settings for the default value.
|
89
|
+
levels = $settings.list_indent
|
90
|
+
return levels if levels
|
108
91
|
|
109
|
-
|
110
|
-
|
111
|
-
TEXT
|
92
|
+
# Last chance: use the default
|
93
|
+
return 1
|
112
94
|
end
|
113
95
|
|
114
96
|
end
|
data/lib/gloo/verbs/load.rb
CHANGED
@@ -10,14 +10,20 @@ module Gloo
|
|
10
10
|
|
11
11
|
KEYWORD = 'load'.freeze
|
12
12
|
KEYWORD_SHORT = '<'.freeze
|
13
|
+
MISSING_EXPR_ERR = 'Missing Expression!'.freeze
|
13
14
|
|
14
15
|
#
|
15
16
|
# Run the verb.
|
16
17
|
#
|
17
18
|
def run
|
18
19
|
fn = @tokens.second
|
19
|
-
|
20
|
-
|
20
|
+
|
21
|
+
if fn
|
22
|
+
$log.debug "Getting ready to load file: #{fn}"
|
23
|
+
$engine.persist_man.load fn
|
24
|
+
else
|
25
|
+
$engine.err MISSING_EXPR_ERR
|
26
|
+
end
|
21
27
|
end
|
22
28
|
|
23
29
|
#
|
@@ -34,41 +40,6 @@ module Gloo
|
|
34
40
|
return KEYWORD_SHORT
|
35
41
|
end
|
36
42
|
|
37
|
-
# ---------------------------------------------------------------------
|
38
|
-
# Help
|
39
|
-
# ---------------------------------------------------------------------
|
40
|
-
|
41
|
-
#
|
42
|
-
# Get help for this verb.
|
43
|
-
#
|
44
|
-
def self.help
|
45
|
-
return <<~TEXT
|
46
|
-
LOAD VERB
|
47
|
-
NAME: load
|
48
|
-
SHORTCUT: <
|
49
|
-
|
50
|
-
DESCRIPTION
|
51
|
-
Load an object file.
|
52
|
-
There are two ways to specify the file. Give either the full path and file name or use a relative path from the gloo project folder. For the latter, the extension is not needed. For the former, the
|
53
|
-
file extension is necessary.
|
54
|
-
Using * instead of a file name will load all gloo files in the folder.
|
55
|
-
|
56
|
-
SYNTAX
|
57
|
-
load <file_name>
|
58
|
-
|
59
|
-
PARAMETERS
|
60
|
-
file_name - Name of the object file that is to be loaded.
|
61
|
-
|
62
|
-
RESULT
|
63
|
-
Objects are loaded into the heap.
|
64
|
-
on_load scripts are run within the loaded objects.
|
65
|
-
|
66
|
-
ERRORS
|
67
|
-
If the file specified can't be found or can't be loaded,
|
68
|
-
an error condition will result.
|
69
|
-
TEXT
|
70
|
-
end
|
71
|
-
|
72
43
|
end
|
73
44
|
end
|
74
45
|
end
|
data/lib/gloo/verbs/move.rb
CHANGED
@@ -11,6 +11,10 @@ module Gloo
|
|
11
11
|
KEYWORD = 'move'.freeze
|
12
12
|
KEYWORD_SHORT = 'mv'.freeze
|
13
13
|
TO = 'to'.freeze
|
14
|
+
MISSING_SRC_ERR = 'Object to move was not specified!'.freeze
|
15
|
+
MISSING_SRC_OBJ_ERR = 'Could not find object to move: '.freeze
|
16
|
+
MISSING_DST_ERR = "Move' must include 'to' parent object!".freeze
|
17
|
+
MISSING_DST_OBJ_ERR = 'Could not resolve target: '.freeze
|
14
18
|
|
15
19
|
#
|
16
20
|
# Run the verb.
|
@@ -41,28 +45,26 @@ module Gloo
|
|
41
45
|
end
|
42
46
|
|
43
47
|
# ---------------------------------------------------------------------
|
44
|
-
#
|
48
|
+
# Private functions
|
45
49
|
# ---------------------------------------------------------------------
|
46
50
|
|
51
|
+
private
|
52
|
+
|
47
53
|
#
|
48
54
|
# Lookup the object that we're moving.
|
49
55
|
#
|
50
56
|
def lookup_obj
|
51
57
|
arr = @tokens.before_token( TO )
|
52
58
|
if arr.count == 1
|
53
|
-
|
54
|
-
|
59
|
+
$engine.err MISSING_SRC_ERR
|
60
|
+
return
|
55
61
|
end
|
56
62
|
|
57
63
|
name = arr[ 1 ]
|
58
64
|
pn = Gloo::Core::Pn.new name
|
59
65
|
o = pn.resolve
|
60
66
|
|
61
|
-
unless o
|
62
|
-
msg = "could not find object to move: #{name}"
|
63
|
-
$log.error msg, nil, $engine
|
64
|
-
end
|
65
|
-
|
67
|
+
$engine.err( "#{MISSING_SRC_OBJ_ERR} #{name}" ) unless o
|
66
68
|
return o
|
67
69
|
end
|
68
70
|
|
@@ -72,57 +74,16 @@ module Gloo
|
|
72
74
|
def lookup_dst
|
73
75
|
dst = @tokens.after_token( TO )
|
74
76
|
unless dst
|
75
|
-
|
76
|
-
$log.error msg, nil, $engine
|
77
|
+
$engine.err MISSING_DST_ERR
|
77
78
|
return nil
|
78
79
|
end
|
79
80
|
|
80
81
|
pn = Gloo::Core::Pn.new dst
|
81
82
|
o = pn.resolve
|
82
|
-
unless o
|
83
|
-
msg = "could not resolve '#{dst}'"
|
84
|
-
$log.error msg, nil, $engine
|
85
|
-
return nil
|
86
|
-
end
|
87
|
-
|
83
|
+
$engine.err( "#{MISSING_DST_OBJ_ERR} '#{dst}'" ) unless o
|
88
84
|
return o
|
89
85
|
end
|
90
86
|
|
91
|
-
# ---------------------------------------------------------------------
|
92
|
-
# Help
|
93
|
-
# ---------------------------------------------------------------------
|
94
|
-
|
95
|
-
#
|
96
|
-
# Get help for this verb.
|
97
|
-
#
|
98
|
-
def self.help
|
99
|
-
return <<~TEXT
|
100
|
-
MOVE VERB
|
101
|
-
NAME: move
|
102
|
-
SHORTCUT: mv
|
103
|
-
|
104
|
-
DESCRIPTION
|
105
|
-
Move an object to a new parent.
|
106
|
-
|
107
|
-
SYNTAX
|
108
|
-
move <path.to.object> to <new.parent>
|
109
|
-
|
110
|
-
PARAMETERS
|
111
|
-
path.to.object - The object that we want to move.
|
112
|
-
new.parent - The new location for the object.
|
113
|
-
|
114
|
-
RESULT
|
115
|
-
The object will now be in the new location.
|
116
|
-
|
117
|
-
ERRORS
|
118
|
-
The <path.to.object> is not specified.
|
119
|
-
The <path.to.object> cannot be resolved.
|
120
|
-
The <new.parent> is not specified.
|
121
|
-
The <new.parent> cannot be resolved.
|
122
|
-
The 'to' keyword is missing.
|
123
|
-
TEXT
|
124
|
-
end
|
125
|
-
|
126
87
|
end
|
127
88
|
end
|
128
89
|
end
|
data/lib/gloo/verbs/put.rb
CHANGED
@@ -11,6 +11,9 @@ module Gloo
|
|
11
11
|
KEYWORD = 'put'.freeze
|
12
12
|
KEYWORD_SHORT = 'p'.freeze
|
13
13
|
INTO = 'into'.freeze
|
14
|
+
MISSING_EXPR_ERR = 'Missing Expression!'.freeze
|
15
|
+
INTO_MISSING_ERR = 'Target (into) missing!'.freeze
|
16
|
+
TARGET_ERR = 'Target could not be resolved: '.freeze
|
14
17
|
|
15
18
|
#
|
16
19
|
# Run the verb.
|
@@ -22,17 +25,7 @@ module Gloo
|
|
22
25
|
target = lookup_target
|
23
26
|
return if target.nil?
|
24
27
|
|
25
|
-
|
26
|
-
o = pn.resolve
|
27
|
-
if o.nil?
|
28
|
-
msg = "could not find target of put: #{target}"
|
29
|
-
$log.error msg, nil, $engine
|
30
|
-
elsif value.count.positive?
|
31
|
-
expr = Gloo::Expr::Expression.new( value )
|
32
|
-
result = expr.evaluate
|
33
|
-
o.set_value result
|
34
|
-
$engine.heap.it.set_to result
|
35
|
-
end
|
28
|
+
update_target target, value
|
36
29
|
end
|
37
30
|
|
38
31
|
#
|
@@ -50,67 +43,50 @@ module Gloo
|
|
50
43
|
end
|
51
44
|
|
52
45
|
# ---------------------------------------------------------------------
|
53
|
-
#
|
46
|
+
# Private functions
|
54
47
|
# ---------------------------------------------------------------------
|
55
48
|
|
49
|
+
private
|
50
|
+
|
51
|
+
#
|
56
52
|
# Get the value that is being put.
|
53
|
+
#
|
57
54
|
def fetch_value_tokens
|
58
55
|
value = @tokens.before_token( INTO )
|
59
|
-
if value.nil?
|
60
|
-
|
61
|
-
$log.error msg, nil, $engine
|
56
|
+
if value.nil? || ( value.count <= 1 )
|
57
|
+
$engine.err MISSING_EXPR_ERR
|
62
58
|
return nil
|
63
59
|
end
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
value = value[ 1..-1 ]
|
68
|
-
end
|
69
|
-
return value
|
61
|
+
# The first token is the verb, so we drop it.
|
62
|
+
return value[ 1..-1 ]
|
70
63
|
end
|
71
64
|
|
65
|
+
#
|
72
66
|
# Lookup the target of the put command.
|
67
|
+
#
|
73
68
|
def lookup_target
|
74
69
|
target = @tokens.after_token( INTO )
|
75
70
|
return target if target
|
76
71
|
|
77
|
-
|
78
|
-
$log.error msg, nil, $engine
|
72
|
+
$engine.err INTO_MISSING_ERR
|
79
73
|
return nil
|
80
74
|
end
|
81
75
|
|
82
|
-
# ---------------------------------------------------------------------
|
83
|
-
# Help
|
84
|
-
# ---------------------------------------------------------------------
|
85
|
-
|
86
76
|
#
|
87
|
-
#
|
77
|
+
# Update the target with the new value.
|
88
78
|
#
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
put <expression> into <dst.path>
|
101
|
-
|
102
|
-
PARAMETERS
|
103
|
-
expression - The expression that is evaluated.
|
104
|
-
dst.path - The path to the destination object.
|
105
|
-
|
106
|
-
RESULT
|
107
|
-
<it> will contain the result of the evaluation.
|
108
|
-
|
109
|
-
ERRORS
|
110
|
-
The destination is not specified.
|
111
|
-
The destination cannot be resolved.
|
112
|
-
The 'into' keyword is missing.
|
113
|
-
TEXT
|
79
|
+
def update_target( target, value )
|
80
|
+
pn = Gloo::Core::Pn.new target
|
81
|
+
o = pn.resolve
|
82
|
+
if o.nil?
|
83
|
+
$engine.err "#{TARGET_ERR} #{target}"
|
84
|
+
elsif value.count.positive?
|
85
|
+
expr = Gloo::Expr::Expression.new( value )
|
86
|
+
result = expr.evaluate
|
87
|
+
o.set_value result
|
88
|
+
$engine.heap.it.set_to result
|
89
|
+
end
|
114
90
|
end
|
115
91
|
|
116
92
|
end
|