gloo-lang 0.9.2 → 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 +1 -5
- 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 +190 -2
@@ -0,0 +1,303 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An data/value object.
|
5
|
+
# Derives from the Baseo object. Is not a verb.
|
6
|
+
#
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Core
|
10
|
+
class Obj < Baseo
|
11
|
+
|
12
|
+
attr_accessor :value
|
13
|
+
attr_reader :children, :parent
|
14
|
+
|
15
|
+
#
|
16
|
+
# Set up the object.
|
17
|
+
#
|
18
|
+
def initialize
|
19
|
+
@value = ''
|
20
|
+
@children = []
|
21
|
+
@parent = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Register object types when they are loaded.
|
26
|
+
#
|
27
|
+
def self.inherited( subclass )
|
28
|
+
Dictionary.instance.register_obj( subclass )
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# The name of the object type.
|
33
|
+
#
|
34
|
+
def self.typename
|
35
|
+
raise 'this method should be overriden'
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# The object type, suitable for display.
|
40
|
+
#
|
41
|
+
def type_display
|
42
|
+
return self.class.typename
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Set the parent for the object.
|
47
|
+
#
|
48
|
+
def set_parent( obj )
|
49
|
+
@parent = obj
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Is this the root object?
|
54
|
+
#
|
55
|
+
def root?
|
56
|
+
return false if @parent
|
57
|
+
return false unless name.downcase == 'root'
|
58
|
+
|
59
|
+
return true
|
60
|
+
end
|
61
|
+
|
62
|
+
# Can this object be created?
|
63
|
+
# This is true by default and only false for some special cases
|
64
|
+
# such as the System object.
|
65
|
+
def self.can_create?
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Get the path and name to this object.
|
71
|
+
#
|
72
|
+
def pn
|
73
|
+
str = self.name
|
74
|
+
p = self.parent
|
75
|
+
while p && !p.root?
|
76
|
+
str = "#{p.name}.#{str}"
|
77
|
+
p = p.parent
|
78
|
+
end
|
79
|
+
return str
|
80
|
+
end
|
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
|
+
|
90
|
+
# ---------------------------------------------------------------------
|
91
|
+
# Value
|
92
|
+
# ---------------------------------------------------------------------
|
93
|
+
|
94
|
+
#
|
95
|
+
# Set the value with any necessary type conversions.
|
96
|
+
#
|
97
|
+
def set_value( new_value )
|
98
|
+
self.value = new_value
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Get the value for display purposes.
|
103
|
+
#
|
104
|
+
def value_display
|
105
|
+
return self.value.to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Does this object support multi-line values?
|
110
|
+
# Initially only true for scripts.
|
111
|
+
#
|
112
|
+
def multiline_value?
|
113
|
+
return false
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Is the value a String?
|
118
|
+
#
|
119
|
+
def value_string?
|
120
|
+
return self.value.is_a? String
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Is the value an Array?
|
125
|
+
#
|
126
|
+
def value_is_array?
|
127
|
+
return self.value.is_a? Array
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Is the value a blank string?
|
132
|
+
#
|
133
|
+
def value_is_blank?
|
134
|
+
return true if value.nil?
|
135
|
+
|
136
|
+
return self.value.to_s.strip.empty?
|
137
|
+
end
|
138
|
+
|
139
|
+
# ---------------------------------------------------------------------
|
140
|
+
# Children
|
141
|
+
# ---------------------------------------------------------------------
|
142
|
+
|
143
|
+
#
|
144
|
+
# Find a child of the given name.
|
145
|
+
# If found, return it. If not found create it.
|
146
|
+
#
|
147
|
+
def find_add_child( name, type )
|
148
|
+
child = self.find_child( name )
|
149
|
+
return child if child
|
150
|
+
|
151
|
+
params = { :name => name,
|
152
|
+
:type => type,
|
153
|
+
:value => nil,
|
154
|
+
:parent => self }
|
155
|
+
return $engine.factory.create params
|
156
|
+
end
|
157
|
+
|
158
|
+
#
|
159
|
+
# Add a child object to the container.
|
160
|
+
#
|
161
|
+
def add_child( obj )
|
162
|
+
@children << obj
|
163
|
+
obj.set_parent self
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Get the number of children.
|
168
|
+
#
|
169
|
+
def child_count
|
170
|
+
return @children.count
|
171
|
+
end
|
172
|
+
|
173
|
+
#
|
174
|
+
# Does this object contain an object with the given name?
|
175
|
+
#
|
176
|
+
def contains_child?( name )
|
177
|
+
@children.each do |o|
|
178
|
+
return true if name.downcase == o.name.downcase
|
179
|
+
end
|
180
|
+
return false
|
181
|
+
end
|
182
|
+
|
183
|
+
#
|
184
|
+
# Find a child object with the given name.
|
185
|
+
#
|
186
|
+
def find_child( name )
|
187
|
+
if name.end_with?( GlooLang::Objs::Alias::ALIAS_REFERENCE )
|
188
|
+
name = name[ 0..-2 ]
|
189
|
+
end
|
190
|
+
|
191
|
+
@children.each do |o|
|
192
|
+
return o if name.downcase == o.name.downcase
|
193
|
+
end
|
194
|
+
|
195
|
+
if self.type_display == GlooLang::Objs::Alias.typename
|
196
|
+
ln = GlooLang::Core::Pn.new( self.value )
|
197
|
+
redirect = ln.resolve
|
198
|
+
return redirect.find_child( name )
|
199
|
+
end
|
200
|
+
return nil
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# Delete all children from the container.
|
205
|
+
#
|
206
|
+
def delete_children
|
207
|
+
@children.reverse.each do |o|
|
208
|
+
self.remove_child o
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# Remove the object from the children collection.
|
214
|
+
#
|
215
|
+
def remove_child( obj )
|
216
|
+
@children.delete obj
|
217
|
+
end
|
218
|
+
|
219
|
+
# Does this object have children to add when an object
|
220
|
+
# is created in interactive mode?
|
221
|
+
# This does not apply during obj load, etc.
|
222
|
+
def add_children_on_create?
|
223
|
+
return false
|
224
|
+
end
|
225
|
+
|
226
|
+
# Add children to this object.
|
227
|
+
# This is used by containers to add children needed
|
228
|
+
# for default configurations.
|
229
|
+
def add_default_children
|
230
|
+
# Override this.
|
231
|
+
end
|
232
|
+
|
233
|
+
# ---------------------------------------------------------------------
|
234
|
+
# Messages
|
235
|
+
# ---------------------------------------------------------------------
|
236
|
+
|
237
|
+
#
|
238
|
+
# Get a list of message names that this object receives.
|
239
|
+
#
|
240
|
+
def self.messages
|
241
|
+
return %w[unload]
|
242
|
+
end
|
243
|
+
|
244
|
+
#
|
245
|
+
# Can this object receive a message?
|
246
|
+
#
|
247
|
+
def can_receive_message?( msg )
|
248
|
+
msgs = self.class.messages
|
249
|
+
return msgs.include?( msg.strip.downcase )
|
250
|
+
end
|
251
|
+
|
252
|
+
#
|
253
|
+
# Sent this object the given message.
|
254
|
+
#
|
255
|
+
def send_message( msg, params = nil )
|
256
|
+
@params = params
|
257
|
+
return self.dispatch msg if self.can_receive_message? msg
|
258
|
+
|
259
|
+
$log.error "Object #{self.name} cannot receive message #{msg}"
|
260
|
+
return false
|
261
|
+
end
|
262
|
+
|
263
|
+
#
|
264
|
+
# Dispatch the message to the object.
|
265
|
+
#
|
266
|
+
def dispatch( msg )
|
267
|
+
o = "msg_#{msg}"
|
268
|
+
if self.respond_to? o
|
269
|
+
self.public_send( o )
|
270
|
+
return true
|
271
|
+
else
|
272
|
+
$log.error "Message #{msg} not implemented"
|
273
|
+
return false
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
#
|
278
|
+
# Send the object the unload message.
|
279
|
+
#
|
280
|
+
def msg_unload
|
281
|
+
if self.root?
|
282
|
+
$log.error 'Cannot unload the root object.'
|
283
|
+
return
|
284
|
+
end
|
285
|
+
|
286
|
+
$engine.event_manager.on_unload self
|
287
|
+
$engine.heap.unload self
|
288
|
+
end
|
289
|
+
|
290
|
+
# ---------------------------------------------------------------------
|
291
|
+
# Help
|
292
|
+
# ---------------------------------------------------------------------
|
293
|
+
|
294
|
+
#
|
295
|
+
# Get help for this object.
|
296
|
+
#
|
297
|
+
def self.help
|
298
|
+
return 'No help found.'
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Utility used to find objects.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Core
|
9
|
+
class ObjFinder
|
10
|
+
|
11
|
+
#
|
12
|
+
# Find all objects in the given container that have
|
13
|
+
# the given name.
|
14
|
+
# If the container isn't provided, root will be used.
|
15
|
+
#
|
16
|
+
def self.by_name( name, container = nil )
|
17
|
+
container = $engine.heap.root if container.nil?
|
18
|
+
arr = []
|
19
|
+
|
20
|
+
container.children.each do |o|
|
21
|
+
arr << o if o.name == name
|
22
|
+
arr += by_name( name, o ) if o.child_count.positive?
|
23
|
+
end
|
24
|
+
|
25
|
+
return arr
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An Operator; part of an expression.
|
5
|
+
# A static helper class.
|
6
|
+
#
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Core
|
10
|
+
class Op
|
11
|
+
|
12
|
+
#
|
13
|
+
# Is the token an operator?
|
14
|
+
#
|
15
|
+
def self.op?( token )
|
16
|
+
return [ '+', '-', '*', '/' ].include?( token.strip )
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Create the operator for the given token.
|
21
|
+
#
|
22
|
+
def self.create_op( token )
|
23
|
+
return GlooLang::Expr::OpMinus.new if token == '-'
|
24
|
+
return GlooLang::Expr::OpMult.new if token == '*'
|
25
|
+
return GlooLang::Expr::OpDiv.new if token == '/'
|
26
|
+
return GlooLang::Expr::OpPlus.new if token == '+'
|
27
|
+
|
28
|
+
return default_op
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Get the default operator (+).
|
33
|
+
#
|
34
|
+
def self.default_op
|
35
|
+
return GlooLang::Expr::OpPlus.new
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# The Parser.
|
5
|
+
# Can parse single line commands or files.
|
6
|
+
#
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Core
|
10
|
+
class Parser
|
11
|
+
|
12
|
+
#
|
13
|
+
# Set up the parser.
|
14
|
+
#
|
15
|
+
def initialize
|
16
|
+
$log.debug 'parser intialized...'
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Parse a command from the immediate execution context.
|
21
|
+
#
|
22
|
+
def parse_immediate( cmd )
|
23
|
+
cmd, params = split_params cmd
|
24
|
+
params = GlooLang::Core::Tokens.new( params ) if params
|
25
|
+
tokens = GlooLang::Core::Tokens.new( cmd )
|
26
|
+
dic = GlooLang::Core::Dictionary.instance
|
27
|
+
verb = dic.find_verb( tokens.verb )
|
28
|
+
return verb.new( tokens, params ) if verb
|
29
|
+
|
30
|
+
$log.error "Verb '#{tokens.verb}' was not found."
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# If additional params were provided, split them out
|
36
|
+
# from the token list.
|
37
|
+
#
|
38
|
+
def split_params( cmd )
|
39
|
+
params = nil
|
40
|
+
i = cmd.rindex( '(' )
|
41
|
+
if i && cmd.strip.end_with?( ')' )
|
42
|
+
pstr = cmd[ i + 1..-1 ]
|
43
|
+
params = pstr.strip[ 0..-2 ] if pstr
|
44
|
+
cmd = cmd[ 0, i - 1 ]
|
45
|
+
end
|
46
|
+
return cmd, params
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Parse a command and then run it if it parsed correctly.
|
51
|
+
#
|
52
|
+
def run( cmd )
|
53
|
+
v = parse_immediate( cmd )
|
54
|
+
GlooLang::Exec::Runner.go( v ) if v
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An object path name.
|
5
|
+
# Path and name elements are separated by periods.
|
6
|
+
#
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Core
|
10
|
+
class Pn < Baseo
|
11
|
+
|
12
|
+
ROOT = 'root'.freeze
|
13
|
+
IT = 'it'.freeze
|
14
|
+
ERROR = 'error'.freeze
|
15
|
+
|
16
|
+
attr_reader :src, :elements
|
17
|
+
|
18
|
+
#
|
19
|
+
# Set up the object given a source string,
|
20
|
+
# ie: the full path and name.
|
21
|
+
#
|
22
|
+
def initialize( src )
|
23
|
+
set_to src
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Reference to the root object path.
|
28
|
+
#
|
29
|
+
def self.root
|
30
|
+
return Pn.new( ROOT )
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Reference to it.
|
35
|
+
#
|
36
|
+
def self.it
|
37
|
+
return Pn.new( IT )
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Reference to the error message.
|
42
|
+
#
|
43
|
+
def self.error
|
44
|
+
return Pn.new( ERROR )
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Does the pathname reference refer to the root?
|
49
|
+
#
|
50
|
+
def root?
|
51
|
+
return @src.downcase == ROOT
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Does the pathname reference refer to it?
|
56
|
+
#
|
57
|
+
def it?
|
58
|
+
return @src.downcase == IT
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Does the pathname reference refer to error?
|
63
|
+
#
|
64
|
+
def error?
|
65
|
+
return @src.downcase == ERROR
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Does the pathname reference refer to the gloo system object?
|
70
|
+
#
|
71
|
+
def gloo_sys?
|
72
|
+
return false unless @elements&.count&.positive?
|
73
|
+
|
74
|
+
o = @elements.first.downcase
|
75
|
+
return true if o == GlooLang::Core::GlooSystem.typename
|
76
|
+
return true if o == GlooLang::Core::GlooSystem.short_typename
|
77
|
+
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Get the string representation of the pathname.
|
83
|
+
#
|
84
|
+
def to_s
|
85
|
+
return @src
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Set the object pathname to the given value.
|
90
|
+
#
|
91
|
+
def set_to( value )
|
92
|
+
@src = value.nil? ? nil : value.strip
|
93
|
+
@elements = @src.nil? ? [] : @src.split( '.' )
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Convert the raw string to a list of segments.
|
98
|
+
#
|
99
|
+
def segments
|
100
|
+
return @elements
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Get the name element.
|
105
|
+
#
|
106
|
+
def name
|
107
|
+
return '' unless self.named?
|
108
|
+
|
109
|
+
return @elements.last
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Does the value include path elements?
|
114
|
+
#
|
115
|
+
def named?
|
116
|
+
return @elements.count.positive?
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Does the value include a name?
|
121
|
+
#
|
122
|
+
def includes_path?
|
123
|
+
return @elements.count > 1
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# Get the parent that contains the object referenced.
|
128
|
+
#
|
129
|
+
def get_parent
|
130
|
+
o = $engine.heap.root
|
131
|
+
|
132
|
+
if self.includes_path?
|
133
|
+
@elements[ 0..-2 ].each do |e|
|
134
|
+
o = o.find_child( e )
|
135
|
+
if o.nil?
|
136
|
+
$log.error "Object '#{e}' was not found."
|
137
|
+
return nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
return o
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# Does the object at the path exist?
|
147
|
+
#
|
148
|
+
def exists?
|
149
|
+
return true if self.root?
|
150
|
+
return true if self.it?
|
151
|
+
return true if self.error?
|
152
|
+
|
153
|
+
parent = self.get_parent
|
154
|
+
return false unless parent
|
155
|
+
|
156
|
+
return parent.contains_child? name
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# Is the reference to a color?
|
161
|
+
#
|
162
|
+
def named_color?
|
163
|
+
colors = %w[red blue green white black yellow]
|
164
|
+
return true if colors.include?( @src.downcase )
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
# Resolve the pathname reference.
|
169
|
+
# Find the object referenced or return nil if it is not found.
|
170
|
+
#
|
171
|
+
def resolve
|
172
|
+
return $engine.heap.root if self.root?
|
173
|
+
return $engine.heap.it if self.it?
|
174
|
+
return $engine.heap.error if self.error?
|
175
|
+
return GlooLang::Core::GlooSystem.new( self ) if self.gloo_sys?
|
176
|
+
|
177
|
+
Here.expand_here( self ) if Here.includes_here_ref?( @elements )
|
178
|
+
|
179
|
+
parent = self.get_parent
|
180
|
+
return nil unless parent
|
181
|
+
|
182
|
+
obj = parent.find_child( self.name )
|
183
|
+
return GlooLang::Objs::Alias.resolve_alias( obj, self.src )
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|