gloo-lang 0.9.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/lib/VERSION +1 -1
  3. data/lib/dependencies.rb +2 -2
  4. data/lib/{gloo_lang.rb → gloo-lang.rb} +7 -9
  5. data/lib/gloo_lang/app/args.rb +112 -0
  6. data/lib/gloo_lang/app/engine.rb +230 -0
  7. data/lib/gloo_lang/app/help.rb +156 -0
  8. data/lib/gloo_lang/app/log.rb +81 -0
  9. data/lib/gloo_lang/app/mode.rb +27 -0
  10. data/lib/gloo_lang/app/settings.rb +186 -0
  11. data/lib/gloo_lang/convert/converter.rb +35 -0
  12. data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
  13. data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
  14. data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
  15. data/lib/gloo_lang/core/baseo.rb +30 -0
  16. data/lib/gloo_lang/core/dictionary.rb +181 -0
  17. data/lib/gloo_lang/core/error.rb +61 -0
  18. data/lib/gloo_lang/core/event_manager.rb +44 -0
  19. data/lib/gloo_lang/core/factory.rb +210 -0
  20. data/lib/gloo_lang/core/gloo_system.rb +266 -0
  21. data/lib/gloo_lang/core/heap.rb +52 -0
  22. data/lib/gloo_lang/core/here.rb +36 -0
  23. data/lib/gloo_lang/core/it.rb +36 -0
  24. data/lib/gloo_lang/core/literal.rb +30 -0
  25. data/lib/gloo_lang/core/obj.rb +303 -0
  26. data/lib/gloo_lang/core/obj_finder.rb +30 -0
  27. data/lib/gloo_lang/core/op.rb +40 -0
  28. data/lib/gloo_lang/core/parser.rb +59 -0
  29. data/lib/gloo_lang/core/pn.rb +188 -0
  30. data/lib/gloo_lang/core/tokens.rb +165 -0
  31. data/lib/gloo_lang/core/verb.rb +86 -0
  32. data/lib/gloo_lang/exec/action.rb +48 -0
  33. data/lib/gloo_lang/exec/dispatch.rb +40 -0
  34. data/lib/gloo_lang/exec/exec_env.rb +74 -0
  35. data/lib/gloo_lang/exec/runner.rb +45 -0
  36. data/lib/gloo_lang/exec/script.rb +49 -0
  37. data/lib/gloo_lang/exec/stack.rb +78 -0
  38. data/lib/gloo_lang/expr/expression.rb +118 -0
  39. data/lib/gloo_lang/expr/l_boolean.rb +36 -0
  40. data/lib/gloo_lang/expr/l_decimal.rb +39 -0
  41. data/lib/gloo_lang/expr/l_integer.rb +37 -0
  42. data/lib/gloo_lang/expr/l_string.rb +58 -0
  43. data/lib/gloo_lang/expr/op_div.rb +22 -0
  44. data/lib/gloo_lang/expr/op_minus.rb +22 -0
  45. data/lib/gloo_lang/expr/op_mult.rb +22 -0
  46. data/lib/gloo_lang/expr/op_plus.rb +24 -0
  47. data/lib/gloo_lang/help/app/application.txt +22 -0
  48. data/lib/gloo_lang/help/app/configuration.txt +7 -0
  49. data/lib/gloo_lang/help/app/default_help.txt +14 -0
  50. data/lib/gloo_lang/help/app/logging.txt +16 -0
  51. data/lib/gloo_lang/help/core/color.txt +31 -0
  52. data/lib/gloo_lang/help/core/error.txt +33 -0
  53. data/lib/gloo_lang/help/core/events.txt +21 -0
  54. data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
  55. data/lib/gloo_lang/help/core/here.txt +30 -0
  56. data/lib/gloo_lang/help/core/it.txt +23 -0
  57. data/lib/gloo_lang/help/core/ops.txt +16 -0
  58. data/lib/gloo_lang/help/core/pathname.txt +29 -0
  59. data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
  60. data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
  61. data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
  62. data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
  63. data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
  64. data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
  65. data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
  66. data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
  67. data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
  68. data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
  69. data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
  70. data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
  71. data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
  72. data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
  73. data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
  74. data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
  75. data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
  76. data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
  77. data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
  78. data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
  79. data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
  80. data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
  81. data/lib/gloo_lang/help/objs/data/query.txt +37 -0
  82. data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
  83. data/lib/gloo_lang/help/objs/data/table.txt +46 -0
  84. data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
  85. data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
  86. data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
  87. data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
  88. data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
  89. data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
  90. data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
  91. data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
  92. data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
  93. data/lib/gloo_lang/help/objs/system/file.txt +48 -0
  94. data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
  95. data/lib/gloo_lang/help/objs/system/system.txt +32 -0
  96. data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
  97. data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
  98. data/lib/gloo_lang/help/objs/web/json.txt +34 -0
  99. data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
  100. data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
  101. data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
  102. data/lib/gloo_lang/help/verbs/alert.txt +33 -0
  103. data/lib/gloo_lang/help/verbs/beep.txt +25 -0
  104. data/lib/gloo_lang/help/verbs/cls.txt +24 -0
  105. data/lib/gloo_lang/help/verbs/context.txt +43 -0
  106. data/lib/gloo_lang/help/verbs/create.txt +33 -0
  107. data/lib/gloo_lang/help/verbs/execute.txt +27 -0
  108. data/lib/gloo_lang/help/verbs/help.txt +34 -0
  109. data/lib/gloo_lang/help/verbs/if.txt +37 -0
  110. data/lib/gloo_lang/help/verbs/list.txt +34 -0
  111. data/lib/gloo_lang/help/verbs/load.txt +38 -0
  112. data/lib/gloo_lang/help/verbs/move.txt +42 -0
  113. data/lib/gloo_lang/help/verbs/put.txt +38 -0
  114. data/lib/gloo_lang/help/verbs/quit.txt +25 -0
  115. data/lib/gloo_lang/help/verbs/run.txt +41 -0
  116. data/lib/gloo_lang/help/verbs/save.txt +26 -0
  117. data/lib/gloo_lang/help/verbs/show.txt +30 -0
  118. data/lib/gloo_lang/help/verbs/tell.txt +34 -0
  119. data/lib/gloo_lang/help/verbs/unless.txt +38 -0
  120. data/lib/gloo_lang/help/verbs/version.txt +32 -0
  121. data/lib/gloo_lang/help/verbs/wait.txt +29 -0
  122. data/lib/gloo_lang/objs/basic/alias.rb +78 -0
  123. data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
  124. data/lib/gloo_lang/objs/basic/container.rb +76 -0
  125. data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
  126. data/lib/gloo_lang/objs/basic/integer.rb +73 -0
  127. data/lib/gloo_lang/objs/basic/script.rb +99 -0
  128. data/lib/gloo_lang/objs/basic/string.rb +77 -0
  129. data/lib/gloo_lang/objs/basic/text.rb +87 -0
  130. data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
  131. data/lib/gloo_lang/objs/cli/banner.rb +108 -0
  132. data/lib/gloo_lang/objs/cli/bar.rb +133 -0
  133. data/lib/gloo_lang/objs/cli/colorize.rb +73 -0
  134. data/lib/gloo_lang/objs/cli/confirm.rb +96 -0
  135. data/lib/gloo_lang/objs/cli/menu.rb +206 -0
  136. data/lib/gloo_lang/objs/cli/menu_item.rb +95 -0
  137. data/lib/gloo_lang/objs/cli/pastel.rb +97 -0
  138. data/lib/gloo_lang/objs/cli/prompt.rb +110 -0
  139. data/lib/gloo_lang/objs/cli/select.rb +126 -0
  140. data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
  141. data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
  142. data/lib/gloo_lang/objs/data/markdown.rb +84 -0
  143. data/lib/gloo_lang/objs/data/mysql.rb +192 -0
  144. data/lib/gloo_lang/objs/data/query.rb +176 -0
  145. data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
  146. data/lib/gloo_lang/objs/data/table.rb +140 -0
  147. data/lib/gloo_lang/objs/dev/git.rb +140 -0
  148. data/lib/gloo_lang/objs/dev/stats.rb +120 -0
  149. data/lib/gloo_lang/objs/dt/date.rb +50 -0
  150. data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
  151. data/lib/gloo_lang/objs/dt/time.rb +50 -0
  152. data/lib/gloo_lang/objs/ror/erb.rb +116 -0
  153. data/lib/gloo_lang/objs/ror/eval.rb +107 -0
  154. data/lib/gloo_lang/objs/snd/play.rb +48 -0
  155. data/lib/gloo_lang/objs/snd/say.rb +98 -0
  156. data/lib/gloo_lang/objs/system/file_handle.rb +138 -0
  157. data/lib/gloo_lang/objs/system/ssh_exec.rb +126 -0
  158. data/lib/gloo_lang/objs/system/system.rb +136 -0
  159. data/lib/gloo_lang/objs/web/http_get.rb +159 -0
  160. data/lib/gloo_lang/objs/web/http_post.rb +183 -0
  161. data/lib/gloo_lang/objs/web/json.rb +135 -0
  162. data/lib/gloo_lang/objs/web/slack.rb +130 -0
  163. data/lib/gloo_lang/objs/web/teams.rb +117 -0
  164. data/lib/gloo_lang/objs/web/uri.rb +148 -0
  165. data/lib/gloo_lang/persist/file_loader.rb +191 -0
  166. data/lib/gloo_lang/persist/file_saver.rb +49 -0
  167. data/lib/gloo_lang/persist/file_storage.rb +45 -0
  168. data/lib/gloo_lang/persist/line_splitter.rb +81 -0
  169. data/lib/gloo_lang/persist/persist_man.rb +120 -0
  170. data/lib/gloo_lang/utils/format.rb +21 -0
  171. data/lib/gloo_lang/utils/stats.rb +205 -0
  172. data/lib/gloo_lang/utils/words.rb +19 -0
  173. data/lib/gloo_lang/verbs/alert.rb +79 -0
  174. data/lib/gloo_lang/verbs/beep.rb +40 -0
  175. data/lib/gloo_lang/verbs/cls.rb +37 -0
  176. data/lib/gloo_lang/verbs/context.rb +62 -0
  177. data/lib/gloo_lang/verbs/create.rb +68 -0
  178. data/lib/gloo_lang/verbs/execute.rb +56 -0
  179. data/lib/gloo_lang/verbs/help.rb +264 -0
  180. data/lib/gloo_lang/verbs/if.rb +92 -0
  181. data/lib/gloo_lang/verbs/list.rb +98 -0
  182. data/lib/gloo_lang/verbs/load.rb +45 -0
  183. data/lib/gloo_lang/verbs/move.rb +89 -0
  184. data/lib/gloo_lang/verbs/put.rb +94 -0
  185. data/lib/gloo_lang/verbs/quit.rb +40 -0
  186. data/lib/gloo_lang/verbs/run.rb +75 -0
  187. data/lib/gloo_lang/verbs/save.rb +39 -0
  188. data/lib/gloo_lang/verbs/show.rb +64 -0
  189. data/lib/gloo_lang/verbs/tell.rb +79 -0
  190. data/lib/gloo_lang/verbs/unless.rb +92 -0
  191. data/lib/gloo_lang/verbs/version.rb +37 -0
  192. data/lib/gloo_lang/verbs/wait.rb +42 -0
  193. metadata +191 -3
@@ -0,0 +1,264 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Show the help information.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Help < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'help'.freeze
12
+ KEYWORD_SHORT = '?'.freeze
13
+ DEFAULT_HELP = 'default_help'.freeze
14
+ HELP_NOT_FOUND_ERR = 'Help command could not be found:'.freeze
15
+
16
+ DISPATCH = {
17
+ settings: 'show_settings',
18
+ keywords: 'show_keywords',
19
+ verb: 'show_verbs',
20
+ verbs: 'show_verbs',
21
+ v: 'show_verbs',
22
+ obj: 'show_objs',
23
+ object: 'show_objs',
24
+ objects: 'show_objs',
25
+ o: 'show_objs',
26
+ topics: 'show_topics'
27
+ }.freeze
28
+
29
+ #
30
+ # Run the verb.
31
+ #
32
+ def run
33
+ opts = @tokens.second if @tokens
34
+ opts = opts.strip.downcase if opts
35
+
36
+ if opts
37
+ dispatch opts
38
+ else
39
+ $engine.help.page_topic DEFAULT_HELP
40
+ end
41
+ end
42
+
43
+ #
44
+ # Get the text for the list of verbs.
45
+ #
46
+ def get_verb_list
47
+ out = "Verbs:\n"
48
+ str = ''
49
+ verbs = $engine.dictionary.get_verbs.sort_by( &:keyword )
50
+ verbs.each_with_index do |v, i|
51
+ cut = v.keyword_shortcut.ljust( 5, ' ' )
52
+ str << " #{cut} #{v.keyword.ljust( 20, ' ' )}"
53
+ if ( ( i + 1 ) % 3 ).zero?
54
+ out << "#{str}\n"
55
+ str = ''
56
+ end
57
+ end
58
+
59
+ return out
60
+ end
61
+
62
+ #
63
+ # Lookup the opts in the dispatch table.
64
+ #
65
+ def lookup_opts( opts )
66
+ return DISPATCH[ opts.to_sym ]
67
+ end
68
+
69
+ #
70
+ # Get the text for the list of verbs.
71
+ #
72
+ def get_obj_list
73
+ out = "Object Types:\n"
74
+ str = ''
75
+ objs = $engine.dictionary.get_obj_types.sort_by( &:typename )
76
+ objs.each_with_index do |o, i|
77
+ name = o.typename
78
+ if o.short_typename != o.typename
79
+ name = "#{name} (#{o.short_typename})"
80
+ end
81
+ str << " #{name.ljust( 30, ' ' )}"
82
+ if ( ( i + 1 ) % 4 ).zero?
83
+ out << "#{str}\n"
84
+ str = ''
85
+ end
86
+ end
87
+
88
+ return out
89
+ end
90
+
91
+ #
92
+ # Get the list of help topics.
93
+ #
94
+ def get_topics
95
+ out = "Help Topics:\n"
96
+ str = ''
97
+ objs = $engine.help.topics.keys.sort
98
+ objs.each_with_index do |o, i|
99
+ str << " #{o.ljust( 30, ' ' )}"
100
+ if ( ( i + 1 ) % 4 ).zero?
101
+ out << "#{str}\n"
102
+ str = ''
103
+ end
104
+ end
105
+
106
+ return out
107
+ end
108
+
109
+ #
110
+ # Get the Verb's keyword.
111
+ #
112
+ def self.keyword
113
+ return KEYWORD
114
+ end
115
+
116
+ #
117
+ # Get the Verb's keyword shortcut.
118
+ #
119
+ def self.keyword_shortcut
120
+ return KEYWORD_SHORT
121
+ end
122
+
123
+ # ---------------------------------------------------------------------
124
+ # Private functions
125
+ # ---------------------------------------------------------------------
126
+
127
+ private
128
+
129
+ #
130
+ # Report an error with the inline help.
131
+ #
132
+ def report_help_error( opts )
133
+ $engine.err "#{HELP_NOT_FOUND_ERR} '#{opts}'"
134
+ end
135
+
136
+ #
137
+ # Dispatch the help to the right place.
138
+ #
139
+ def dispatch( opts )
140
+ return if dispatch_help_page( opts )
141
+
142
+ $log.debug 'looking for built in help topic'
143
+ cmd = DISPATCH[ opts.to_sym ]
144
+ if cmd
145
+ $log.debug 'found help index'
146
+ send cmd
147
+ else
148
+ $log.debug 'looking for entity help'
149
+ entity_help opts
150
+ end
151
+ rescue
152
+ report_help_error opts
153
+ end
154
+
155
+ #
156
+ # Dispatch to a help page if we can find one.
157
+ #
158
+ def dispatch_help_page( opts )
159
+ if $engine.help.topic? opts
160
+ $log.debug 'found expanded help topic'
161
+ $engine.help.page_topic opts
162
+ return true
163
+ end
164
+
165
+ key = $engine.dictionary.lookup_keyword opts
166
+ if $engine.help.topic? key
167
+ $log.debug 'found expanded help topic'
168
+ $engine.help.page_topic key
169
+ return true
170
+ end
171
+
172
+ return false
173
+ end
174
+
175
+ #
176
+ # Write output to it and show it unless we are in
177
+ # silent mode.
178
+ #
179
+ def show_output( out )
180
+ $engine.heap.it.set_to out
181
+ puts out unless $engine.args.quiet?
182
+ end
183
+
184
+ #
185
+ # List all help topics (articles)
186
+ #
187
+ def show_topics
188
+ out = self.get_topics
189
+ show_output out
190
+ end
191
+
192
+ #
193
+ # Dispatch the help command to a verb or object
194
+ # if we can find one matching the request.
195
+ #
196
+ def entity_help( opts )
197
+ return if try_verb_help opts
198
+ return if try_object_help opts
199
+
200
+ report_help_error opts
201
+ end
202
+
203
+ #
204
+ # See if there is a verb we can show help
205
+ # information about.
206
+ #
207
+ def try_verb_help( opts )
208
+ if $engine.dictionary.verb?( opts )
209
+ t = $engine.dictionary.find_verb( opts )
210
+ out = t.send 'help'
211
+ show_output out
212
+ return true
213
+ end
214
+
215
+ return false
216
+ end
217
+
218
+ #
219
+ # See if there is a verb we can show help
220
+ # information about.
221
+ #
222
+ def try_object_help( opts )
223
+ if $engine.dictionary.obj?( opts )
224
+ t = $engine.dictionary.find_obj( opts )
225
+ out = t.send 'help'
226
+ show_output out
227
+ return true
228
+ end
229
+
230
+ return false
231
+ end
232
+
233
+ #
234
+ # Show application settings.
235
+ #
236
+ def show_settings
237
+ $settings.show
238
+ end
239
+
240
+ #
241
+ # Show all keywords: verbs and objects.
242
+ #
243
+ def show_keywords
244
+ $engine.dictionary.show_keywords
245
+ end
246
+
247
+ #
248
+ # List the verbs
249
+ #
250
+ def show_verbs
251
+ show_output get_verb_list
252
+ end
253
+
254
+ #
255
+ # List the object types
256
+ #
257
+ def show_objs
258
+ out = self.get_obj_list
259
+ show_output out
260
+ end
261
+
262
+ end
263
+ end
264
+ end
@@ -0,0 +1,92 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # If something is true, do something.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class If < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'if'.freeze
12
+ KEYWORD_SHORT = 'if'.freeze
13
+ THEN = 'then'.freeze
14
+ MISSING_EXPR_ERR = 'Missing Expression!'.freeze
15
+
16
+ #
17
+ # Run the verb.
18
+ #
19
+ def run
20
+ value = value_tokens
21
+ return if value.nil?
22
+
23
+ return unless evals_true( value )
24
+
25
+ run_then
26
+ end
27
+
28
+ #
29
+ # Get the Verb's keyword.
30
+ #
31
+ def self.keyword
32
+ return KEYWORD
33
+ end
34
+
35
+ #
36
+ # Get the Verb's keyword shortcut.
37
+ #
38
+ def self.keyword_shortcut
39
+ return KEYWORD_SHORT
40
+ end
41
+
42
+ # ---------------------------------------------------------------------
43
+ # Private functions
44
+ # ---------------------------------------------------------------------
45
+
46
+ private
47
+
48
+ #
49
+ # Get the list of tokens that represent the parameters
50
+ # of the if command.
51
+ #
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 = GlooLang::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
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,98 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # List out an object and it's children.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class List < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'list'.freeze
12
+ KEYWORD_SHORT = '.'.freeze
13
+ TARGET_MISSING_ERR = 'Object does not exist: '.freeze
14
+
15
+ #
16
+ # Run the verb.
17
+ #
18
+ def run
19
+ levels = determine_levels
20
+ target = self.determine_target
21
+ obj = target.resolve
22
+ if obj
23
+ show_target( obj, levels )
24
+ else
25
+ $engine.err "#{TARGET_MISSING_ERR} #{target}"
26
+ end
27
+ end
28
+
29
+ #
30
+ # Determine the target object for the show command.
31
+ #
32
+ def determine_target
33
+ return $engine.heap.context if @tokens.token_count == 1
34
+
35
+ return GlooLang::Core::Pn.new( @tokens.second )
36
+ end
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
+ #
59
+ # Show the target object.
60
+ #
61
+ def show_target( obj, levels, indent = '' )
62
+ show_obj( obj, indent )
63
+ return if levels.zero?
64
+
65
+ obj.children.each do |o|
66
+ show_target( o, levels - 1, "#{indent} " )
67
+ end
68
+ end
69
+
70
+ #
71
+ # Show object in standard format.
72
+ #
73
+ def show_obj( obj, indent = ' ' )
74
+ if obj.multiline_value? && obj.value_is_array?
75
+ $log.show "#{indent}#{obj.name} [#{obj.type_display}] :"
76
+ obj.value.each do |line|
77
+ $log.show "#{indent} #{line}"
78
+ end
79
+ else
80
+ $log.show "#{indent}#{obj.name} [#{obj.type_display}] : #{obj.value}"
81
+ end
82
+ end
83
+
84
+ #
85
+ # Determine how many levels to show.
86
+ #
87
+ def determine_levels
88
+ # Check settings for the default value.
89
+ levels = $settings.list_indent
90
+ return levels if levels
91
+
92
+ # Last chance: use the default
93
+ return 1
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,45 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Save an object to a file or other persistance mechcanism.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Load < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'load'.freeze
12
+ KEYWORD_SHORT = '<'.freeze
13
+ MISSING_EXPR_ERR = 'Missing Expression!'.freeze
14
+
15
+ #
16
+ # Run the verb.
17
+ #
18
+ def run
19
+ fn = @tokens.second
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
27
+ end
28
+
29
+ #
30
+ # Get the Verb's keyword.
31
+ #
32
+ def self.keyword
33
+ return KEYWORD
34
+ end
35
+
36
+ #
37
+ # Get the Verb's keyword shortcut.
38
+ #
39
+ def self.keyword_shortcut
40
+ return KEYWORD_SHORT
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,89 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Move an object to a new parent.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Move < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'move'.freeze
12
+ KEYWORD_SHORT = 'mv'.freeze
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
18
+
19
+ #
20
+ # Run the verb.
21
+ #
22
+ def run
23
+ dst = lookup_dst
24
+ return if dst.nil?
25
+
26
+ o = lookup_obj
27
+ return unless o
28
+
29
+ o.parent.remove_child o
30
+ dst.add_child o
31
+ end
32
+
33
+ #
34
+ # Get the Verb's keyword.
35
+ #
36
+ def self.keyword
37
+ return KEYWORD
38
+ end
39
+
40
+ #
41
+ # Get the Verb's keyword shortcut.
42
+ #
43
+ def self.keyword_shortcut
44
+ return KEYWORD_SHORT
45
+ end
46
+
47
+ # ---------------------------------------------------------------------
48
+ # Private functions
49
+ # ---------------------------------------------------------------------
50
+
51
+ private
52
+
53
+ #
54
+ # Lookup the object that we're moving.
55
+ #
56
+ def lookup_obj
57
+ arr = @tokens.before_token( TO )
58
+ if arr.count == 1
59
+ $engine.err MISSING_SRC_ERR
60
+ return
61
+ end
62
+
63
+ name = arr[ 1 ]
64
+ pn = GlooLang::Core::Pn.new name
65
+ o = pn.resolve
66
+
67
+ $engine.err( "#{MISSING_SRC_OBJ_ERR} #{name}" ) unless o
68
+ return o
69
+ end
70
+
71
+ #
72
+ # Lookup destination, the new parent object.
73
+ #
74
+ def lookup_dst
75
+ dst = @tokens.after_token( TO )
76
+ unless dst
77
+ $engine.err MISSING_DST_ERR
78
+ return nil
79
+ end
80
+
81
+ pn = GlooLang::Core::Pn.new dst
82
+ o = pn.resolve
83
+ $engine.err( "#{MISSING_DST_OBJ_ERR} '#{dst}'" ) unless o
84
+ return o
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,94 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Create an object, optionally of a type.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Put < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'put'.freeze
12
+ KEYWORD_SHORT = 'p'.freeze
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
17
+
18
+ #
19
+ # Run the verb.
20
+ #
21
+ def run
22
+ value = fetch_value_tokens
23
+ return if value.nil?
24
+
25
+ target = lookup_target
26
+ return if target.nil?
27
+
28
+ update_target target, value
29
+ end
30
+
31
+ #
32
+ # Get the Verb's keyword.
33
+ #
34
+ def self.keyword
35
+ return KEYWORD
36
+ end
37
+
38
+ #
39
+ # Get the Verb's keyword shortcut.
40
+ #
41
+ def self.keyword_shortcut
42
+ return KEYWORD_SHORT
43
+ end
44
+
45
+ # ---------------------------------------------------------------------
46
+ # Private functions
47
+ # ---------------------------------------------------------------------
48
+
49
+ private
50
+
51
+ #
52
+ # Get the value that is being put.
53
+ #
54
+ def fetch_value_tokens
55
+ value = @tokens.before_token( INTO )
56
+ if value.nil? || ( value.count <= 1 )
57
+ $engine.err MISSING_EXPR_ERR
58
+ return nil
59
+ end
60
+
61
+ # The first token is the verb, so we drop it.
62
+ return value[ 1..-1 ]
63
+ end
64
+
65
+ #
66
+ # Lookup the target of the put command.
67
+ #
68
+ def lookup_target
69
+ target = @tokens.after_token( INTO )
70
+ return target if target
71
+
72
+ $engine.err INTO_MISSING_ERR
73
+ return nil
74
+ end
75
+
76
+ #
77
+ # Update the target with the new value.
78
+ #
79
+ def update_target( target, value )
80
+ pn = GlooLang::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 = GlooLang::Expr::Expression.new( value )
86
+ result = expr.evaluate
87
+ o.set_value result
88
+ $engine.heap.it.set_to result
89
+ end
90
+ end
91
+
92
+ end
93
+ end
94
+ 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
+ # Quit the running gloo engine.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Quit < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'quit'.freeze
12
+ KEYWORD_SHORT = 'q'.freeze
13
+
14
+ #
15
+ # Run the verb.
16
+ #
17
+ # We'll mark the application as not running and let the
18
+ # engine stop gracefully next time through the loop.
19
+ #
20
+ def run
21
+ $engine.stop_running
22
+ end
23
+
24
+ #
25
+ # Get the Verb's keyword.
26
+ #
27
+ def self.keyword
28
+ return KEYWORD
29
+ end
30
+
31
+ #
32
+ # Get the Verb's keyword shortcut.
33
+ #
34
+ def self.keyword_shortcut
35
+ return KEYWORD_SHORT
36
+ end
37
+
38
+ end
39
+ end
40
+ end