gloo 0.5.4 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/core/error.rb
CHANGED
|
@@ -8,39 +8,50 @@ module Gloo
|
|
|
8
8
|
module Core
|
|
9
9
|
class Error
|
|
10
10
|
|
|
11
|
-
attr_accessor :value
|
|
11
|
+
attr_accessor :value, :error_count
|
|
12
12
|
|
|
13
|
+
#
|
|
13
14
|
# Set up the error object.
|
|
15
|
+
#
|
|
14
16
|
def initialize
|
|
15
|
-
|
|
17
|
+
clear
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#
|
|
21
|
+
# Clear out the error message.
|
|
22
|
+
#
|
|
23
|
+
def clear
|
|
16
24
|
@error_count = 0
|
|
25
|
+
@value = nil
|
|
17
26
|
end
|
|
18
27
|
|
|
28
|
+
#
|
|
19
29
|
# Set the value of error.
|
|
30
|
+
#
|
|
20
31
|
def set_to( new_value )
|
|
21
32
|
@error_count += 1
|
|
22
33
|
@value = new_value
|
|
23
34
|
end
|
|
24
35
|
|
|
25
|
-
#
|
|
26
|
-
def clear
|
|
27
|
-
@error_count = 0
|
|
28
|
-
@value = nil
|
|
29
|
-
end
|
|
30
|
-
|
|
36
|
+
#
|
|
31
37
|
# Start counting errors.
|
|
32
38
|
# We're looking to see if we get any new ones during
|
|
33
39
|
# a script or an immediate command.
|
|
40
|
+
#
|
|
34
41
|
def start_tracking
|
|
35
42
|
@error_count = 0
|
|
36
43
|
end
|
|
37
44
|
|
|
45
|
+
#
|
|
38
46
|
# Clear out error if we didn't add any new ones.
|
|
47
|
+
#
|
|
39
48
|
def clear_if_no_errors
|
|
40
49
|
self.clear if @error_count.zero?
|
|
41
50
|
end
|
|
42
51
|
|
|
52
|
+
#
|
|
43
53
|
# Get the string representation of the error.
|
|
54
|
+
#
|
|
44
55
|
def to_s
|
|
45
56
|
return @value.to_s
|
|
46
57
|
end
|
|
@@ -9,7 +9,9 @@ module Gloo
|
|
|
9
9
|
module Core
|
|
10
10
|
class EventManager
|
|
11
11
|
|
|
12
|
+
#
|
|
12
13
|
# Set up the event manager.
|
|
14
|
+
#
|
|
13
15
|
def initialize
|
|
14
16
|
$log.debug 'event manager intialized...'
|
|
15
17
|
end
|
|
@@ -21,6 +23,7 @@ module Gloo
|
|
|
21
23
|
def on_load( obj = nil, in_heap = false )
|
|
22
24
|
return unless obj || in_heap
|
|
23
25
|
|
|
26
|
+
$log.debug 'on_load event'
|
|
24
27
|
arr = Gloo::Core::ObjFinder.by_name 'on_load', obj
|
|
25
28
|
arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
|
|
26
29
|
end
|
|
@@ -31,6 +34,7 @@ module Gloo
|
|
|
31
34
|
def on_unload( obj )
|
|
32
35
|
return unless obj
|
|
33
36
|
|
|
37
|
+
$log.debug 'on_unload event'
|
|
34
38
|
arr = Gloo::Core::ObjFinder.by_name 'on_unload', obj
|
|
35
39
|
arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
|
|
36
40
|
end
|
data/lib/gloo/core/factory.rb
CHANGED
|
@@ -45,6 +45,17 @@ module Gloo
|
|
|
45
45
|
create params
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
#
|
|
49
|
+
# Helper shortcut to create a text child object.
|
|
50
|
+
#
|
|
51
|
+
def create_text( name, value, parent )
|
|
52
|
+
params = { :name => name,
|
|
53
|
+
:type => 'text',
|
|
54
|
+
:value => value,
|
|
55
|
+
:parent => parent }
|
|
56
|
+
create params
|
|
57
|
+
end
|
|
58
|
+
|
|
48
59
|
#
|
|
49
60
|
# Helper shortcut to create an integer child object.
|
|
50
61
|
#
|
data/lib/gloo/core/heap.rb
CHANGED
|
@@ -14,12 +14,11 @@ module Gloo
|
|
|
14
14
|
# The context will be the root by default.
|
|
15
15
|
attr_reader :context
|
|
16
16
|
|
|
17
|
-
# TODO: Do I need a running script context?
|
|
18
|
-
# how to resolve relative reference.
|
|
19
|
-
|
|
20
17
|
attr_reader :it, :root, :error
|
|
21
18
|
|
|
19
|
+
#
|
|
22
20
|
# Set up the object heap.
|
|
21
|
+
#
|
|
23
22
|
def initialize
|
|
24
23
|
$log.debug 'object heap intialized...'
|
|
25
24
|
|
|
@@ -31,7 +30,9 @@ module Gloo
|
|
|
31
30
|
@error = Error.new
|
|
32
31
|
end
|
|
33
32
|
|
|
33
|
+
#
|
|
34
34
|
# Unload the given obj--remove it from the heap.
|
|
35
|
+
#
|
|
35
36
|
def unload( obj )
|
|
36
37
|
can = obj.parent.nil? ? @root : obj.parent
|
|
37
38
|
return unless can
|
|
@@ -39,6 +40,13 @@ module Gloo
|
|
|
39
40
|
can.remove_child obj
|
|
40
41
|
end
|
|
41
42
|
|
|
43
|
+
#
|
|
44
|
+
# Is there one or more errors?
|
|
45
|
+
#
|
|
46
|
+
def error?
|
|
47
|
+
return @error.error_count.positive?
|
|
48
|
+
end
|
|
49
|
+
|
|
42
50
|
end
|
|
43
51
|
end
|
|
44
52
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Here helper class,
|
|
5
|
+
# used to resolve relative referencing.
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
module Gloo
|
|
9
|
+
module Core
|
|
10
|
+
class Here
|
|
11
|
+
|
|
12
|
+
HERE = '^'.freeze
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Does the pathname start with here reference?
|
|
16
|
+
#
|
|
17
|
+
def self.includes_here_ref?( elements )
|
|
18
|
+
return elements.first.start_with?( HERE )
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Expand here reference if present.
|
|
23
|
+
#
|
|
24
|
+
def self.expand_here( pn )
|
|
25
|
+
target = $engine.exec_env.here_obj
|
|
26
|
+
|
|
27
|
+
here = pn.elements.first
|
|
28
|
+
remainder = pn.elements[ 1..-1 ].join( '.' )
|
|
29
|
+
|
|
30
|
+
here.length.times { target = target.parent }
|
|
31
|
+
pn.set_to "#{target.pn}.#{remainder}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/gloo/core/it.rb
CHANGED
|
@@ -10,17 +10,23 @@ module Gloo
|
|
|
10
10
|
|
|
11
11
|
attr_accessor :value
|
|
12
12
|
|
|
13
|
+
#
|
|
13
14
|
# Set up the object.
|
|
15
|
+
#
|
|
14
16
|
def initialize
|
|
15
17
|
@value = nil
|
|
16
18
|
end
|
|
17
19
|
|
|
20
|
+
#
|
|
18
21
|
# Set the value of it.
|
|
22
|
+
#
|
|
19
23
|
def set_to( new_value )
|
|
20
24
|
@value = new_value
|
|
21
25
|
end
|
|
22
26
|
|
|
27
|
+
#
|
|
23
28
|
# Get the string representation of it.
|
|
29
|
+
#
|
|
24
30
|
def to_s
|
|
25
31
|
return @value.to_s
|
|
26
32
|
end
|
data/lib/gloo/core/literal.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
|
3
3
|
#
|
|
4
4
|
# A Literal value.
|
|
5
|
+
# Base class for all literal values.
|
|
5
6
|
#
|
|
6
7
|
|
|
7
8
|
module Gloo
|
|
@@ -10,12 +11,16 @@ module Gloo
|
|
|
10
11
|
|
|
11
12
|
attr_reader :value
|
|
12
13
|
|
|
14
|
+
#
|
|
13
15
|
# Create the expression from a list of tokens.
|
|
16
|
+
#
|
|
14
17
|
def initialize( value )
|
|
15
18
|
set_value( value )
|
|
16
19
|
end
|
|
17
20
|
|
|
21
|
+
#
|
|
18
22
|
# Set the literal value.
|
|
23
|
+
#
|
|
19
24
|
def set_value( value )
|
|
20
25
|
@value = value
|
|
21
26
|
end
|
data/lib/gloo/core/obj.rb
CHANGED
|
@@ -12,14 +12,18 @@ module Gloo
|
|
|
12
12
|
attr_accessor :value
|
|
13
13
|
attr_reader :children, :parent
|
|
14
14
|
|
|
15
|
+
#
|
|
15
16
|
# Set up the object.
|
|
17
|
+
#
|
|
16
18
|
def initialize
|
|
17
19
|
@value = ''
|
|
18
20
|
@children = []
|
|
19
21
|
@parent = nil
|
|
20
22
|
end
|
|
21
23
|
|
|
24
|
+
#
|
|
22
25
|
# Register object types when they are loaded.
|
|
26
|
+
#
|
|
23
27
|
def self.inherited( subclass )
|
|
24
28
|
Dictionary.instance.register_obj( subclass )
|
|
25
29
|
end
|
|
@@ -45,7 +49,9 @@ module Gloo
|
|
|
45
49
|
@parent = obj
|
|
46
50
|
end
|
|
47
51
|
|
|
52
|
+
#
|
|
48
53
|
# Is this the root object?
|
|
54
|
+
#
|
|
49
55
|
def root?
|
|
50
56
|
return false if @parent
|
|
51
57
|
return false unless name.downcase == 'root'
|
|
@@ -73,6 +79,14 @@ module Gloo
|
|
|
73
79
|
return str
|
|
74
80
|
end
|
|
75
81
|
|
|
82
|
+
#
|
|
83
|
+
# Generic function to get display value.
|
|
84
|
+
# Can be used for debugging, etc.
|
|
85
|
+
#
|
|
86
|
+
def display_value
|
|
87
|
+
return self.pn
|
|
88
|
+
end
|
|
89
|
+
|
|
76
90
|
# ---------------------------------------------------------------------
|
|
77
91
|
# Value
|
|
78
92
|
# ---------------------------------------------------------------------
|
|
@@ -141,18 +155,24 @@ module Gloo
|
|
|
141
155
|
return $engine.factory.create params
|
|
142
156
|
end
|
|
143
157
|
|
|
158
|
+
#
|
|
144
159
|
# Add a child object to the container.
|
|
160
|
+
#
|
|
145
161
|
def add_child( obj )
|
|
146
162
|
@children << obj
|
|
147
163
|
obj.set_parent self
|
|
148
164
|
end
|
|
149
165
|
|
|
166
|
+
#
|
|
150
167
|
# Get the number of children.
|
|
168
|
+
#
|
|
151
169
|
def child_count
|
|
152
170
|
return @children.count
|
|
153
171
|
end
|
|
154
172
|
|
|
173
|
+
#
|
|
155
174
|
# Does this object contain an object with the given name?
|
|
175
|
+
#
|
|
156
176
|
def contains_child?( name )
|
|
157
177
|
@children.each do |o|
|
|
158
178
|
return true if name.downcase == o.name.downcase
|
|
@@ -160,7 +180,9 @@ module Gloo
|
|
|
160
180
|
return false
|
|
161
181
|
end
|
|
162
182
|
|
|
183
|
+
#
|
|
163
184
|
# Find a child object with the given name.
|
|
185
|
+
#
|
|
164
186
|
def find_child( name )
|
|
165
187
|
if name.end_with?( Gloo::Objs::Alias::ALIAS_REFERENCE )
|
|
166
188
|
name = name[ 0..-2 ]
|
data/lib/gloo/core/op.rb
CHANGED
|
@@ -2,18 +2,23 @@
|
|
|
2
2
|
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
|
3
3
|
#
|
|
4
4
|
# An Operator; part of an expression.
|
|
5
|
+
# A static helper class.
|
|
5
6
|
#
|
|
6
7
|
|
|
7
8
|
module Gloo
|
|
8
9
|
module Core
|
|
9
10
|
class Op
|
|
10
11
|
|
|
12
|
+
#
|
|
11
13
|
# Is the token an operator?
|
|
14
|
+
#
|
|
12
15
|
def self.op?( token )
|
|
13
16
|
return [ '+', '-', '*', '/' ].include?( token.strip )
|
|
14
17
|
end
|
|
15
18
|
|
|
19
|
+
#
|
|
16
20
|
# Create the operator for the given token.
|
|
21
|
+
#
|
|
17
22
|
def self.create_op( token )
|
|
18
23
|
return Gloo::Expr::OpMinus.new if token == '-'
|
|
19
24
|
return Gloo::Expr::OpMult.new if token == '*'
|
|
@@ -23,7 +28,9 @@ module Gloo
|
|
|
23
28
|
return default_op
|
|
24
29
|
end
|
|
25
30
|
|
|
31
|
+
#
|
|
26
32
|
# Get the default operator (+).
|
|
33
|
+
#
|
|
27
34
|
def self.default_op
|
|
28
35
|
return Gloo::Expr::OpPlus.new
|
|
29
36
|
end
|
data/lib/gloo/core/parser.rb
CHANGED
|
@@ -9,12 +9,16 @@ module Gloo
|
|
|
9
9
|
module Core
|
|
10
10
|
class Parser
|
|
11
11
|
|
|
12
|
+
#
|
|
12
13
|
# Set up the parser.
|
|
14
|
+
#
|
|
13
15
|
def initialize
|
|
14
16
|
$log.debug 'parser intialized...'
|
|
15
17
|
end
|
|
16
18
|
|
|
19
|
+
#
|
|
17
20
|
# Parse a command from the immediate execution context.
|
|
21
|
+
#
|
|
18
22
|
def parse_immediate( cmd )
|
|
19
23
|
cmd, params = split_params cmd
|
|
20
24
|
params = Gloo::Core::Tokens.new( params ) if params
|
|
@@ -27,8 +31,10 @@ module Gloo
|
|
|
27
31
|
return nil
|
|
28
32
|
end
|
|
29
33
|
|
|
34
|
+
#
|
|
30
35
|
# If additional params were provided, split them out
|
|
31
36
|
# from the token list.
|
|
37
|
+
#
|
|
32
38
|
def split_params( cmd )
|
|
33
39
|
params = nil
|
|
34
40
|
i = cmd.rindex( '(' )
|
data/lib/gloo/core/pn.rb
CHANGED
|
@@ -15,43 +15,59 @@ module Gloo
|
|
|
15
15
|
|
|
16
16
|
attr_reader :src, :elements
|
|
17
17
|
|
|
18
|
+
#
|
|
18
19
|
# Set up the object given a source string,
|
|
19
20
|
# ie: the full path and name.
|
|
21
|
+
#
|
|
20
22
|
def initialize( src )
|
|
21
23
|
set_to src
|
|
22
24
|
end
|
|
23
25
|
|
|
26
|
+
#
|
|
24
27
|
# Reference to the root object path.
|
|
28
|
+
#
|
|
25
29
|
def self.root
|
|
26
30
|
return Pn.new( ROOT )
|
|
27
31
|
end
|
|
28
32
|
|
|
33
|
+
#
|
|
29
34
|
# Reference to it.
|
|
35
|
+
#
|
|
30
36
|
def self.it
|
|
31
37
|
return Pn.new( IT )
|
|
32
38
|
end
|
|
33
39
|
|
|
40
|
+
#
|
|
34
41
|
# Reference to the error message.
|
|
42
|
+
#
|
|
35
43
|
def self.error
|
|
36
44
|
return Pn.new( ERROR )
|
|
37
45
|
end
|
|
38
46
|
|
|
47
|
+
#
|
|
39
48
|
# Does the pathname reference refer to the root?
|
|
49
|
+
#
|
|
40
50
|
def root?
|
|
41
51
|
return @src.downcase == ROOT
|
|
42
52
|
end
|
|
43
53
|
|
|
54
|
+
#
|
|
44
55
|
# Does the pathname reference refer to it?
|
|
56
|
+
#
|
|
45
57
|
def it?
|
|
46
58
|
return @src.downcase == IT
|
|
47
59
|
end
|
|
48
60
|
|
|
61
|
+
#
|
|
49
62
|
# Does the pathname reference refer to error?
|
|
63
|
+
#
|
|
50
64
|
def error?
|
|
51
65
|
return @src.downcase == ERROR
|
|
52
66
|
end
|
|
53
67
|
|
|
68
|
+
#
|
|
54
69
|
# Does the pathname reference refer to the gloo system object?
|
|
70
|
+
#
|
|
55
71
|
def gloo_sys?
|
|
56
72
|
return false unless @elements&.count&.positive?
|
|
57
73
|
|
|
@@ -62,40 +78,54 @@ module Gloo
|
|
|
62
78
|
return false
|
|
63
79
|
end
|
|
64
80
|
|
|
81
|
+
#
|
|
65
82
|
# Get the string representation of the pathname.
|
|
83
|
+
#
|
|
66
84
|
def to_s
|
|
67
85
|
return @src
|
|
68
86
|
end
|
|
69
87
|
|
|
88
|
+
#
|
|
70
89
|
# Set the object pathname to the given value.
|
|
90
|
+
#
|
|
71
91
|
def set_to( value )
|
|
72
92
|
@src = value.nil? ? nil : value.strip
|
|
73
93
|
@elements = @src.nil? ? [] : @src.split( '.' )
|
|
74
94
|
end
|
|
75
95
|
|
|
96
|
+
#
|
|
76
97
|
# Convert the raw string to a list of segments.
|
|
98
|
+
#
|
|
77
99
|
def segments
|
|
78
100
|
return @elements
|
|
79
101
|
end
|
|
80
102
|
|
|
103
|
+
#
|
|
81
104
|
# Get the name element.
|
|
105
|
+
#
|
|
82
106
|
def name
|
|
83
107
|
return '' unless self.named?
|
|
84
108
|
|
|
85
109
|
return @elements.last
|
|
86
110
|
end
|
|
87
111
|
|
|
112
|
+
#
|
|
88
113
|
# Does the value include path elements?
|
|
114
|
+
#
|
|
89
115
|
def named?
|
|
90
116
|
return @elements.count.positive?
|
|
91
117
|
end
|
|
92
118
|
|
|
119
|
+
#
|
|
93
120
|
# Does the value include a name?
|
|
121
|
+
#
|
|
94
122
|
def includes_path?
|
|
95
123
|
return @elements.count > 1
|
|
96
124
|
end
|
|
97
125
|
|
|
126
|
+
#
|
|
98
127
|
# Get the parent that contains the object referenced.
|
|
128
|
+
#
|
|
99
129
|
def get_parent
|
|
100
130
|
o = $engine.heap.root
|
|
101
131
|
|
|
@@ -112,7 +142,9 @@ module Gloo
|
|
|
112
142
|
return o
|
|
113
143
|
end
|
|
114
144
|
|
|
145
|
+
#
|
|
115
146
|
# Does the object at the path exist?
|
|
147
|
+
#
|
|
116
148
|
def exists?
|
|
117
149
|
return true if self.root?
|
|
118
150
|
return true if self.it?
|
|
@@ -124,20 +156,26 @@ module Gloo
|
|
|
124
156
|
return parent.contains_child? name
|
|
125
157
|
end
|
|
126
158
|
|
|
159
|
+
#
|
|
127
160
|
# Is the reference to a color?
|
|
161
|
+
#
|
|
128
162
|
def named_color?
|
|
129
163
|
colors = %w[red blue green white black yellow]
|
|
130
164
|
return true if colors.include?( @src.downcase )
|
|
131
165
|
end
|
|
132
166
|
|
|
167
|
+
#
|
|
133
168
|
# Resolve the pathname reference.
|
|
134
169
|
# Find the object referenced or return nil if it is not found.
|
|
170
|
+
#
|
|
135
171
|
def resolve
|
|
136
172
|
return $engine.heap.root if self.root?
|
|
137
173
|
return $engine.heap.it if self.it?
|
|
138
174
|
return $engine.heap.error if self.error?
|
|
139
175
|
return Gloo::Core::GlooSystem.new( self ) if self.gloo_sys?
|
|
140
176
|
|
|
177
|
+
Here.expand_here( self ) if Here.includes_here_ref?( @elements )
|
|
178
|
+
|
|
141
179
|
parent = self.get_parent
|
|
142
180
|
return nil unless parent
|
|
143
181
|
|