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,205 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Utilities related to words (strings).
5
+ #
6
+
7
+ module GlooLang
8
+ module Utils
9
+ class Stats
10
+
11
+ DIR_NOT_FOUND_ERR = 'The folder was not found!'.freeze
12
+
13
+ # ---------------------------------------------------------------------
14
+ # Setup
15
+ # ---------------------------------------------------------------------
16
+
17
+ #
18
+ # Create a stats utility class for the given directory.
19
+ #
20
+ def initialize( dir, types, skip = [] )
21
+ @dir = dir
22
+ setup_loc types
23
+ @skip = skip
24
+ end
25
+
26
+ # ---------------------------------------------------------------------
27
+ # Public Functions
28
+ # ---------------------------------------------------------------------
29
+
30
+ #
31
+ # Is the stats utility valid?
32
+ # Does it have a valid root directory.
33
+ #
34
+ def valid?
35
+ return true if @dir && File.directory?( @dir )
36
+
37
+ $engine.err DIR_NOT_FOUND_ERR
38
+ $engine.heap.it.set_to false
39
+
40
+ return false
41
+ end
42
+
43
+ #
44
+ # Show all stat data for the project.
45
+ #
46
+ def show_all
47
+ return unless valid?
48
+
49
+ generate
50
+ puts "Showing All stats for #{@dir}".white
51
+ puts "\n ** #{@dir_cnt} Total Folders ** "
52
+ puts " ** #{@file_cnt} Total Files ** "
53
+
54
+ busy_folders( 7 )
55
+ file_types
56
+ loc
57
+ end
58
+
59
+ #
60
+ # Get a list of the busiest folders.
61
+ # Count is how many results we want.
62
+ #
63
+ def busy_folders( count = 17 )
64
+ return unless valid?
65
+
66
+ generate
67
+ puts "\nBusy Folders:".yellow
68
+
69
+ @folders.sort! { |a, b| a[ :cnt ] <=> b[ :cnt ] }
70
+ @folders.reverse!
71
+ @folders[ 0..count ].each do |f|
72
+ puts " #{f[ :cnt ]} - #{f[ :name ]}"
73
+ end
74
+ end
75
+
76
+ #
77
+ # Show file types and how many of each there are.
78
+ #
79
+ def file_types
80
+ return unless valid?
81
+
82
+ generate
83
+ puts "\nFiles by Type:".yellow
84
+
85
+ @types = @types.sort_by( &:last )
86
+ @types.reverse!
87
+ @types.each do |o|
88
+ puts " #{o[ 1 ]} - #{o[ 0 ]}" unless o[ 0 ].empty?
89
+ end
90
+ end
91
+
92
+ #
93
+ # Show Lines of Code
94
+ #
95
+ def loc
96
+ return unless valid?
97
+
98
+ generate
99
+ total = 0
100
+
101
+ @loc.each do |k, v|
102
+ puts "\n #{k} Lines of Code".yellow
103
+ total += v[ :lines ]
104
+ formatted = GlooLang::Utils::Format.number( v[ :lines ] )
105
+ puts " ** #{formatted} in #{v[ :files ].count} #{k} files ** "
106
+
107
+ puts "\n Busy #{k} files:".yellow
108
+ files = v[ :files ].sort! { |a, b| a[ :lines ] <=> b[ :lines ] }
109
+ files.reverse!
110
+ files[ 0..12 ].each do |f|
111
+ puts " #{f[ :lines ]} - #{f[ :file ]}"
112
+ end
113
+ end
114
+
115
+ formatted = GlooLang::Utils::Format.number( total )
116
+ puts "\n #{formatted} Total Lines of Code".white
117
+ end
118
+
119
+ # ---------------------------------------------------------------------
120
+ # Private Functions
121
+ # ---------------------------------------------------------------------
122
+
123
+ #
124
+ # Setup counters for lines of code by file type.
125
+ def setup_loc( types )
126
+ @loc = {}
127
+
128
+ types.split( ' ' ).each do |t|
129
+ @loc[ t ] = { lines: 0, files: [] }
130
+ end
131
+ end
132
+
133
+ #
134
+ # Generate stat data unless we've already done so.
135
+ #
136
+ def generate
137
+ return if @folders
138
+
139
+ $log.debug 'Generating...'
140
+ @folders = []
141
+ @types = {}
142
+ @file_cnt = 0
143
+ @dir_cnt = 0
144
+
145
+ generate_for Pathname.new( @dir )
146
+ end
147
+
148
+ #
149
+ # Generate data for the given path.
150
+ # NOTE: this is a recursive function.
151
+ # It traverses all sub-direcctories.
152
+ #
153
+ def generate_for( path )
154
+ return if @skip.include?( File.basename( path ) )
155
+
156
+ cnt = 0
157
+ path.children.each do |f|
158
+ if f.directory?
159
+ @dir_cnt += 1
160
+ generate_for( f )
161
+ else
162
+ @file_cnt += 1
163
+ cnt += 1
164
+ handle_file( f )
165
+ inc_type( File.extname( f ) )
166
+ end
167
+ end
168
+ @folders << { name: path, cnt: cnt }
169
+ end
170
+
171
+ #
172
+ # Increment the file count.
173
+ #
174
+ def inc_type( type )
175
+ if @types[ type ]
176
+ @types[ type ] += 1
177
+ else
178
+ @types[ type ] = 1
179
+ end
180
+ end
181
+
182
+ #
183
+ # Consider code file types.
184
+ #
185
+ def handle_file( file )
186
+ ext = File.extname( file )
187
+ return unless ext
188
+
189
+ ext = ext[ 1..-1 ]
190
+ return unless @loc.key?( ext )
191
+
192
+ lines = count_lines( file )
193
+ @loc[ ext ][ :lines ] += lines
194
+ @loc[ ext ][ :files ] << { lines: lines, file: file }
195
+ end
196
+
197
+ #
198
+ # Count lines of code in file.
199
+ def count_lines( file )
200
+ return `wc -l #{file}`.split.first.to_i
201
+ end
202
+
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,19 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Utilities related to words (strings).
5
+ #
6
+
7
+ require 'active_support/inflector'
8
+
9
+ module GlooLang
10
+ module Utils
11
+ class Words
12
+
13
+ def self.pluralize( word )
14
+ return word.pluralize
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,79 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Show a system notification.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Alert < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'alert'.freeze
12
+ KEYWORD_SHORT = '!'.freeze
13
+
14
+ MISSING_EXPR_ERR = 'Missing Expression!'.freeze
15
+ NO_RESULT_ERR = 'Expression evaluated with no result!'.freeze
16
+
17
+ #
18
+ # Run the verb.
19
+ #
20
+ def run
21
+ unless @tokens.token_count > 1
22
+ $engine.err MISSING_EXPR_ERR
23
+ return
24
+ end
25
+
26
+ expr = GlooLang::Expr::Expression.new( @tokens.params )
27
+ result = expr.evaluate
28
+
29
+ if result
30
+ $engine.heap.it.set_to result
31
+ post_alert result
32
+ else
33
+ $engine.err NO_RESULT_ERR
34
+ end
35
+ end
36
+
37
+ #
38
+ # Get the Verb's keyword.
39
+ #
40
+ def self.keyword
41
+ return KEYWORD
42
+ end
43
+
44
+ #
45
+ # Get the Verb's keyword shortcut.
46
+ #
47
+ def self.keyword_shortcut
48
+ return KEYWORD_SHORT
49
+ end
50
+
51
+ # ---------------------------------------------------------------------
52
+ # Private functions
53
+ # ---------------------------------------------------------------------
54
+
55
+ private
56
+
57
+ #
58
+ # Post the alert for the specific platform.
59
+ # Notice is not posted if we're in quiet mode.
60
+ #
61
+ def post_alert( msg )
62
+ $log.info msg
63
+ return if $engine.args.quiet?
64
+
65
+ post_osx msg
66
+ end
67
+
68
+ #
69
+ # Post the alert on the Mac OSX.
70
+ #
71
+ def post_osx( msg )
72
+ cmd1 = '/usr/bin/osascript -e "display notification \"'
73
+ cmd2 = '\" with title \"Gloo\" "'
74
+ system( cmd1 + msg.to_s + cmd2 )
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,40 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Play a standard system beep sound.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Beep < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'beep'.freeze
12
+ KEYWORD_SHORT = 'b'.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
+ print 7.chr
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
@@ -0,0 +1,37 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Clear the screen.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Cls < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'cls'.freeze
12
+ KEYWORD_SHORT = 'cls'.freeze
13
+
14
+ #
15
+ # Run the verb.
16
+ #
17
+ def run
18
+ $engine&.clear_screen
19
+ end
20
+
21
+ #
22
+ # Get the Verb's keyword.
23
+ #
24
+ def self.keyword
25
+ return KEYWORD
26
+ end
27
+
28
+ #
29
+ # Get the Verb's keyword shortcut.
30
+ #
31
+ def self.keyword_shortcut
32
+ return KEYWORD_SHORT
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,62 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Set the current context pointer.
5
+ # Alternatively if no value is provided, just show the context.
6
+ #
7
+
8
+ module GlooLang
9
+ module Verbs
10
+ class Context < GlooLang::Core::Verb
11
+
12
+ KEYWORD = 'context'.freeze
13
+ KEYWORD_SHORT = '@'.freeze
14
+
15
+ #
16
+ # Run the verb.
17
+ #
18
+ def run
19
+ set_context if @tokens.token_count > 1
20
+ show_context
21
+ end
22
+
23
+ #
24
+ # Show the current context.
25
+ #
26
+ def show_context
27
+ $log.show "Context: #{$engine.heap.context}"
28
+ end
29
+
30
+ #
31
+ # Get the Verb's keyword.
32
+ #
33
+ def self.keyword
34
+ return KEYWORD
35
+ end
36
+
37
+ #
38
+ # Get the Verb's keyword shortcut.
39
+ #
40
+ def self.keyword_shortcut
41
+ return KEYWORD_SHORT
42
+ end
43
+
44
+ # ---------------------------------------------------------------------
45
+ # Private functions
46
+ # ---------------------------------------------------------------------
47
+
48
+ private
49
+
50
+ #
51
+ # Set the context to the given path.
52
+ #
53
+ def set_context
54
+ path = @tokens.second
55
+ $engine.heap.context.set_to path
56
+ $engine.heap.it.set_to path
57
+ $log.debug "Context set to #{$engine.heap.context}"
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,68 @@
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 Create < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'create'.freeze
12
+ KEYWORD_SHORT = '`'.freeze
13
+ AS = 'as'.freeze
14
+ VAL = ':'.freeze
15
+ NO_NAME_ERR = 'Object name is missing!'.freeze
16
+
17
+ #
18
+ # Run the verb.
19
+ #
20
+ def run
21
+ name = @tokens.second
22
+ type = @tokens.after_token( AS )
23
+ value = @tokens.after_token( VAL )
24
+
25
+ unless name
26
+ $engine.err NO_NAME_ERR
27
+ return
28
+ end
29
+ create name, type, value
30
+ end
31
+
32
+ #
33
+ # Get the Verb's keyword.
34
+ #
35
+ def self.keyword
36
+ return KEYWORD
37
+ end
38
+
39
+ #
40
+ # Get the Verb's keyword shortcut.
41
+ #
42
+ def self.keyword_shortcut
43
+ return KEYWORD_SHORT
44
+ end
45
+
46
+ # ---------------------------------------------------------------------
47
+ # Private functions
48
+ # ---------------------------------------------------------------------
49
+
50
+ private
51
+
52
+ #
53
+ # Create an object with given name of given type with
54
+ # the given initial value.
55
+ #
56
+ def create( name, type, value )
57
+ if GlooLang::Expr::LString.string?( value )
58
+ value = GlooLang::Expr::LString.strip_quotes( value )
59
+ end
60
+ obj = $engine.factory.create( { name: name, type: type, value: value } )
61
+
62
+ obj.add_default_children if obj&.add_children_on_create?
63
+ $engine.heap.it.set_to value
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,56 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Execute a shell command.
5
+ #
6
+
7
+ module GlooLang
8
+ module Verbs
9
+ class Execute < GlooLang::Core::Verb
10
+
11
+ KEYWORD = 'execute'.freeze
12
+ KEYWORD_SHORT = 'exec'.freeze
13
+ MISSING_EXPR_ERR = 'Missing Expression!'.freeze
14
+
15
+ #
16
+ # Run the verb.
17
+ #
18
+ def run
19
+ if @tokens.token_count < 2
20
+ $engine.err MISSING_EXPR_ERR
21
+ return
22
+ end
23
+
24
+ expr = GlooLang::Expr::Expression.new( @tokens.params )
25
+ cmd = expr.evaluate
26
+ $log.debug "starting cmd: #{cmd}"
27
+
28
+ pid = fork { exec( cmd ) }
29
+ Process.wait pid
30
+
31
+ # pid = spawn cmd
32
+ # Process.wait pid
33
+ $log.debug "done executing cmd: #{cmd}"
34
+
35
+ # system expr.evaluate #, chdir: Dir.pwd
36
+ # `#{expr.evaluate}`
37
+ # exec expr.evaluate
38
+ end
39
+
40
+ #
41
+ # Get the Verb's keyword.
42
+ #
43
+ def self.keyword
44
+ return KEYWORD
45
+ end
46
+
47
+ #
48
+ # Get the Verb's keyword shortcut.
49
+ #
50
+ def self.keyword_shortcut
51
+ return KEYWORD_SHORT
52
+ end
53
+
54
+ end
55
+ end
56
+ end