gloo 0.6.1 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/gloo/app/args.rb +48 -6
  4. data/lib/gloo/app/engine.rb +58 -39
  5. data/lib/gloo/app/help.rb +126 -25
  6. data/lib/gloo/app/info.rb +3 -1
  7. data/lib/gloo/app/log.rb +23 -0
  8. data/lib/gloo/app/mode.rb +2 -0
  9. data/lib/gloo/app/settings.rb +75 -68
  10. data/lib/gloo/convert/converter.rb +35 -0
  11. data/lib/gloo/convert/string_to_datetime.rb +1 -1
  12. data/lib/gloo/convert/string_to_decimal.rb +1 -1
  13. data/lib/gloo/convert/string_to_integer.rb +1 -1
  14. data/lib/gloo/core/dictionary.rb +99 -22
  15. data/lib/gloo/core/error.rb +19 -8
  16. data/lib/gloo/core/event_manager.rb +4 -0
  17. data/lib/gloo/core/factory.rb +11 -0
  18. data/lib/gloo/core/gloo_system.rb +1 -1
  19. data/lib/gloo/core/heap.rb +11 -3
  20. data/lib/gloo/core/it.rb +6 -0
  21. data/lib/gloo/core/literal.rb +5 -0
  22. data/lib/gloo/core/obj.rb +14 -0
  23. data/lib/gloo/core/op.rb +7 -0
  24. data/lib/gloo/core/parser.rb +6 -0
  25. data/lib/gloo/core/pn.rb +36 -0
  26. data/lib/gloo/core/tokens.rb +66 -22
  27. data/lib/gloo/core/verb.rb +4 -0
  28. data/lib/gloo/exec/exec_env.rb +13 -1
  29. data/lib/gloo/expr/expression.rb +26 -4
  30. data/lib/gloo/expr/l_boolean.rb +6 -0
  31. data/lib/gloo/expr/l_decimal.rb +5 -0
  32. data/lib/gloo/expr/l_integer.rb +7 -0
  33. data/lib/gloo/expr/l_string.rb +7 -0
  34. data/lib/gloo/expr/op_div.rb +2 -0
  35. data/lib/gloo/expr/op_minus.rb +2 -0
  36. data/lib/gloo/expr/op_mult.rb +2 -0
  37. data/lib/gloo/expr/op_plus.rb +2 -0
  38. data/lib/gloo/help/app/application.txt +22 -0
  39. data/lib/gloo/help/app/configuration.txt +7 -0
  40. data/lib/gloo/help/app/default_help.txt +14 -0
  41. data/lib/gloo/help/app/logging.txt +16 -0
  42. data/lib/gloo/help/core/color.txt +31 -0
  43. data/lib/gloo/help/core/error.txt +33 -0
  44. data/lib/gloo/help/core/events.txt +21 -0
  45. data/lib/gloo/help/core/gloo_system.txt +54 -0
  46. data/lib/gloo/help/core/here.txt +30 -0
  47. data/lib/gloo/help/core/it.txt +23 -0
  48. data/lib/gloo/help/core/ops.txt +16 -0
  49. data/lib/gloo/help/core/pathname.txt +29 -0
  50. data/lib/gloo/help/objs/basic/alias.txt +36 -0
  51. data/lib/gloo/help/objs/basic/boolean.txt +28 -0
  52. data/lib/gloo/help/objs/basic/container.txt +33 -0
  53. data/lib/gloo/help/objs/basic/decimal.txt +28 -0
  54. data/lib/gloo/help/objs/basic/integer.txt +27 -0
  55. data/lib/gloo/help/objs/basic/script.txt +29 -0
  56. data/lib/gloo/help/objs/basic/string.txt +28 -0
  57. data/lib/gloo/help/objs/basic/text.txt +27 -0
  58. data/lib/gloo/help/objs/basic/untyped.txt +22 -0
  59. data/lib/gloo/help/objs/cli/banner.txt +49 -0
  60. data/lib/gloo/help/objs/cli/bar.txt +34 -0
  61. data/lib/gloo/help/objs/cli/colorize.txt +33 -0
  62. data/lib/gloo/help/objs/cli/confirm.txt +26 -0
  63. data/lib/gloo/help/objs/cli/menu.txt +44 -0
  64. data/lib/gloo/help/objs/cli/menu_item.txt +26 -0
  65. data/lib/gloo/help/objs/cli/pastel.txt +43 -0
  66. data/lib/gloo/help/objs/cli/prompt.txt +27 -0
  67. data/lib/gloo/help/objs/cli/select.txt +34 -0
  68. data/lib/gloo/help/objs/ctrl/each.txt +48 -0
  69. data/lib/gloo/help/objs/ctrl/repeat.txt +38 -0
  70. data/lib/gloo/help/objs/data/markdown.txt +25 -0
  71. data/lib/gloo/help/objs/data/table.txt +46 -0
  72. data/lib/gloo/help/objs/dev/git_repo.txt +35 -0
  73. data/lib/gloo/help/objs/dt/date.txt +23 -0
  74. data/lib/gloo/help/objs/dt/datetime.txt +24 -0
  75. data/lib/gloo/help/objs/dt/time.txt +23 -0
  76. data/lib/gloo/help/objs/ror/erb.txt +37 -0
  77. data/lib/gloo/help/objs/ror/eval.txt +24 -0
  78. data/lib/gloo/help/objs/snd/play.txt +23 -0
  79. data/lib/gloo/help/objs/snd/say.txt +28 -0
  80. data/lib/gloo/help/objs/system/file.txt +48 -0
  81. data/lib/gloo/help/objs/system/system.txt +32 -0
  82. data/lib/gloo/help/objs/web/http_get.txt +35 -0
  83. data/lib/gloo/help/objs/web/http_post.txt +32 -0
  84. data/lib/gloo/help/objs/web/json.txt +34 -0
  85. data/lib/gloo/help/objs/web/slack.txt +33 -0
  86. data/lib/gloo/help/objs/web/teams.txt +30 -0
  87. data/lib/gloo/help/objs/web/uri.txt +37 -0
  88. data/lib/gloo/help/verbs/alert.txt +33 -0
  89. data/lib/gloo/help/verbs/beep.txt +25 -0
  90. data/lib/gloo/help/verbs/cls.txt +24 -0
  91. data/lib/gloo/help/verbs/context.txt +43 -0
  92. data/lib/gloo/help/verbs/create.txt +33 -0
  93. data/lib/gloo/help/verbs/execute.txt +27 -0
  94. data/lib/gloo/help/verbs/help.txt +34 -0
  95. data/lib/gloo/help/verbs/if.txt +37 -0
  96. data/lib/gloo/help/verbs/list.txt +34 -0
  97. data/lib/gloo/help/verbs/load.txt +38 -0
  98. data/lib/gloo/help/verbs/move.txt +42 -0
  99. data/lib/gloo/help/verbs/put.txt +38 -0
  100. data/lib/gloo/help/verbs/quit.txt +25 -0
  101. data/lib/gloo/help/verbs/run.txt +41 -0
  102. data/lib/gloo/help/verbs/save.txt +26 -0
  103. data/lib/gloo/help/verbs/show.txt +30 -0
  104. data/lib/gloo/help/verbs/tell.txt +34 -0
  105. data/lib/gloo/help/verbs/unless.txt +38 -0
  106. data/lib/gloo/help/verbs/version.txt +32 -0
  107. data/lib/gloo/help/verbs/wait.txt +29 -0
  108. data/lib/gloo/objs/basic/alias.rb +0 -33
  109. data/lib/gloo/objs/basic/boolean.rb +6 -27
  110. data/lib/gloo/objs/basic/container.rb +0 -33
  111. data/lib/gloo/objs/basic/decimal.rb +8 -28
  112. data/lib/gloo/objs/basic/integer.rb +5 -26
  113. data/lib/gloo/objs/basic/script.rb +0 -26
  114. data/lib/gloo/objs/basic/string.rb +6 -26
  115. data/lib/gloo/objs/basic/text.rb +0 -25
  116. data/lib/gloo/objs/basic/untyped.rb +0 -26
  117. data/lib/gloo/objs/cli/banner.rb +0 -29
  118. data/lib/gloo/objs/cli/bar.rb +0 -29
  119. data/lib/gloo/objs/cli/colorize.rb +4 -34
  120. data/lib/gloo/objs/cli/confirm.rb +6 -36
  121. data/lib/gloo/objs/cli/menu.rb +4 -34
  122. data/lib/gloo/objs/cli/menu_item.rb +0 -33
  123. data/lib/gloo/objs/cli/pastel.rb +4 -27
  124. data/lib/gloo/objs/cli/prompt.rb +4 -28
  125. data/lib/gloo/objs/cli/select.rb +4 -31
  126. data/lib/gloo/objs/ctrl/each.rb +33 -33
  127. data/lib/gloo/objs/ctrl/repeat.rb +8 -29
  128. data/lib/gloo/objs/data/markdown.rb +0 -25
  129. data/lib/gloo/objs/data/table.rb +4 -32
  130. data/lib/gloo/objs/dev/git.rb +12 -30
  131. data/lib/gloo/objs/dt/date.rb +3 -25
  132. data/lib/gloo/objs/dt/datetime.rb +4 -26
  133. data/lib/gloo/objs/dt/time.rb +3 -25
  134. data/lib/gloo/objs/ror/erb.rb +11 -45
  135. data/lib/gloo/objs/ror/eval.rb +11 -38
  136. data/lib/gloo/objs/snd/play.rb +2 -25
  137. data/lib/gloo/objs/snd/say.rb +9 -31
  138. data/lib/gloo/objs/system/file_handle.rb +7 -36
  139. data/lib/gloo/objs/system/system.rb +16 -46
  140. data/lib/gloo/objs/web/http_get.rb +57 -83
  141. data/lib/gloo/objs/web/http_post.rb +8 -31
  142. data/lib/gloo/objs/web/json.rb +11 -31
  143. data/lib/gloo/objs/web/slack.rb +7 -34
  144. data/lib/gloo/objs/web/teams.rb +13 -48
  145. data/lib/gloo/objs/web/uri.rb +0 -29
  146. data/lib/gloo/persist/file_loader.rb +8 -0
  147. data/lib/gloo/persist/file_saver.rb +6 -0
  148. data/lib/gloo/persist/file_storage.rb +2 -0
  149. data/lib/gloo/persist/line_splitter.rb +2 -0
  150. data/lib/gloo/persist/persist_man.rb +6 -0
  151. data/lib/gloo/verbs/alert.rb +30 -44
  152. data/lib/gloo/verbs/beep.rb +0 -30
  153. data/lib/gloo/verbs/cls.rb +0 -30
  154. data/lib/gloo/verbs/context.rb +9 -39
  155. data/lib/gloo/verbs/create.rb +17 -32
  156. data/lib/gloo/verbs/execute.rb +56 -0
  157. data/lib/gloo/verbs/help.rb +151 -115
  158. data/lib/gloo/verbs/if.rb +46 -44
  159. data/lib/gloo/verbs/list.rb +36 -54
  160. data/lib/gloo/verbs/load.rb +8 -37
  161. data/lib/gloo/verbs/move.rb +12 -51
  162. data/lib/gloo/verbs/put.rb +28 -52
  163. data/lib/gloo/verbs/quit.rb +0 -31
  164. data/lib/gloo/verbs/run.rb +23 -39
  165. data/lib/gloo/verbs/save.rb +0 -33
  166. data/lib/gloo/verbs/show.rb +6 -31
  167. data/lib/gloo/verbs/tell.rb +31 -31
  168. data/lib/gloo/verbs/unless.rb +47 -46
  169. data/lib/gloo/verbs/version.rb +0 -30
  170. data/lib/gloo/verbs/wait.rb +0 -31
  171. metadata +74 -3
  172. data/lib/gloo/help/help.md +0 -16
@@ -8,10 +8,12 @@ module Gloo
8
8
  module App
9
9
  class Info
10
10
 
11
- VERSION = '0.6.1'.freeze
11
+ VERSION = '0.7.4'.freeze
12
12
  APP_NAME = 'Gloo'.freeze
13
13
 
14
+ #
14
15
  # Get the application display title.
16
+ #
15
17
  def self.display_title
16
18
  return "#{APP_NAME}, version #{VERSION}"
17
19
  end
@@ -13,6 +13,11 @@ module Gloo
13
13
 
14
14
  attr_reader :logger, :quiet
15
15
 
16
+ #
17
+ # Set up a logger.
18
+ # If quiet is true, then message are written to the log
19
+ # but not to the console.
20
+ #
16
21
  def initialize( quiet )
17
22
  f = File.join( $settings.log_path, 'gloo.log' )
18
23
  @logger = Logger.new( f )
@@ -20,25 +25,43 @@ module Gloo
20
25
  @quiet = quiet
21
26
  end
22
27
 
28
+ #
23
29
  # Show a message unless we're in quite mode.
30
+ #
24
31
  def show( msg )
25
32
  puts msg unless @quiet
26
33
  end
27
34
 
35
+ #
36
+ # Write a debug message to the log.
37
+ #
28
38
  def debug( msg )
29
39
  @logger.debug msg
30
40
  end
31
41
 
42
+ #
43
+ # Write an information message to the log.
44
+ # Also write to the console unless quiet.
45
+ #
32
46
  def info( msg )
33
47
  @logger.info msg
34
48
  puts msg.blue unless @quiet
35
49
  end
36
50
 
51
+ #
52
+ # Write a warning message to the log.
53
+ # Also write to the console unless quiet.
54
+ #
37
55
  def warn( msg )
38
56
  @logger.warn msg
39
57
  puts msg.yellow unless @quiet
40
58
  end
41
59
 
60
+ #
61
+ # Write an error message to the log and set the error
62
+ # in the engine's data heap.
63
+ # Also write to the console unless quiet.
64
+ #
42
65
  def error( msg, ex = nil, engine = nil )
43
66
  engine&.heap&.error&.set_to msg
44
67
  @logger.error msg
@@ -15,7 +15,9 @@ module Gloo
15
15
  HELP = :help # Show the help screen
16
16
  TEST = :test # Running in Unit Test mode.
17
17
 
18
+ #
18
19
  # Get the default mode.
20
+ #
19
21
  def self.default_mode
20
22
  return EMBED
21
23
  end
@@ -18,6 +18,7 @@ module Gloo
18
18
 
19
19
  #
20
20
  # Load setting from the yml file.
21
+ # The mode parameter is used to determine if we are running in TEST.
21
22
  #
22
23
  def initialize( mode )
23
24
  @mode = mode
@@ -26,20 +27,6 @@ module Gloo
26
27
  init_user_settings
27
28
  end
28
29
 
29
- #
30
- # Initialize gloo's root path.
31
- #
32
- def init_root
33
- if in_test_mode?
34
- path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
35
- path = File.dirname( File.dirname( path ) )
36
- path = File.join( path, 'test', 'gloo' )
37
- @user_root = path
38
- else
39
- @user_root = File.join( Dir.home, 'gloo' )
40
- end
41
- end
42
-
43
30
  #
44
31
  # Are we in test mode?
45
32
  #
@@ -56,6 +43,80 @@ module Gloo
56
43
  return settings[ 'gloo' ][ 'project_path' ]
57
44
  end
58
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 + Gloo::App::Settings.lines.to_s.white
55
+ puts ' Page Size: '.yellow + Gloo::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
+
59
120
  #
60
121
  # Get the app's required directories.
61
122
  #
@@ -120,60 +181,6 @@ module Gloo
120
181
  return str
121
182
  end
122
183
 
123
- #
124
- # Show the current application settings.
125
- # Can be seen in app with 'help settings'
126
- #
127
- def show
128
- puts "\nApplication Settings:".blue
129
- puts ' Startup with: '.yellow + @start_with.white
130
- puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
131
- puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
132
- puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
133
- puts ''
134
- self.show_paths
135
- puts ''
136
- end
137
-
138
- #
139
- # Show path settings
140
- #
141
- def show_paths
142
- puts ' User Root Path is here: '.yellow + @user_root.white
143
- puts ' Projects Path: '.yellow + @project_path.white
144
- puts ' Tmp Path: '.yellow + @tmp_path.white
145
- puts ' Debug Path: '.yellow + @debug_path.white
146
- end
147
-
148
- #
149
- # Get the number of vertical lines on screen.
150
- #
151
- def self.lines
152
- TTY::Screen.rows
153
- end
154
-
155
- #
156
- # Get the number of horizontal columns on screen.
157
- #
158
- def self.cols
159
- TTY::Screen.cols
160
- end
161
-
162
- #
163
- # Get the default page size.
164
- # This is the number of lines of text we can show.
165
- #
166
- def self.page_size
167
- Settings.lines - 3
168
- end
169
-
170
- #
171
- # How many lines should we use for a preview?
172
- #
173
- def self.preview_lines
174
- return 7
175
- end
176
-
177
184
  end
178
185
  end
179
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 Gloo
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 = "Gloo::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
@@ -1,5 +1,5 @@
1
1
  # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 202 Eric Crane. All rights reserved.
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
3
  #
4
4
  # Conversion tool: String to Date Time.
5
5
  #
@@ -1,5 +1,5 @@
1
1
  # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 202 Eric Crane. All rights reserved.
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
3
  #
4
4
  # Conversion tool: String to Decimal.
5
5
  #
@@ -1,5 +1,5 @@
1
1
  # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 202 Eric Crane. All rights reserved.
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
3
  #
4
4
  # Conversion tool: String to Integer.
5
5
  #
@@ -11,51 +11,54 @@ module Gloo
11
11
 
12
12
  include Singleton
13
13
 
14
- attr_reader :verbs, :objs
14
+ attr_reader :verbs, :objs, :keywords
15
15
 
16
+ #
16
17
  # Set up the object dictionary.
18
+ #
17
19
  def initialize
18
20
  @verbs = {}
19
21
  @objs = {}
20
22
  @verb_references = []
21
23
  @obj_references = []
24
+ @keywords = []
22
25
  end
23
26
 
27
+ #
24
28
  # Register a verb.
29
+ #
25
30
  def register_verb( subclass )
26
31
  @verb_references << subclass
27
32
  end
28
33
 
34
+ #
29
35
  # Register an object type.
36
+ #
30
37
  def register_obj( subclass )
31
38
  @obj_references << subclass
32
39
  end
33
40
 
41
+ #
34
42
  # Initialize verbs and objects in the dictionary.
43
+ #
35
44
  def init
36
45
  $log.debug 'initializing dictionaries'
37
46
  init_verbs
38
47
  init_objs
39
48
  end
40
49
 
41
- # Init the list of verbs.
42
- def init_objs
43
- $log.debug "initializing #{@obj_references.count} objects"
44
- @obj_references.each do |o|
45
- $log.debug o
46
- @objs[ o.typename ] = o
47
- @objs[ o.short_typename ] = o
48
- end
49
- end
50
-
50
+ #
51
51
  # Is the given word an object type?
52
+ #
52
53
  def obj?( word )
53
54
  return false unless word
54
55
 
55
56
  return @objs.key?( word.downcase )
56
57
  end
57
58
 
59
+ #
58
60
  # Find the object type by name.
61
+ #
59
62
  def find_obj( word )
60
63
  return nil unless word
61
64
  return nil unless obj?( word )
@@ -63,25 +66,18 @@ module Gloo
63
66
  return @objs[ word.downcase ]
64
67
  end
65
68
 
66
- # Init the list of verbs.
67
- def init_verbs
68
- $log.debug "initializing #{@verb_references.count} verbs"
69
- @verb_references.each do |v|
70
- $log.debug v
71
- @verbs[ v.keyword ] = v
72
- @verbs[ v.keyword_shortcut ] = v
73
- # v.send( :new ).run
74
- end
75
- end
76
-
69
+ #
77
70
  # Is the given word a verb?
71
+ #
78
72
  def verb?( word )
79
73
  return false unless word
80
74
 
81
75
  return @verbs.key?( word.downcase )
82
76
  end
83
77
 
78
+ #
84
79
  # Find the verb by name.
80
+ #
85
81
  def find_verb( verb )
86
82
  return nil unless verb
87
83
  return nil unless verb?( verb )
@@ -89,16 +85,97 @@ module Gloo
89
85
  return @verbs[ verb.downcase ]
90
86
  end
91
87
 
88
+ #
92
89
  # Get the list of verbs, sorted.
90
+ #
93
91
  def get_obj_types
94
92
  return @obj_references.sort { |a, b| a.typename <=> b.typename }
95
93
  end
96
94
 
95
+ #
97
96
  # Get the list of verbs, sorted.
97
+ #
98
98
  def get_verbs
99
99
  return @verb_references.sort { |a, b| a.keyword <=> b.keyword }
100
100
  end
101
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
+
102
179
  end
103
180
  end
104
181
  end