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.
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 +1 -5
  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 +190 -2
@@ -0,0 +1,186 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Application and user settings.
5
+ #
6
+
7
+ require 'yaml'
8
+ require 'tty-screen'
9
+ require 'colorize'
10
+
11
+ module GlooLang
12
+ module App
13
+ class Settings
14
+
15
+ attr_reader :user_root, :log_path, :config_path, :project_path,
16
+ :start_with, :list_indent, :tmp_path,
17
+ :debug_path, :debug
18
+
19
+ #
20
+ # Load setting from the yml file.
21
+ # The mode parameter is used to determine if we are running in TEST.
22
+ #
23
+ def initialize( mode )
24
+ @mode = mode
25
+ init_root
26
+ init_path_settings
27
+ init_user_settings
28
+ end
29
+
30
+ #
31
+ # Are we in test mode?
32
+ #
33
+ def in_test_mode?
34
+ return @mode == 'TEST'
35
+ end
36
+
37
+ #
38
+ # Get the project path for the current mode.
39
+ #
40
+ def project_path_for_mode( settings )
41
+ return File.join( @user_root, 'projects' ) if in_test_mode?
42
+
43
+ return settings[ 'gloo' ][ 'project_path' ]
44
+ end
45
+
46
+ #
47
+ # Show the current application settings.
48
+ # Can be seen in app with 'help settings'
49
+ #
50
+ def show
51
+ puts "\nApplication Settings:".blue
52
+ puts ' Startup with: '.yellow + @start_with.white
53
+ puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
54
+ puts ' Screen Lines: '.yellow + GlooLang::App::Settings.lines.to_s.white
55
+ puts ' Page Size: '.yellow + GlooLang::App::Settings.page_size.to_s.white
56
+ puts ''
57
+ self.show_paths
58
+ puts ''
59
+ end
60
+
61
+ #
62
+ # Show path settings
63
+ #
64
+ def show_paths
65
+ puts ' User Root Path is here: '.yellow + @user_root.white
66
+ puts ' Projects Path: '.yellow + @project_path.white
67
+ puts ' Tmp Path: '.yellow + @tmp_path.white
68
+ puts ' Debug Path: '.yellow + @debug_path.white
69
+ end
70
+
71
+ #
72
+ # Get the number of vertical lines on screen.
73
+ #
74
+ def self.lines
75
+ TTY::Screen.rows
76
+ end
77
+
78
+ #
79
+ # Get the number of horizontal columns on screen.
80
+ #
81
+ def self.cols
82
+ TTY::Screen.cols
83
+ end
84
+
85
+ #
86
+ # Get the default page size.
87
+ # This is the number of lines of text we can show.
88
+ #
89
+ def self.page_size
90
+ Settings.lines - 3
91
+ end
92
+
93
+ #
94
+ # How many lines should we use for a preview?
95
+ #
96
+ def self.preview_lines
97
+ return 7
98
+ end
99
+
100
+ # ---------------------------------------------------------------------
101
+ # Private
102
+ # ---------------------------------------------------------------------
103
+
104
+ private
105
+
106
+ #
107
+ # Initialize gloo's root path.
108
+ #
109
+ def init_root
110
+ if in_test_mode?
111
+ path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
112
+ path = File.dirname( File.dirname( path ) )
113
+ path = File.join( path, 'test', 'gloo' )
114
+ @user_root = path
115
+ else
116
+ @user_root = File.join( Dir.home, 'gloo' )
117
+ end
118
+ end
119
+
120
+ #
121
+ # Get the app's required directories.
122
+ #
123
+ def init_path_settings
124
+ Dir.mkdir( @user_root ) unless File.exist?( @user_root )
125
+
126
+ @log_path = File.join( @user_root, 'logs' )
127
+ Dir.mkdir( @log_path ) unless File.exist?( @log_path )
128
+
129
+ @config_path = File.join( @user_root, 'config' )
130
+ Dir.mkdir( @config_path ) unless File.exist?( @config_path )
131
+
132
+ @tmp_path = File.join( @user_root, 'tmp' )
133
+ Dir.mkdir( @tmp_path ) unless File.exist?( @tmp_path )
134
+
135
+ @debug_path = File.join( @user_root, 'debug' )
136
+ Dir.mkdir( @debug_path ) unless File.exist?( @debug_path )
137
+ end
138
+
139
+ #
140
+ # Initialize the user settings for the currently
141
+ # running environment.
142
+ #
143
+ def init_user_settings
144
+ settings = get_settings
145
+
146
+ @project_path = project_path_for_mode settings
147
+ @start_with = settings[ 'gloo' ][ 'start_with' ]
148
+ @list_indent = settings[ 'gloo' ][ 'list_indent' ]
149
+
150
+ @debug = settings[ 'gloo' ][ 'debug' ]
151
+ end
152
+
153
+ #
154
+ # Get the app's required directories.
155
+ #
156
+ def get_settings
157
+ f = File.join( @config_path, 'gloo.yml' )
158
+ create_settings( f ) unless File.exist?( f )
159
+ return YAML.load_file f
160
+ end
161
+
162
+ #
163
+ # Create settings file.
164
+ #
165
+ def create_settings( file )
166
+ IO.write( file, get_default_settings )
167
+ end
168
+
169
+ #
170
+ # Get the value for default settings.
171
+ #
172
+ def get_default_settings
173
+ projects = File.join( @user_root, 'projects' )
174
+ str = <<~TEXT
175
+ gloo:
176
+ project_path: #{projects}
177
+ start_with:
178
+ list_indent: 1
179
+ debug: false
180
+ TEXT
181
+ return str
182
+ end
183
+
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,35 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Data conversion manager.
5
+ #
6
+
7
+ module GlooLang
8
+ module Convert
9
+ class Converter
10
+
11
+ # ---------------------------------------------------------------------
12
+ # Convert
13
+ # ---------------------------------------------------------------------
14
+
15
+ #
16
+ # Convert the given value to the specified type,
17
+ # or if no conversion is available, revert to default.
18
+ #
19
+ def convert( value, to_type, default = nil )
20
+ begin
21
+ name = "GlooLang::Convert::#{value.class}To#{to_type}"
22
+ clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c }
23
+ o = clazz.new
24
+ return o.convert( value )
25
+ rescue => e
26
+ $log.error e.message
27
+ $engine.heap.error.set_to e.message
28
+ end
29
+
30
+ return default
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Date Time.
5
+ #
6
+ require 'chronic'
7
+
8
+ module GlooLang
9
+ module Convert
10
+ class StringToDateTime
11
+
12
+ #
13
+ # Convert the given string value to a date and time.
14
+ #
15
+ def convert( value )
16
+ return Chronic.parse( value )
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Decimal.
5
+ #
6
+
7
+ module GlooLang
8
+ module Convert
9
+ class StringToDecimal
10
+
11
+ #
12
+ # Convert the given string value to an integer.
13
+ #
14
+ def convert( value )
15
+ return value.to_f
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Integer.
5
+ #
6
+
7
+ module GlooLang
8
+ module Convert
9
+ class StringToInteger
10
+
11
+ #
12
+ # Convert the given string value to an integer.
13
+ #
14
+ def convert( value )
15
+ return value.to_i
16
+ end
17
+
18
+ end
19
+ end
20
+ 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
+ # An abstract base object.
5
+ # All objects and verbs derive from this.
6
+ #
7
+
8
+ module GlooLang
9
+ module Core
10
+ class Baseo
11
+
12
+ attr_accessor :name
13
+
14
+ NOT_IMPLEMENTED_ERR = 'Not implemented yet!'.freeze
15
+
16
+ # Set up the object.
17
+ def initialize
18
+ @name = ''
19
+ end
20
+
21
+ #
22
+ # The object type, suitable for display.
23
+ #
24
+ def type_display
25
+ raise 'this method should be overriden'
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,181 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # A dictionary of Objects and Verbs.
5
+ #
6
+ require 'singleton'
7
+
8
+ module GlooLang
9
+ module Core
10
+ class Dictionary
11
+
12
+ include Singleton
13
+
14
+ attr_reader :verbs, :objs, :keywords
15
+
16
+ #
17
+ # Set up the object dictionary.
18
+ #
19
+ def initialize
20
+ @verbs = {}
21
+ @objs = {}
22
+ @verb_references = []
23
+ @obj_references = []
24
+ @keywords = []
25
+ end
26
+
27
+ #
28
+ # Register a verb.
29
+ #
30
+ def register_verb( subclass )
31
+ @verb_references << subclass
32
+ end
33
+
34
+ #
35
+ # Register an object type.
36
+ #
37
+ def register_obj( subclass )
38
+ @obj_references << subclass
39
+ end
40
+
41
+ #
42
+ # Initialize verbs and objects in the dictionary.
43
+ #
44
+ def init
45
+ $log.debug 'initializing dictionaries'
46
+ init_verbs
47
+ init_objs
48
+ end
49
+
50
+ #
51
+ # Is the given word an object type?
52
+ #
53
+ def obj?( word )
54
+ return false unless word
55
+
56
+ return @objs.key?( word.downcase )
57
+ end
58
+
59
+ #
60
+ # Find the object type by name.
61
+ #
62
+ def find_obj( word )
63
+ return nil unless word
64
+ return nil unless obj?( word )
65
+
66
+ return @objs[ word.downcase ]
67
+ end
68
+
69
+ #
70
+ # Is the given word a verb?
71
+ #
72
+ def verb?( word )
73
+ return false unless word
74
+
75
+ return @verbs.key?( word.downcase )
76
+ end
77
+
78
+ #
79
+ # Find the verb by name.
80
+ #
81
+ def find_verb( verb )
82
+ return nil unless verb
83
+ return nil unless verb?( verb )
84
+
85
+ return @verbs[ verb.downcase ]
86
+ end
87
+
88
+ #
89
+ # Get the list of verbs, sorted.
90
+ #
91
+ def get_obj_types
92
+ return @obj_references.sort { |a, b| a.typename <=> b.typename }
93
+ end
94
+
95
+ #
96
+ # Get the list of verbs, sorted.
97
+ #
98
+ def get_verbs
99
+ return @verb_references.sort { |a, b| a.keyword <=> b.keyword }
100
+ end
101
+
102
+ #
103
+ # Lookup the keyword by name or shortcut.
104
+ # Return the keyword (name) or nil if it is not found.
105
+ #
106
+ def lookup_keyword( key )
107
+ v = find_verb key
108
+ return v.keyword if v
109
+
110
+ o = find_obj key
111
+ return o.typename if o
112
+
113
+ return nil
114
+ end
115
+
116
+ #
117
+ # Show a list of all keywords.
118
+ # This includes verbs and objects, names and shortcuts.
119
+ #
120
+ def show_keywords
121
+ str = ''
122
+ @keywords.sort.each_with_index do |k, i|
123
+ str << k.ljust( 20, ' ' )
124
+ if ( ( i + 1 ) % 6 ).zero?
125
+ puts str
126
+ str = ''
127
+ end
128
+ end
129
+ end
130
+
131
+ # ---------------------------------------------------------------------
132
+ # Private
133
+ # ---------------------------------------------------------------------
134
+
135
+ private
136
+
137
+ #
138
+ # Add a keyword to the keyword list.
139
+ # Report an error if the keyword is already in the list.
140
+ #
141
+ def add_key( keyword )
142
+ if @keywords.include?( keyword )
143
+ $log.error "duplicate keyword '#{keyword}'"
144
+ return
145
+ end
146
+
147
+ @keywords << keyword
148
+ end
149
+
150
+ #
151
+ # Init the list of objects.
152
+ #
153
+ def init_objs
154
+ $log.debug "initializing #{@obj_references.count} objects"
155
+ @obj_references.each do |o|
156
+ $log.debug o
157
+ @objs[ o.typename ] = o
158
+ @objs[ o.short_typename ] = o
159
+ add_key o.typename
160
+ add_key o.short_typename if o.typename != o.short_typename
161
+ end
162
+ end
163
+
164
+ #
165
+ # Init the list of verbs.
166
+ #
167
+ def init_verbs
168
+ $log.debug "initializing #{@verb_references.count} verbs"
169
+ @verb_references.each do |v|
170
+ $log.debug v
171
+ @verbs[ v.keyword ] = v
172
+ @verbs[ v.keyword_shortcut ] = v
173
+ # v.send( :new ).run
174
+ add_key v.keyword
175
+ add_key v.keyword_shortcut if v.keyword != v.keyword_shortcut
176
+ end
177
+ end
178
+
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,61 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # If the last command to run generated an error it will be here.
5
+ #
6
+
7
+ module GlooLang
8
+ module Core
9
+ class Error
10
+
11
+ attr_accessor :value, :error_count
12
+
13
+ #
14
+ # Set up the error object.
15
+ #
16
+ def initialize
17
+ clear
18
+ end
19
+
20
+ #
21
+ # Clear out the error message.
22
+ #
23
+ def clear
24
+ @error_count = 0
25
+ @value = nil
26
+ end
27
+
28
+ #
29
+ # Set the value of error.
30
+ #
31
+ def set_to( new_value )
32
+ @error_count += 1
33
+ @value = new_value
34
+ end
35
+
36
+ #
37
+ # Start counting errors.
38
+ # We're looking to see if we get any new ones during
39
+ # a script or an immediate command.
40
+ #
41
+ def start_tracking
42
+ @error_count = 0
43
+ end
44
+
45
+ #
46
+ # Clear out error if we didn't add any new ones.
47
+ #
48
+ def clear_if_no_errors
49
+ self.clear if @error_count.zero?
50
+ end
51
+
52
+ #
53
+ # Get the string representation of the error.
54
+ #
55
+ def to_s
56
+ return @value.to_s
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,44 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The Event Manager.
5
+ # Run scripts in response to pre-defined events.
6
+ #
7
+
8
+ module GlooLang
9
+ module Core
10
+ class EventManager
11
+
12
+ #
13
+ # Set up the event manager.
14
+ #
15
+ def initialize
16
+ $log.debug 'event manager intialized...'
17
+ end
18
+
19
+ #
20
+ # Run on_load scripts in the recently loaded object
21
+ # If no obj is given the script will be run in root.
22
+ #
23
+ def on_load( obj = nil, in_heap = false )
24
+ return unless obj || in_heap
25
+
26
+ $log.debug 'on_load event'
27
+ arr = GlooLang::Core::ObjFinder.by_name 'on_load', obj
28
+ arr.each { |o| GlooLang::Exec::Dispatch.message 'run', o }
29
+ end
30
+
31
+ #
32
+ # Run on_unload scripts in the object that will be unloaded.
33
+ #
34
+ def on_unload( obj )
35
+ return unless obj
36
+
37
+ $log.debug 'on_unload event'
38
+ arr = GlooLang::Core::ObjFinder.by_name 'on_unload', obj
39
+ arr.each { |o| GlooLang::Exec::Dispatch.message 'run', o }
40
+ end
41
+
42
+ end
43
+ end
44
+ end