gloo 7.2 → 7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/docs/application.md +19 -3
  3. data/docs/iterators.md +66 -1
  4. data/docs/language_objects.md +14 -7
  5. data/docs/language_scripting.md +17 -0
  6. data/docs/language_syntax.md +86 -3
  7. data/docs/objects.md +6 -6
  8. data/docs/operators.md +36 -2
  9. data/docs/plugins.md +26 -0
  10. data/docs/testing.md +31 -2
  11. data/docs/verbs.md +8 -0
  12. data/lib/VERSION +1 -1
  13. data/lib/VERSION_NOTES +15 -0
  14. data/lib/gloo/app/engine.rb +133 -17
  15. data/lib/gloo/app/prompt.rb +8 -0
  16. data/lib/gloo/convert/string_to_decimal.rb +3 -6
  17. data/lib/gloo/convert/string_to_integer.rb +3 -2
  18. data/lib/gloo/core/dictionary.rb +23 -12
  19. data/lib/gloo/core/obj.rb +77 -0
  20. data/lib/gloo/core/op.rb +99 -0
  21. data/lib/gloo/core/parser.rb +15 -0
  22. data/lib/gloo/core/tokens.rb +18 -0
  23. data/lib/gloo/core/verb.rb +130 -1
  24. data/lib/gloo/exec/dispatch.rb +7 -3
  25. data/lib/gloo/exec/runaway_recursion.rb +34 -0
  26. data/lib/gloo/exec/runner.rb +46 -0
  27. data/lib/gloo/exec/script.rb +16 -2
  28. data/lib/gloo/expr/expression.rb +77 -6
  29. data/lib/gloo/expr/l_decimal.rb +18 -2
  30. data/lib/gloo/expr/l_integer.rb +5 -2
  31. data/lib/gloo/expr/op_div.rb +4 -0
  32. data/lib/gloo/expr/op_eq.rb +4 -0
  33. data/lib/gloo/expr/op_gt.rb +4 -0
  34. data/lib/gloo/expr/op_gteq.rb +4 -0
  35. data/lib/gloo/expr/op_ineq.rb +4 -0
  36. data/lib/gloo/expr/op_lt.rb +4 -0
  37. data/lib/gloo/expr/op_lteq.rb +4 -0
  38. data/lib/gloo/expr/op_minus.rb +4 -0
  39. data/lib/gloo/expr/op_mult.rb +3 -7
  40. data/lib/gloo/expr/op_plus.rb +8 -1
  41. data/lib/gloo/objs/basic/alias.rb +6 -1
  42. data/lib/gloo/objs/basic/boolean.rb +15 -6
  43. data/lib/gloo/objs/basic/decimal.rb +25 -3
  44. data/lib/gloo/objs/basic/script.rb +3 -1
  45. data/lib/gloo/objs/basic/string_msgs.rb +50 -68
  46. data/lib/gloo/objs/ctrl/until.rb +219 -0
  47. data/lib/gloo/plugin/callback.rb +54 -10
  48. data/lib/gloo/plugin/ext_manager.rb +44 -0
  49. data/lib/gloo/plugin/lib_manager.rb +65 -1
  50. data/lib/gloo/shell/runner.rb +36 -9
  51. data/lib/gloo/verbs/break.rb +6 -4
  52. data/lib/gloo/verbs/check.rb +8 -2
  53. data/lib/gloo/verbs/create.rb +13 -4
  54. data/lib/gloo/verbs/if.rb +33 -10
  55. data/lib/gloo/verbs/invoke.rb +6 -1
  56. data/lib/gloo/verbs/list.rb +9 -2
  57. data/lib/gloo/verbs/load.rb +4 -1
  58. data/lib/gloo/verbs/move.rb +8 -2
  59. data/lib/gloo/verbs/put.rb +9 -2
  60. data/lib/gloo/verbs/reload.rb +2 -1
  61. data/lib/gloo/verbs/run.rb +8 -1
  62. data/lib/gloo/verbs/save.rb +4 -0
  63. data/lib/gloo/verbs/tell.rb +9 -2
  64. data/lib/gloo/verbs/unless.rb +34 -10
  65. data/lib/gloo/verbs/unload.rb +81 -16
  66. data/test.gloo/ctrl/until.test.gloo +100 -0
  67. data/test.gloo/lang/computed_paths.test.gloo +98 -0
  68. data/test.gloo/lang/literal.test.gloo +43 -0
  69. data/test.gloo/lang/ops.test.gloo +193 -0
  70. data/test.gloo/lang/runaway_recursion.test.gloo +44 -0
  71. data/test.gloo/objs/decimal.test.gloo +23 -0
  72. data/test.gloo/objs/string.test.gloo +30 -0
  73. data/test.gloo/verbs/create.test.gloo +6 -21
  74. data/test.gloo/verbs/if.test.gloo +41 -0
  75. data/test.gloo/verbs/load.test.gloo +4 -3
  76. data/test.gloo/verbs/unless.test.gloo +40 -0
  77. data/test.gloo/verbs/unload.test.gloo +61 -3
  78. metadata +6 -1
@@ -13,12 +13,19 @@ module Gloo
13
13
  GEM_PREFIX = 'gloo-'
14
14
  INIT_CLASS_SUFFIX = 'Init'
15
15
 
16
+ PINNED_ERR = "Could not unload library '%s': gloo loaded it itself, so it stays loaded.".freeze
17
+ IN_USE_ERR = "Could not unload library '%s': objects of its types are on the heap (%s).".freeze
18
+
16
19
  #
17
20
  # Set up the library manager.
18
21
  #
19
22
  def initialize( engine )
20
23
  @engine = engine
21
24
  @libraries = {}
25
+ # What each library registered (its Callback), for unloading.
26
+ @registrations = {}
27
+ # Libraries gloo loaded itself; unloading them is an error.
28
+ @pinned = []
22
29
  @engine.log.debug 'library manager initialized...'
23
30
  end
24
31
 
@@ -47,8 +54,12 @@ module Gloo
47
54
  # Load the library of the given name.
48
55
  # The name will correspond with the name of a directory
49
56
  # within the gloo libraries directory.
57
+ # A pinned library is one gloo loads itself (gloo-test, in test
58
+ # mode): it can't be unloaded, and survives a session reset.
50
59
  #
51
- def load_lib( name )
60
+ def load_lib( name, pinned: false )
61
+ @pinned << name if pinned && !@pinned.include?( name )
62
+
52
63
  # Check to see if the library is already loaded.
53
64
  if @libraries.key?( name )
54
65
  @engine.log.info "Library #{name} is already loaded."
@@ -92,12 +103,65 @@ module Gloo
92
103
  plugin_class = Object.const_get( class_name )
93
104
  inst = plugin_class.new
94
105
  lib_cb = Callback.new( @engine )
106
+ @registrations[ name ] = lib_cb
95
107
  inst.register( lib_cb )
96
108
  rescue NameError
97
109
  @engine.err "Could not find class '#{class_name}' in library '#{name}'."
98
110
  end
99
111
  end
100
112
 
113
+
114
+ #
115
+ # Is the library one gloo loaded itself (see load_lib)?
116
+ #
117
+ def pinned?( name )
118
+ return @pinned.include?( name )
119
+ end
120
+
121
+ #
122
+ # Unload the library of the given name: take its verbs and object
123
+ # types out of the dictionary, and forget it's loaded. The Ruby
124
+ # code stays loaded (it can't be un-required), so load_lib
125
+ # registers it again. Not done, and an error, for a pinned
126
+ # library or while objects of its types are on the heap.
127
+ # Unloading a library that isn't loaded does nothing.
128
+ # Returns false if it couldn't be unloaded, true otherwise.
129
+ #
130
+ def unload_lib( name )
131
+ unless @libraries.key?( name )
132
+ @engine.log.info "Library #{name} isn't loaded."
133
+ return true
134
+ end
135
+
136
+ if pinned?( name )
137
+ @engine.err format( PINNED_ERR, name )
138
+ return false
139
+ end
140
+
141
+ cb = @registrations[ name ]
142
+ in_use = cb ? cb.objects_in_use : []
143
+ unless in_use.empty?
144
+ @engine.err format( IN_USE_ERR, name, in_use.map( &:pn ).join( ', ' ) )
145
+ return false
146
+ end
147
+
148
+ cb&.unregister
149
+ @registrations.delete( name )
150
+ @libraries.delete( name )
151
+ @engine.log.debug "Core library unloaded: #{name}"
152
+ return true
153
+ end
154
+
155
+
156
+ #
157
+ # Unload every library except the pinned ones (see load_lib), as
158
+ # for a session reset. Called with the heap already emptied, so no
159
+ # object of a library's types can stop it.
160
+ #
161
+ def unload_unpinned
162
+ ( @libraries.keys - @pinned ).each { |name| unload_lib( name ) }
163
+ end
164
+
101
165
  end
102
166
  end
103
167
  end
@@ -31,6 +31,7 @@ module Gloo
31
31
  QUIT_NAME = 'quit'.freeze
32
32
  QUIT_DESCRIPTION = 'Quit the application'.freeze
33
33
  QUIT_METHOD = 'cmd_quit'.freeze
34
+ QUIT_HINT = "Use 'quit' to leave.".freeze
34
35
 
35
36
  #
36
37
  # Initialize the shell runner.
@@ -296,22 +297,48 @@ module Gloo
296
297
  def repl
297
298
  setup_completion
298
299
 
299
- while !@context.done && ( line = Readline.readline( prompt, true ) )
300
+ until @context.done
301
+ line = read_line
302
+ next if line == :interrupted
303
+ break unless line
304
+
300
305
  tokens = line.strip.split( ' ' )
301
306
  if tokens.empty?
302
307
  handle_empty_command
303
308
  next
304
309
  end
305
310
 
306
- result = traverse( @root, tokens )
311
+ # Ctrl-C stops the command and comes back to this prompt.
312
+ @engine.run_interruptible { run_tokens( tokens ) }
313
+ end
314
+ end
307
315
 
308
- if result[ :node ]
309
- run_before_action
310
- execute_command( result[ :node ], tokens, result[ :parent ] )
311
- run_after_action
312
- else
313
- handle_unknown_command
314
- end
316
+ #
317
+ # Read a line at the prompt: nil at the end of input, or
318
+ # :interrupted if Ctrl-C dropped the line (with the hint, if
319
+ # nothing had been typed).
320
+ #
321
+ def read_line
322
+ return Readline.readline( prompt, true )
323
+ rescue Interrupt
324
+ typed = Readline.respond_to?( :line_buffer ) ? Readline.line_buffer.to_s : ''
325
+ @engine.interrupted_at_prompt( typed, @include_quit ? QUIT_HINT : nil )
326
+ return :interrupted
327
+ end
328
+
329
+ #
330
+ # Find and run the command for the given tokens, with the before
331
+ # and after actions.
332
+ #
333
+ def run_tokens( tokens )
334
+ result = traverse( @root, tokens )
335
+
336
+ if result[ :node ]
337
+ run_before_action
338
+ execute_command( result[ :node ], tokens, result[ :parent ] )
339
+ run_after_action
340
+ else
341
+ handle_unknown_command
315
342
  end
316
343
  end
317
344
 
@@ -65,12 +65,14 @@ module Gloo
65
65
  end
66
66
 
67
67
  #
68
- # Is the object the do script of a loop (a repeat or an each)?
68
+ # Is the object the do script of a loop (a repeat, an each or an
69
+ # until)?
69
70
  #
70
71
  def loop_do?( obj )
71
72
  parent = obj&.parent
72
73
  return false unless parent.is_a?( Gloo::Objs::Repeat ) ||
73
- parent.is_a?( Gloo::Objs::Each )
74
+ parent.is_a?( Gloo::Objs::Each ) ||
75
+ parent.is_a?( Gloo::Objs::Until )
74
76
 
75
77
  return parent.find_child( Gloo::Objs::Each::DO ).equal?( obj )
76
78
  end
@@ -114,8 +116,8 @@ module Gloo
114
116
  :syntax => [ 'break', 'break loop' ],
115
117
  :parameters => [
116
118
  'loop — Optional. Also end the loop whose do script this is. ' \
117
- 'Only valid directly in a loop\'s do script (repeat, or any ' \
118
- 'kind of each).'
119
+ 'Only valid directly in a loop\'s do script (repeat, until, ' \
120
+ 'or any kind of each).'
119
121
  ],
120
122
  :result => 'No more commands are executed in the currently ' \
121
123
  'running script. If there are other scripts in the stack, ' \
@@ -18,6 +18,8 @@ module Gloo
18
18
  # Run the verb.
19
19
  #
20
20
  def run
21
+ return unless take_path_arg( 1 )
22
+
21
23
  msg = @tokens.after_token( FOR )
22
24
 
23
25
  unless msg
@@ -67,10 +69,14 @@ module Gloo
67
69
  'state while tell is used to trigger an action. Using the ' \
68
70
  'verb that matches intent makes the code read like ' \
69
71
  'natural communication.',
70
- :syntax => [ 'check {path.to.object} for {condition_message}' ],
72
+ :syntax => [
73
+ 'check {path.to.object} for {condition_message}',
74
+ 'check ( {expression} ) for {condition_message}'
75
+ ],
71
76
  :parameters => [
72
77
  '{path.to.object} — The object that we want to send a condition_message to.',
73
- '{message} — The condition_message to send.'
78
+ '{message} — The condition_message to send.',
79
+ Gloo::Core::Verb::COMPUTED_PATH_DOC
74
80
  ],
75
81
  :result => 'The result depends on the message that is sent, but ' \
76
82
  'by convention the result of the check will be in it.',
@@ -15,13 +15,15 @@ module Gloo
15
15
  NO_NAME_ERR = 'Object name is missing!'.freeze
16
16
  BAD_NAME_CHARS = /[()"']/.freeze
17
17
  BAD_NAME_ERR = "'%s' isn't a name! To create an object at a " \
18
- 'computed path, put the path into an alias, then create ' \
19
- 'the alias: create slot* as string.'.freeze
18
+ 'computed path, put the whole path in parentheses: ' \
19
+ "create ( 'list.' n ) as string.".freeze
20
20
 
21
21
  #
22
22
  # Run the verb.
23
23
  #
24
24
  def run
25
+ return @engine.heap.it.set_to( false ) unless take_path_arg( 1 )
26
+
25
27
  name = @tokens.second
26
28
  type = @tokens.after_token( AS )
27
29
  value = @tokens.after_token( VAL )
@@ -109,12 +111,16 @@ module Gloo
109
111
  :shortcut => KEYWORD_SHORT,
110
112
  :description => 'Create a new object of given type with given ' \
111
113
  'value. Both type and value are optional when creating an object.',
112
- :syntax => [ 'create {new.object.path} as {type} : {value}' ],
114
+ :syntax => [
115
+ 'create {new.object.path} as {type} : {value}',
116
+ 'create ( {expression} ) as {type} : {value}'
117
+ ],
113
118
  :parameters => [
114
119
  '{new.object.path} — The path and name of the new object. ' \
115
120
  'Like any path, it can start from the root, from here in ' \
116
121
  'a script (^.box.new, ^^.new), or from the context (@.new).',
117
122
  '{type} — The type of the new object. Optional; if not provided the object will be untyped.',
123
+ Gloo::Core::Verb::COMPUTED_PATH_DOC,
118
124
  "{value} — The initial value for the new object. Optional; if not provided the object will have the default value for the type."
119
125
  ],
120
126
  :result => "If nothing exists at the path, a new object is " \
@@ -126,7 +132,7 @@ module Gloo
126
132
  :errors => [
127
133
  "#{NO_NAME_ERR} — The name of the object was not specified and the object cannot be created.",
128
134
  "Could not create '{path}': Object '{parent.path}' was not found. — The parent container named in the path does not exist. Every container above the new object must already exist. Nothing is created, and it is false.",
129
- "#{format( BAD_NAME_ERR, '{name}' )} — The name has parentheses or quotes, or there are extra words between the name and as / : — create takes a name as written. Nothing is created, and it is false."
135
+ "#{format( BAD_NAME_ERR, '{name}' )} — The name has quotes or a stray parenthesis, or there are extra words between the name and as / : — a name is taken as written; to compute one, put the whole path in parentheses. Nothing is created, and it is false."
130
136
  ],
131
137
  :examples => <<~EXAMPLES.strip
132
138
  # Basic examples of creating an object from the gloo shell:
@@ -134,6 +140,9 @@ module Gloo
134
140
  > create s : "abc"
135
141
  > create t
136
142
 
143
+ # Create at a path worked out at runtime:
144
+ > create ( 'list.' n ) as string
145
+
137
146
  # Example of creating an object with an alias:
138
147
  a [can] :
139
148
  ln [alias] : x
data/lib/gloo/verbs/if.rb CHANGED
@@ -27,8 +27,13 @@ module Gloo
27
27
 
28
28
  @then = @tokens.expr_after( SEPARATORS, ELSE )
29
29
  @else = @tokens.expr_after( ELSE )
30
+ give_params_to_last_part
30
31
 
31
- if evals_true( value )
32
+ truth = evals_true( value )
33
+ # A condition that reported an error abandons the line.
34
+ return if truth.nil?
35
+
36
+ if truth
32
37
  run_then
33
38
  else
34
39
  run_else unless @else.blank?
@@ -55,6 +60,23 @@ module Gloo
55
60
 
56
61
  private
57
62
 
63
+ #
64
+ # A trailing ( ... ) the parser split off the line belongs to the
65
+ # command at the end of it (eg. show's colour in
66
+ # if x then show 'a' (red)): give it back to the else part if
67
+ # there is one, otherwise to the then part.
68
+ #
69
+ def give_params_to_last_part
70
+ return unless @params.respond_to?( :cmd )
71
+
72
+ group = " ( #{@params.cmd} )"
73
+ if !@else.blank?
74
+ @else += group
75
+ elsif !@then.blank?
76
+ @then += group
77
+ end
78
+ end
79
+
58
80
  #
59
81
  # Get the list of tokens that represent the parameters
60
82
  # of the if command.
@@ -72,18 +94,14 @@ module Gloo
72
94
  end
73
95
 
74
96
  #
75
- # Does the given value evalute to true?
97
+ # Does the given value evalute to true? The [bool] rule decides
98
+ # (see Boolean.to_bool). Nil if working it out reported an error.
76
99
  #
77
100
  def evals_true( value )
78
- eval_result = false
79
- if value.count.positive?
80
- expr = Gloo::Expr::Expression.new( @engine, value )
81
- result = expr.evaluate
82
- eval_result = true if result == true
83
- eval_result = true if result.is_a?( Numeric ) && result != 0
84
- end
101
+ result, ok = evaluate_expr( value )
102
+ return nil unless ok
85
103
 
86
- return eval_result
104
+ return Gloo::Objs::Boolean.to_bool( @engine, result )
87
105
  end
88
106
 
89
107
  #
@@ -137,6 +155,11 @@ module Gloo
137
155
  "#{MISSING_EXPR_ERR} — No expression is provided as parameter to the verb.",
138
156
  'Other errors depend on the command that is run.'
139
157
  ],
158
+ :notes => 'What counts as true follows the [bool] rule: true, a ' \
159
+ 'number other than 0, and the text true or t are true; anything ' \
160
+ 'else is false (blank quietly, other text with a warning). See ' \
161
+ 'doc language_syntax, What Counts as True. A condition that ' \
162
+ 'reports an error abandons the line: neither command runs.',
140
163
  :examples => <<~EXAMPLES.strip
141
164
  #
142
165
  # If statement example
@@ -19,6 +19,8 @@ module Gloo
19
19
  # Run the verb.
20
20
  #
21
21
  def run
22
+ return unless take_path_arg( 1 )
23
+
22
24
  target = @tokens.token_count > 1 ? @tokens.second : nil
23
25
  arg_tokens = @tokens.token_count > 1 ? @tokens.params[ 1..-1 ] : []
24
26
 
@@ -53,12 +55,15 @@ module Gloo
53
55
  :description => 'Invoke a function. Set it to the result of the function.',
54
56
  :syntax => [
55
57
  'invoke {path.to.function} {params}',
58
+ 'invoke ( {expression} ) {params}',
56
59
  'invoke( {path.to.function} {params} ) — inline, usable inside any expression',
57
60
  '~>( {path.to.function} {params} ) — inline, shortcut spelling'
58
61
  ],
59
62
  :parameters => [
60
63
  '{path.to.function} — The function we want to invoke.',
61
- '{params} — The list of parameters to the function.'
64
+ '{params} — The list of parameters to the function.',
65
+ Gloo::Core::Verb::COMPUTED_PATH_DOC + ' Leave a space after invoke: invoke( … ) with no ' \
66
+ 'space is the inline call form.'
62
67
  ],
63
68
  :result => 'The result of the function is put into it; if ' \
64
69
  'anything goes wrong, it is false. The ' \
@@ -15,6 +15,8 @@ module Gloo
15
15
  # Run the verb.
16
16
  #
17
17
  def run
18
+ return unless take_path_arg( 1 )
19
+
18
20
  levels = determine_levels
19
21
  target = self.determine_target
20
22
  indent = self.determine_indent
@@ -185,9 +187,13 @@ module Gloo
185
187
  'setting is on, any listed object that has a doc (the ' \
186
188
  'comment block declared immediately above it in its source ' \
187
189
  'file) shows it too.',
188
- :syntax => [ 'list {path.to.object}' ],
190
+ :syntax => [
191
+ 'list {path.to.object}',
192
+ 'list ( {expression} )'
193
+ ],
189
194
  :parameters => [
190
- '{path.to.object} — Optional path to object that will be listed. When no path is provided, the current context is used.'
195
+ '{path.to.object} — Optional path to object that will be listed. When no path is provided, the current context is used.',
196
+ Gloo::Core::Verb::COMPUTED_PATH_DOC
191
197
  ],
192
198
  :result => 'Object and children are listed out in the CLI. ' \
193
199
  'Doc lines are included when the list_docs setting is on.',
@@ -198,6 +204,7 @@ module Gloo
198
204
  > list
199
205
  > list my.container
200
206
  > list root
207
+ > list ( 'app.' section )
201
208
  EXAMPLES
202
209
  }
203
210
  end
@@ -159,7 +159,10 @@ module Gloo
159
159
  'check {obj} for doc, or see it inline in the object tree ' \
160
160
  'with list when the list_docs setting is on. When a name ' \
161
161
  'is declared in more than one loaded file, the first ' \
162
- 'non-empty doc wins, same as the first value.',
162
+ "non-empty doc wins, same as the first value.\n\n" \
163
+ 'A library or extension stays loaded until it is unloaded ' \
164
+ '(unload lib, unload ext); loading one that is already ' \
165
+ 'loaded does nothing.',
163
166
  :examples => <<~EXAMPLES.strip
164
167
  # Next to this file (or the app folder, in App mode)
165
168
  > load parts/helpers
@@ -24,6 +24,8 @@ module Gloo
24
24
  # nothing.
25
25
  #
26
26
  def run
27
+ return unless take_path_arg( 1 ) && take_path_arg( TO )
28
+
27
29
  dst = lookup_dst
28
30
  return if dst.nil?
29
31
 
@@ -131,10 +133,14 @@ module Gloo
131
133
  :description => 'Move an object to a new parent. A name is unique ' \
132
134
  'in its container, so the new parent must not already have a ' \
133
135
  'child with the same name.',
134
- :syntax => [ 'move {path.to.object} to {new.parent}' ],
136
+ :syntax => [
137
+ 'move {path.to.object} to {new.parent}',
138
+ 'move ( {expression} ) to ( {expression} )'
139
+ ],
135
140
  :parameters => [
136
141
  '{path.to.object} — The object that we want to move.',
137
- '{new.parent} — The new location for the object.'
142
+ '{new.parent} — The new location for the object.',
143
+ "#{Gloo::Core::Verb::COMPUTED_PATH_DOC} Either or both can be computed."
138
144
  ],
139
145
  :result => 'The object will now be in the new location. Moving it ' \
140
146
  'to the parent it is already in does nothing. A pure action: it ' \
@@ -18,6 +18,8 @@ module Gloo
18
18
  # Run the verb.
19
19
  #
20
20
  def run
21
+ return @engine.heap.it.set_to( false ) unless take_path_arg( INTO )
22
+
21
23
  value = fetch_value_tokens
22
24
  return @engine.heap.it.set_to( false ) if value.nil?
23
25
 
@@ -111,10 +113,14 @@ module Gloo
111
113
  :shortcut => KEYWORD_SHORT,
112
114
  :description => 'Put a value into an object. ' \
113
115
  'The value is the result of an expression.',
114
- :syntax => [ 'put {expression} into {dst.path}' ],
116
+ :syntax => [
117
+ 'put {expression} into {dst.path}',
118
+ 'put {expression} into ( {expression} )'
119
+ ],
115
120
  :parameters => [
116
121
  '{expression} — The expression that is evaluated.',
117
- '{dst.path} — The path to the destination object.'
122
+ '{dst.path} — The path to the destination object.',
123
+ Gloo::Core::Verb::COMPUTED_PATH_DOC
118
124
  ],
119
125
  :result => 'The destination object has the result of the ' \
120
126
  'evaluated expression. It will also be set into it. If ' \
@@ -132,6 +138,7 @@ module Gloo
132
138
  > put 123 into x
133
139
  > put 3 + 5 into x
134
140
  > put TRUE into flag
141
+ > put 5 into ( 'counts.' fruit )
135
142
  EXAMPLES
136
143
  }
137
144
  end
@@ -71,7 +71,8 @@ module Gloo
71
71
  :notes => 'If a file has changes that have not been saved, ' \
72
72
  'reloading discards them (a warning is logged, but the ' \
73
73
  'reload still proceeds). reload takes no object; to reload ' \
74
- 'just one object\'s file, send it the reload message.',
74
+ 'just one object\'s file, send it the reload message. ' \
75
+ 'Loaded libraries and extensions stay loaded.',
75
76
  :examples => <<~EXAMPLES.strip
76
77
  > reload
77
78
  EXAMPLES
@@ -18,6 +18,8 @@ module Gloo
18
18
  # Run the verb.
19
19
  #
20
20
  def run
21
+ return unless take_path_arg( 1 )
22
+
21
23
  if @tokens.token_count < 2
22
24
  @engine.syntax_err MISSING_EXPR_ERR
23
25
  return
@@ -85,12 +87,14 @@ module Gloo
85
87
  'same as sending a run message to the object.',
86
88
  :syntax => [
87
89
  'run {path.to.object}',
90
+ 'run ( {expression} )',
88
91
  'run ~> {expression}'
89
92
  ],
90
93
  :parameters => [
91
94
  '{path.to.object} — Reference to the object which will be ' \
92
95
  'run. The object must be a runnable object such as a script.',
93
- '{expression} — Evaluate the expression and run it.'
96
+ '{expression} — Evaluate the expression and run it.',
97
+ Gloo::Core::Verb::COMPUTED_PATH_DOC
94
98
  ],
95
99
  :result => 'The result depends on the object that is run.',
96
100
  :errors => [
@@ -102,6 +106,9 @@ module Gloo
102
106
  > create s as script : "show 3 + 4"
103
107
  > run s
104
108
 
109
+ # Run the script at a path worked out at runtime:
110
+ > run ( 'jobs.' name )
111
+
105
112
  # Run a script in an evaluated expression:
106
113
  > create s as string : "show 3 + 4"
107
114
  > run ~> s
@@ -17,6 +17,8 @@ module Gloo
17
17
  # Run the verb.
18
18
  #
19
19
  def run
20
+ return unless take_path_arg( 1 )
21
+
20
22
  name = @tokens.second
21
23
  return if name && Gloo::Core::Pn.new( @engine, name ).it_target_err?( 'saved' )
22
24
  return @engine.persist_man.save name unless @tokens.index_of( TO )
@@ -86,11 +88,13 @@ module Gloo
86
88
  :syntax => [
87
89
  'save',
88
90
  'save {path.to.object}',
91
+ 'save ( {expression} )',
89
92
  'save {path.to.object} to {path}',
90
93
  'save {path.to.object} to ( {expression} )'
91
94
  ],
92
95
  :parameters => [
93
96
  '{path.to.object} — Name of the object to save.',
97
+ "save ( {expression} ) — The object to save, worked out: #{Gloo::Core::Verb::COMPUTED_PATH_DOC.sub( '( {expression} ) — ', '' )}",
94
98
  '{path} — Where to save it: a full path, one starting ' \
95
99
  'with ~, or a relative name (.gloo appended if omitted). ' \
96
100
  'A relative name goes in the first place a relative load ' \
@@ -19,6 +19,8 @@ module Gloo
19
19
  # Run the verb.
20
20
  #
21
21
  def run
22
+ return unless take_path_arg( 1 )
23
+
22
24
  msg = @tokens.after_token( TO )
23
25
 
24
26
  unless msg
@@ -67,10 +69,14 @@ module Gloo
67
69
  'or change state, while check is used to investigate ' \
68
70
  'state. Using the verb that matches intent makes the ' \
69
71
  'code read like natural communication.',
70
- :syntax => [ 'tell {path.to.object} to {message}' ],
72
+ :syntax => [
73
+ 'tell {path.to.object} to {message}',
74
+ 'tell ( {expression} ) to {message}'
75
+ ],
71
76
  :parameters => [
72
77
  '{path.to.object} — The object that we want to send a message to.',
73
- '{message} — The message to send.'
78
+ '{message} — The message to send.',
79
+ Gloo::Core::Verb::COMPUTED_PATH_DOC
74
80
  ],
75
81
  :result => 'The result depends on the message that is sent.',
76
82
  :errors => [
@@ -82,6 +88,7 @@ module Gloo
82
88
  > tell the.script to run
83
89
  > tell my.str to up
84
90
  > tell the.container to count
91
+ > tell ( 'jobs.' name ) to run
85
92
  EXAMPLES
86
93
  :notes => <<~NOTES.strip
87
94
  tell and check send the same message the same way — the two
@@ -27,8 +27,13 @@ module Gloo
27
27
 
28
28
  @do = @tokens.expr_after( SEPARATORS, ELSE )
29
29
  @else = @tokens.expr_after( ELSE )
30
+ give_params_to_last_part
30
31
 
31
- if evals_false( value )
32
+ truth = evals_false( value )
33
+ # A condition that reported an error abandons the line.
34
+ return if truth.nil?
35
+
36
+ if truth
32
37
  run_do
33
38
  else
34
39
  run_else unless @else.blank?
@@ -55,6 +60,23 @@ module Gloo
55
60
 
56
61
  private
57
62
 
63
+ #
64
+ # A trailing ( ... ) the parser split off the line belongs to the
65
+ # command at the end of it (eg. show's colour in
66
+ # unless x do show 'a' (red)): give it back to the else part if
67
+ # there is one, otherwise to the do part.
68
+ #
69
+ def give_params_to_last_part
70
+ return unless @params.respond_to?( :cmd )
71
+
72
+ group = " ( #{@params.cmd} )"
73
+ if !@else.blank?
74
+ @else += group
75
+ elsif !@do.blank?
76
+ @do += group
77
+ end
78
+ end
79
+
58
80
  #
59
81
  # Get the list of tokens that represent the parameters
60
82
  # of the unless command.
@@ -72,18 +94,15 @@ module Gloo
72
94
  end
73
95
 
74
96
  #
75
- # Does the given value evalute to true?
97
+ # Does the given value evalute to false? The exact opposite of if:
98
+ # the [bool] rule decides (see Boolean.to_bool). Nil if working it
99
+ # out reported an error.
76
100
  #
77
101
  def evals_false( value )
78
- eval_result = false
79
- if value.count.positive?
80
- expr = Gloo::Expr::Expression.new( @engine, value )
81
- result = expr.evaluate
82
- eval_result = true if result == false
83
- eval_result = true if result.is_a?( Numeric ) && result.zero?
84
- end
102
+ result, ok = evaluate_expr( value )
103
+ return nil unless ok
85
104
 
86
- return eval_result
105
+ return !Gloo::Objs::Boolean.to_bool( @engine, result )
87
106
  end
88
107
 
89
108
  #
@@ -137,6 +156,11 @@ module Gloo
137
156
  "#{MISSING_EXPR_ERR} — No expression is provided as parameter to the verb.",
138
157
  'Other errors depend on the command that is run.'
139
158
  ],
159
+ :notes => 'What counts as true follows the [bool] rule: true, a ' \
160
+ 'number other than 0, and the text true or t are true; anything ' \
161
+ 'else is false (blank quietly, other text with a warning). See ' \
162
+ 'doc language_syntax, What Counts as True. A condition that ' \
163
+ 'reports an error abandons the line: neither command runs.',
140
164
  :examples => <<~EXAMPLES.strip
141
165
  #
142
166
  # Unless statement example