gloo 0.7.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/Gemfile.lock +46 -39
- data/LICENSE.txt +1 -1
- data/gloo.gemspec +12 -6
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +28 -0
- data/lib/gloo/app/info.rb +3 -1
- data/lib/gloo/app/log.rb +1 -29
- data/lib/gloo/app/platform.rb +142 -0
- data/lib/gloo/objs/cli/banner.rb +2 -2
- data/lib/gloo/objs/cli/bar.rb +4 -4
- data/lib/gloo/objs/cli/colorize.rb +3 -3
- data/lib/gloo/objs/cli/confirm.rb +3 -3
- data/lib/gloo/objs/cli/menu.rb +9 -9
- data/lib/gloo/objs/cli/menu_item.rb +2 -2
- data/lib/gloo/objs/cli/pastel.rb +2 -2
- data/lib/gloo/objs/cli/prompt.rb +4 -4
- data/lib/gloo/objs/cli/select.rb +4 -4
- data/lib/gloo/objs/dev/git.rb +7 -7
- data/lib/gloo/objs/dev/stats.rb +8 -5
- data/lib/gloo/objs/snd/play.rb +1 -1
- data/lib/gloo/objs/snd/say.rb +2 -2
- data/lib/gloo/objs/system/file_handle.rb +9 -9
- data/lib/gloo/objs/system/ssh_exec.rb +3 -3
- data/lib/gloo/objs/system/system.rb +2 -2
- data/lib/gloo/verbs/alert.rb +7 -7
- data/lib/gloo/verbs/beep.rb +1 -1
- data/lib/gloo/verbs/cls.rb +2 -2
- data/lib/gloo.rb +7 -7
- data/lib/run.rb +7 -5
- metadata +42 -147
- data/lib/gloo/app/args.rb +0 -112
- data/lib/gloo/app/engine.rb +0 -230
- data/lib/gloo/app/help.rb +0 -156
- data/lib/gloo/app/mode.rb +0 -27
- data/lib/gloo/app/settings.rb +0 -186
- data/lib/gloo/convert/converter.rb +0 -35
- data/lib/gloo/convert/string_to_datetime.rb +0 -21
- data/lib/gloo/convert/string_to_decimal.rb +0 -20
- data/lib/gloo/convert/string_to_integer.rb +0 -20
- data/lib/gloo/core/baseo.rb +0 -28
- data/lib/gloo/core/dictionary.rb +0 -181
- data/lib/gloo/core/error.rb +0 -61
- data/lib/gloo/core/event_manager.rb +0 -44
- data/lib/gloo/core/factory.rb +0 -210
- data/lib/gloo/core/gloo_system.rb +0 -266
- data/lib/gloo/core/heap.rb +0 -52
- data/lib/gloo/core/here.rb +0 -36
- data/lib/gloo/core/it.rb +0 -36
- data/lib/gloo/core/literal.rb +0 -30
- data/lib/gloo/core/obj.rb +0 -305
- data/lib/gloo/core/obj_finder.rb +0 -30
- data/lib/gloo/core/op.rb +0 -40
- data/lib/gloo/core/parser.rb +0 -59
- data/lib/gloo/core/pn.rb +0 -188
- data/lib/gloo/core/tokens.rb +0 -165
- data/lib/gloo/core/verb.rb +0 -86
- data/lib/gloo/exec/action.rb +0 -48
- data/lib/gloo/exec/dispatch.rb +0 -40
- data/lib/gloo/exec/exec_env.rb +0 -74
- data/lib/gloo/exec/runner.rb +0 -45
- data/lib/gloo/exec/script.rb +0 -49
- data/lib/gloo/exec/stack.rb +0 -78
- data/lib/gloo/expr/expression.rb +0 -118
- data/lib/gloo/expr/l_boolean.rb +0 -36
- data/lib/gloo/expr/l_decimal.rb +0 -39
- data/lib/gloo/expr/l_integer.rb +0 -37
- data/lib/gloo/expr/l_string.rb +0 -58
- data/lib/gloo/expr/op_div.rb +0 -22
- data/lib/gloo/expr/op_minus.rb +0 -22
- data/lib/gloo/expr/op_mult.rb +0 -22
- data/lib/gloo/expr/op_plus.rb +0 -24
- data/lib/gloo/objs/basic/alias.rb +0 -78
- data/lib/gloo/objs/basic/boolean.rb +0 -120
- data/lib/gloo/objs/basic/container.rb +0 -76
- data/lib/gloo/objs/basic/decimal.rb +0 -76
- data/lib/gloo/objs/basic/integer.rb +0 -73
- data/lib/gloo/objs/basic/script.rb +0 -99
- data/lib/gloo/objs/basic/string.rb +0 -77
- data/lib/gloo/objs/basic/text.rb +0 -87
- data/lib/gloo/objs/basic/untyped.rb +0 -41
- data/lib/gloo/objs/ctrl/each.rb +0 -279
- data/lib/gloo/objs/ctrl/repeat.rb +0 -108
- data/lib/gloo/objs/data/markdown.rb +0 -84
- data/lib/gloo/objs/data/mysql.rb +0 -192
- data/lib/gloo/objs/data/query.rb +0 -176
- data/lib/gloo/objs/data/sqlite.rb +0 -159
- data/lib/gloo/objs/data/table.rb +0 -140
- data/lib/gloo/objs/dt/date.rb +0 -50
- data/lib/gloo/objs/dt/datetime.rb +0 -62
- data/lib/gloo/objs/dt/time.rb +0 -50
- data/lib/gloo/objs/ror/erb.rb +0 -116
- data/lib/gloo/objs/ror/eval.rb +0 -107
- data/lib/gloo/objs/web/http_get.rb +0 -159
- data/lib/gloo/objs/web/http_post.rb +0 -183
- data/lib/gloo/objs/web/json.rb +0 -135
- data/lib/gloo/objs/web/slack.rb +0 -130
- data/lib/gloo/objs/web/teams.rb +0 -117
- data/lib/gloo/objs/web/uri.rb +0 -148
- data/lib/gloo/persist/file_loader.rb +0 -191
- data/lib/gloo/persist/file_saver.rb +0 -49
- data/lib/gloo/persist/file_storage.rb +0 -45
- data/lib/gloo/persist/line_splitter.rb +0 -81
- data/lib/gloo/persist/persist_man.rb +0 -120
- data/lib/gloo/utils/format.rb +0 -21
- data/lib/gloo/utils/stats.rb +0 -205
- data/lib/gloo/utils/words.rb +0 -19
- data/lib/gloo/verbs/context.rb +0 -62
- data/lib/gloo/verbs/create.rb +0 -68
- data/lib/gloo/verbs/execute.rb +0 -56
- data/lib/gloo/verbs/help.rb +0 -264
- data/lib/gloo/verbs/if.rb +0 -92
- data/lib/gloo/verbs/list.rb +0 -98
- data/lib/gloo/verbs/load.rb +0 -45
- data/lib/gloo/verbs/move.rb +0 -89
- data/lib/gloo/verbs/put.rb +0 -94
- data/lib/gloo/verbs/quit.rb +0 -40
- data/lib/gloo/verbs/run.rb +0 -75
- data/lib/gloo/verbs/save.rb +0 -39
- data/lib/gloo/verbs/show.rb +0 -64
- data/lib/gloo/verbs/tell.rb +0 -79
- data/lib/gloo/verbs/unless.rb +0 -92
- data/lib/gloo/verbs/version.rb +0 -37
- data/lib/gloo/verbs/wait.rb +0 -42
data/lib/gloo/core/tokens.rb
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An ordered list of tokens.
|
5
|
-
# The list of tokens makes up a command.
|
6
|
-
#
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Core
|
10
|
-
class Tokens
|
11
|
-
|
12
|
-
attr_reader :cmd, :tokens
|
13
|
-
|
14
|
-
# ---------------------------------------------------------------------
|
15
|
-
# Constructor
|
16
|
-
# ---------------------------------------------------------------------
|
17
|
-
|
18
|
-
#
|
19
|
-
# Set up the tokens.
|
20
|
-
# The command string is parsed into tokens during creation.
|
21
|
-
#
|
22
|
-
def initialize( cmd_string )
|
23
|
-
@cmd = cmd_string
|
24
|
-
@tokens = []
|
25
|
-
tokenize @cmd
|
26
|
-
end
|
27
|
-
|
28
|
-
# ---------------------------------------------------------------------
|
29
|
-
# Public functions
|
30
|
-
# ---------------------------------------------------------------------
|
31
|
-
|
32
|
-
#
|
33
|
-
# Get the number of tokens
|
34
|
-
#
|
35
|
-
def token_count
|
36
|
-
return @tokens.size
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# Get the verb (the first word)
|
41
|
-
#
|
42
|
-
def verb
|
43
|
-
return first
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Get all tokens except the first.
|
48
|
-
#
|
49
|
-
def params
|
50
|
-
return @tokens[ 1..-1 ]
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Get the first token.
|
55
|
-
#
|
56
|
-
def first
|
57
|
-
return @tokens.first if @tokens
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# Get the last token.
|
62
|
-
#
|
63
|
-
def last
|
64
|
-
return @tokens.last if @tokens
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
# Get the second token.
|
69
|
-
#
|
70
|
-
def second
|
71
|
-
return @tokens[ 1 ] if @tokens&.size&.positive?
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# Get the token at the the requested index.
|
76
|
-
#
|
77
|
-
def at( index )
|
78
|
-
return @tokens[ index ] if @tokens && @tokens.size >= index
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# Get the index of the given token.
|
83
|
-
#
|
84
|
-
def index_of( token )
|
85
|
-
return nil unless @tokens
|
86
|
-
|
87
|
-
return @tokens.find_index { |o| o.casecmp( token ).zero? }
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Get the list of tokens after the given token
|
92
|
-
#
|
93
|
-
def tokens_after( token )
|
94
|
-
i = index_of token
|
95
|
-
return @tokens[ i + 1..-1 ] if i && @tokens && @tokens.size > ( i + 1 )
|
96
|
-
|
97
|
-
return nil
|
98
|
-
end
|
99
|
-
|
100
|
-
#
|
101
|
-
# Get the expression after the given token
|
102
|
-
#
|
103
|
-
def expr_after( token )
|
104
|
-
str = ''
|
105
|
-
tokens_after( token ).each do |t|
|
106
|
-
str << ' ' unless str.empty?
|
107
|
-
str << t.to_s
|
108
|
-
end
|
109
|
-
return str
|
110
|
-
end
|
111
|
-
|
112
|
-
#
|
113
|
-
# Get the item after a given token.
|
114
|
-
#
|
115
|
-
def after_token( token )
|
116
|
-
i = index_of token
|
117
|
-
return @tokens[ i + 1 ] if i && @tokens && @tokens.size > ( i + 1 )
|
118
|
-
|
119
|
-
return nil
|
120
|
-
end
|
121
|
-
|
122
|
-
#
|
123
|
-
# Get the item after a given token.
|
124
|
-
#
|
125
|
-
def before_token( token )
|
126
|
-
i = index_of token
|
127
|
-
return @tokens[ 0..i - 1 ] if i && @tokens && @tokens.size >= i
|
128
|
-
|
129
|
-
return nil
|
130
|
-
end
|
131
|
-
|
132
|
-
# ---------------------------------------------------------------------
|
133
|
-
# Private functions
|
134
|
-
# ---------------------------------------------------------------------
|
135
|
-
|
136
|
-
private
|
137
|
-
|
138
|
-
#
|
139
|
-
# Create a list of token from the given string.
|
140
|
-
#
|
141
|
-
def tokenize( str )
|
142
|
-
if str.index( '"' )
|
143
|
-
i = str.index( '"' )
|
144
|
-
j = str.index( '"', i + 1 )
|
145
|
-
j ||= str.length
|
146
|
-
|
147
|
-
tokenize( str[ 0..i - 1 ] ) if i > 1
|
148
|
-
@tokens << str[ i..j ]
|
149
|
-
tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
|
150
|
-
elsif str.index( "'" )
|
151
|
-
i = str.index( "'" )
|
152
|
-
j = str.index( "'", i + 1 )
|
153
|
-
j ||= str.length
|
154
|
-
|
155
|
-
tokenize( str[ 0..i - 1 ] ) if i > 1
|
156
|
-
@tokens << str[ i..j ]
|
157
|
-
tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
|
158
|
-
else
|
159
|
-
str.strip.split( ' ' ).each { |t| @tokens << t }
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
data/lib/gloo/core/verb.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An abstract base verb.
|
5
|
-
# Derives from the Baseo object.
|
6
|
-
# It is a special type of object in that it can be run
|
7
|
-
# and can perform an action.
|
8
|
-
#
|
9
|
-
|
10
|
-
module Gloo
|
11
|
-
module Core
|
12
|
-
class Verb < Baseo
|
13
|
-
|
14
|
-
attr_reader :tokens, :params
|
15
|
-
|
16
|
-
#
|
17
|
-
# Set up the verb.
|
18
|
-
#
|
19
|
-
def initialize( tokens, params = [] )
|
20
|
-
@tokens = tokens
|
21
|
-
@params = params
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# Register verbs when they are loaded.
|
26
|
-
#
|
27
|
-
def self.inherited( subclass )
|
28
|
-
Dictionary.instance.register_verb( subclass )
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Run the verb.
|
33
|
-
#
|
34
|
-
# We'll mark the application as not running and let the
|
35
|
-
# engine stop gracefully next time through the loop.
|
36
|
-
#
|
37
|
-
def run
|
38
|
-
raise 'this method should be overriden'
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Get the Verb's keyword.
|
43
|
-
#
|
44
|
-
# The keyword will be in lower case only.
|
45
|
-
# It is used by the parser.
|
46
|
-
#
|
47
|
-
def self.keyword
|
48
|
-
raise 'this method should be overriden'
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# Get the Verb's keyword shortcut.
|
53
|
-
#
|
54
|
-
def self.keyword_shortcut
|
55
|
-
raise 'this method should be overriden'
|
56
|
-
end
|
57
|
-
|
58
|
-
#
|
59
|
-
# The object type, suitable for display.
|
60
|
-
#
|
61
|
-
def type_display
|
62
|
-
return self.class.keyword
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Generic function to get display value.
|
67
|
-
# Can be used for debugging, etc.
|
68
|
-
#
|
69
|
-
def display_value
|
70
|
-
return self.class.keyword
|
71
|
-
end
|
72
|
-
|
73
|
-
# ---------------------------------------------------------------------
|
74
|
-
# Help
|
75
|
-
# ---------------------------------------------------------------------
|
76
|
-
|
77
|
-
#
|
78
|
-
# Get help for this verb.
|
79
|
-
#
|
80
|
-
def self.help
|
81
|
-
return 'No help found.'
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
data/lib/gloo/exec/action.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An action is a message sent to an object with optional parameters.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Exec
|
9
|
-
class Action
|
10
|
-
|
11
|
-
attr_accessor :msg, :to, :params
|
12
|
-
|
13
|
-
#
|
14
|
-
# Set up the action.
|
15
|
-
#
|
16
|
-
def initialize( msg, to, params = nil )
|
17
|
-
@msg = msg
|
18
|
-
@to = to
|
19
|
-
@params = params
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# The action is valid if the object can receive
|
24
|
-
# the message specified.
|
25
|
-
#
|
26
|
-
def valid?
|
27
|
-
return @to.can_receive_message?( @msg )
|
28
|
-
end
|
29
|
-
|
30
|
-
#
|
31
|
-
# Execute the action.
|
32
|
-
# Dispatch the message to the object.
|
33
|
-
#
|
34
|
-
def dispatch
|
35
|
-
@to.send_message @msg, @params
|
36
|
-
end
|
37
|
-
|
38
|
-
#
|
39
|
-
# Generic function to get display value.
|
40
|
-
# Can be used for debugging, etc.
|
41
|
-
#
|
42
|
-
def display_value
|
43
|
-
return "#{@msg} -> #{@to.pn}"
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/lib/gloo/exec/dispatch.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Central Message Dispatch.
|
5
|
-
# Responsible for sending message to objects.
|
6
|
-
# All object messaging goes through here so we can uniformly
|
7
|
-
# manage things like checking to make sure object can
|
8
|
-
# receive the messages sent, handling errors, etc.
|
9
|
-
#
|
10
|
-
|
11
|
-
module Gloo
|
12
|
-
module Exec
|
13
|
-
class Dispatch
|
14
|
-
|
15
|
-
#
|
16
|
-
# Dispatch the given message to the given object.
|
17
|
-
#
|
18
|
-
def self.message( msg, to_obj, params = nil )
|
19
|
-
$log.debug "Dispatch message #{msg} to #{to_obj.name}"
|
20
|
-
a = Gloo::Exec::Action.new msg, to_obj, params
|
21
|
-
Gloo::Exec::Dispatch.action a
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# Dispatch an action.
|
26
|
-
#
|
27
|
-
def self.action( action )
|
28
|
-
unless action.valid?
|
29
|
-
$log.warn "Object #{action.to.name} does not respond to #{action.msg}"
|
30
|
-
end
|
31
|
-
|
32
|
-
$engine.exec_env.push_action action
|
33
|
-
$log.debug "Sending message #{action.msg} to #{action.to.name}"
|
34
|
-
action.dispatch
|
35
|
-
$engine.exec_env.pop_action
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/gloo/exec/exec_env.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# The execution environment.
|
5
|
-
# The current state of running scripts and messaging.
|
6
|
-
#
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Exec
|
10
|
-
class ExecEnv
|
11
|
-
|
12
|
-
attr_accessor :verbs, :actions, :scripts, :here
|
13
|
-
|
14
|
-
VERB_STACK = 'verbs'.freeze
|
15
|
-
ACTION_STACK = 'actions'.freeze
|
16
|
-
SCRIPT_STACK = 'scripts'.freeze
|
17
|
-
HERE_STACK = 'here'.freeze
|
18
|
-
|
19
|
-
#
|
20
|
-
# Set up the execution environment.
|
21
|
-
#
|
22
|
-
def initialize
|
23
|
-
$log.debug 'exec env intialized...'
|
24
|
-
|
25
|
-
@verbs = Gloo::Exec::Stack.new VERB_STACK
|
26
|
-
@actions = Gloo::Exec::Stack.new ACTION_STACK
|
27
|
-
@scripts = Gloo::Exec::Stack.new SCRIPT_STACK
|
28
|
-
@here = Gloo::Exec::Stack.new HERE_STACK
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the here object.
|
33
|
-
#
|
34
|
-
def here_obj
|
35
|
-
return nil if @here.stack.empty?
|
36
|
-
|
37
|
-
return @here.stack.last
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Push a script onto the stack.
|
42
|
-
#
|
43
|
-
def push_script( script )
|
44
|
-
@scripts.push script
|
45
|
-
@here.push script.obj
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# Pop a script off the stack.
|
50
|
-
#
|
51
|
-
def pop_script
|
52
|
-
@scripts.pop
|
53
|
-
@here.pop
|
54
|
-
end
|
55
|
-
|
56
|
-
#
|
57
|
-
# Push an action onto the stack.
|
58
|
-
#
|
59
|
-
def push_action( action )
|
60
|
-
@actions.push action
|
61
|
-
# @here.push action.to
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Pop an action off the stack.
|
66
|
-
#
|
67
|
-
def pop_action
|
68
|
-
@actions.pop
|
69
|
-
# @here.pop
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/lib/gloo/exec/runner.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# The Runner is a static helper function.
|
5
|
-
# It is used to send the run command to verbs.
|
6
|
-
#
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Exec
|
10
|
-
class Runner
|
11
|
-
|
12
|
-
#
|
13
|
-
# Dispatch run command to a verb.
|
14
|
-
# We abstract this out in case there are things
|
15
|
-
# that need to be done before or after a verb
|
16
|
-
# is done running.
|
17
|
-
#
|
18
|
-
def self.go( verb )
|
19
|
-
$log.debug "running verb #{verb.type_display}"
|
20
|
-
$engine.heap.error.start_tracking
|
21
|
-
$engine.exec_env.verbs.push verb
|
22
|
-
verb&.run
|
23
|
-
$engine.exec_env.verbs.pop
|
24
|
-
$engine.heap.error.clear_if_no_errors
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
# Send 'run' message to the object.
|
29
|
-
# Resolve the path_name and then send the run message.
|
30
|
-
#
|
31
|
-
def self.run( path_name )
|
32
|
-
$log.debug "running script at #{path_name}"
|
33
|
-
pn = Gloo::Core::Pn.new path_name
|
34
|
-
o = pn.resolve
|
35
|
-
|
36
|
-
if o
|
37
|
-
o.send_message 'run'
|
38
|
-
else
|
39
|
-
$log.error "Could not send message to object. Bad path: #{path_name}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/gloo/exec/script.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# A script to be run.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Exec
|
9
|
-
class Script
|
10
|
-
|
11
|
-
attr_accessor :obj
|
12
|
-
|
13
|
-
#
|
14
|
-
# Set up the script.
|
15
|
-
#
|
16
|
-
def initialize( obj )
|
17
|
-
@obj = obj
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# Run the script.
|
22
|
-
# The script might be a single string or an array
|
23
|
-
# of lines.
|
24
|
-
#
|
25
|
-
def run
|
26
|
-
$engine.exec_env.push_script self
|
27
|
-
|
28
|
-
if @obj.value.is_a? String
|
29
|
-
$engine.parser.run @obj.value
|
30
|
-
elsif @obj.value.is_a? Array
|
31
|
-
@obj.value.each do |line|
|
32
|
-
$engine.parser.run line
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
$engine.exec_env.pop_script
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# Generic function to get display value.
|
41
|
-
# Can be used for debugging, etc.
|
42
|
-
#
|
43
|
-
def display_value
|
44
|
-
return @obj.pn
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/gloo/exec/stack.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# A stack of items, a call stack.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Exec
|
9
|
-
class Stack
|
10
|
-
|
11
|
-
attr_accessor :stack
|
12
|
-
|
13
|
-
#
|
14
|
-
# Set up the stack.
|
15
|
-
#
|
16
|
-
def initialize( name )
|
17
|
-
@name = name
|
18
|
-
clear_stack
|
19
|
-
$log.debug "#{name} stack intialized..."
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# Push an item onto the stack.
|
24
|
-
#
|
25
|
-
def push( obj )
|
26
|
-
$log.debug "#{@name}:push #{obj.display_value}"
|
27
|
-
@stack.push obj
|
28
|
-
self.update_out_file if $settings.debug
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Pop an item from the stack.
|
33
|
-
#
|
34
|
-
def pop
|
35
|
-
o = @stack.pop
|
36
|
-
$log.debug "#{@name}:pop #{o.display_value}"
|
37
|
-
self.update_out_file if $settings.debug
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Get the current size of the call stack.
|
42
|
-
#
|
43
|
-
def size
|
44
|
-
return @stack.size
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Get stack data for output.
|
49
|
-
#
|
50
|
-
def out_data
|
51
|
-
return @stack.map( &:display_value ).join( "\n" )
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# Get the file we'll write debug information for the stack.
|
56
|
-
#
|
57
|
-
def out_file
|
58
|
-
return File.join( $settings.debug_path, @name )
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# Update the stack trace file.
|
63
|
-
#
|
64
|
-
def update_out_file
|
65
|
-
File.write( self.out_file, self.out_data )
|
66
|
-
end
|
67
|
-
|
68
|
-
#
|
69
|
-
# Clear the stack and the output file.
|
70
|
-
#
|
71
|
-
def clear_stack
|
72
|
-
@stack = []
|
73
|
-
self.update_out_file
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/lib/gloo/expr/expression.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An Expression that can be evaluated.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Expr
|
9
|
-
class Expression
|
10
|
-
|
11
|
-
# ---------------------------------------------------------------------
|
12
|
-
# Constructor
|
13
|
-
# ---------------------------------------------------------------------
|
14
|
-
|
15
|
-
#
|
16
|
-
# Create the expression from a list of tokens.
|
17
|
-
#
|
18
|
-
def initialize( tokens )
|
19
|
-
@tokens = tokens
|
20
|
-
@symbols = []
|
21
|
-
@left = nil
|
22
|
-
@right = nil
|
23
|
-
@op = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
# ---------------------------------------------------------------------
|
27
|
-
# Evaluate Expression
|
28
|
-
# ---------------------------------------------------------------------
|
29
|
-
|
30
|
-
#
|
31
|
-
# Evaluate the expression and return the value.
|
32
|
-
#
|
33
|
-
def evaluate
|
34
|
-
identify_tokens
|
35
|
-
|
36
|
-
@symbols.each do |sym|
|
37
|
-
if sym.is_a? Gloo::Core::Op
|
38
|
-
@op = sym
|
39
|
-
elsif @left.nil?
|
40
|
-
@left = sym
|
41
|
-
else
|
42
|
-
@right = sym
|
43
|
-
end
|
44
|
-
|
45
|
-
perform_op if @left && @right
|
46
|
-
end
|
47
|
-
|
48
|
-
return @left.value if @left.is_a? Gloo::Core::Literal
|
49
|
-
return resolve_ref @left if @left.is_a? Gloo::Core::Pn
|
50
|
-
|
51
|
-
return @left
|
52
|
-
end
|
53
|
-
|
54
|
-
# ---------------------------------------------------------------------
|
55
|
-
# Private functions
|
56
|
-
# ---------------------------------------------------------------------
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
#
|
61
|
-
# Perform the operation.
|
62
|
-
#
|
63
|
-
def perform_op
|
64
|
-
@op ||= Gloo::Core::Op.default_op
|
65
|
-
l = evaluate_sym @left
|
66
|
-
r = evaluate_sym @right
|
67
|
-
@left = @op.perform l, r
|
68
|
-
@right = nil
|
69
|
-
@op = nil
|
70
|
-
end
|
71
|
-
|
72
|
-
#
|
73
|
-
# Evaluate the symbol and get a simple value.
|
74
|
-
#
|
75
|
-
def evaluate_sym( sym )
|
76
|
-
return sym.value if sym.is_a? Gloo::Core::Literal
|
77
|
-
return resolve_ref sym if sym.is_a? Gloo::Core::Pn
|
78
|
-
|
79
|
-
return sym
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# resolve an object reference and get the value.
|
84
|
-
#
|
85
|
-
def resolve_ref( ref )
|
86
|
-
return ref.src if ref.named_color?
|
87
|
-
|
88
|
-
ob = ref.resolve
|
89
|
-
return ob.value if ob
|
90
|
-
end
|
91
|
-
|
92
|
-
#
|
93
|
-
# Identify each token in the list.
|
94
|
-
#
|
95
|
-
def identify_tokens
|
96
|
-
@tokens.each do |o|
|
97
|
-
@symbols << identify_token( o )
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
#
|
102
|
-
# Identify the tokens and create appropriate symbols.
|
103
|
-
#
|
104
|
-
def identify_token( token )
|
105
|
-
return Gloo::Core::Op.create_op( token ) if Gloo::Core::Op.op?( token )
|
106
|
-
|
107
|
-
return LBoolean.new( token ) if LBoolean.boolean?( token )
|
108
|
-
return LInteger.new( token ) if LInteger.integer?( token )
|
109
|
-
return LString.new( token ) if LString.string?( token )
|
110
|
-
return LDecimal.new( token ) if LDecimal.decimal?( token )
|
111
|
-
|
112
|
-
# last chance: an Object reference
|
113
|
-
return Gloo::Core::Pn.new( token )
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|