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,6 +13,13 @@ module Gloo
13
13
 
14
14
  attr_reader :tokens, :params
15
15
 
16
+ BLANK_PATH_ERR = "Object path '( %s )' is blank.".freeze
17
+ COMPUTED_PATH_DOC = '( {expression} ) — Instead of a literal ' \
18
+ 'path, an expression in parentheses: it is worked out and its ' \
19
+ 'value is used as the path, as if it had been typed there. The ' \
20
+ "fixed part is quoted text: ( 'list.' n ). See doc " \
21
+ 'language_syntax, Computed Arguments.'.freeze
22
+
16
23
  #
17
24
  # Set up the verb.
18
25
  #
@@ -92,7 +99,7 @@ module Gloo
92
99
  # couldn't be worked out (already reported), true otherwise.
93
100
  #
94
101
  def take_evaluated_arg
95
- return true unless @params
102
+ return take_leading_group_arg unless @params
96
103
 
97
104
  value, ok = evaluate_expr( @params.tokens )
98
105
  return false unless ok
@@ -102,6 +109,128 @@ module Gloo
102
109
  return true
103
110
  end
104
111
 
112
+ #
113
+ # The whole argument is a group right after the verb, as in
114
+ # load ( x ): the parser leaves that in the tokens (it groups,
115
+ # see Parser#split_params), so it's worked out here and its value
116
+ # put in its place. Returns false if the expression couldn't be
117
+ # worked out (already reported), true otherwise.
118
+ #
119
+ def take_leading_group_arg
120
+ return true unless @tokens.respond_to?( :token_count )
121
+
122
+ last = path_group_end( 1 )
123
+ return true unless last && last == @tokens.token_count - 1
124
+
125
+ value, ok = evaluate_expr( Gloo::Core::Tokens.new( path_group_text( 1, last ) ).tokens )
126
+ return false unless ok
127
+
128
+ @tokens = @tokens.with_tokens_replaced( 1, last, value.to_s )
129
+ return true
130
+ end
131
+
132
+ #
133
+ # For a verb whose argument at the given position is an object
134
+ # path: a ( expr ) group there is worked out, and its value put
135
+ # back as one token, so the path can be computed, as in
136
+ # put 1 into ( 'counts.' key ). The verb then reads its arguments
137
+ # as usual. The position is a token index (1 for the word after
138
+ # the verb), or a keyword, meaning the token after it ('into').
139
+ #
140
+ # The group is either mid-line, in the tokens (tell ( t ) to run),
141
+ # or, when the path is the last argument, already split off by
142
+ # the parser into params (put 1 into ( x )). A trailing group
143
+ # after some other argument (tell t to run ( 1 )) is left alone.
144
+ # Returns false if the expression couldn't be worked out (already
145
+ # reported), true otherwise.
146
+ #
147
+ def take_path_arg( position )
148
+ return true unless @tokens.respond_to?( :token_count )
149
+
150
+ i = path_arg_index( position )
151
+ return true unless i
152
+
153
+ return take_trailing_path_arg if i == @tokens.token_count
154
+
155
+ last = path_group_end( i )
156
+ return true unless last
157
+
158
+ text = path_group_text( i, last )
159
+ value, ok = evaluate_expr( Gloo::Core::Tokens.new( text ).tokens )
160
+ return false unless ok && path_value_given?( value, text )
161
+
162
+ @tokens = @tokens.with_tokens_replaced( i, last, value.to_s )
163
+ return true
164
+ end
165
+
166
+ #
167
+ # The token index of the path argument at the given position:
168
+ # an index as given, or the one after a keyword. Nil if the
169
+ # keyword isn't there.
170
+ #
171
+ def path_arg_index( position )
172
+ return position if position.is_a?( Integer )
173
+
174
+ i = @tokens.index_of( position )
175
+ return i ? i + 1 : nil
176
+ end
177
+
178
+ #
179
+ # The path is the last argument and has no token: if the parser
180
+ # split a trailing group off into params, that's the path. Work
181
+ # it out and add it as the last token.
182
+ #
183
+ def take_trailing_path_arg
184
+ return true unless @params.respond_to?( :tokens )
185
+
186
+ value, ok = evaluate_expr( @params.tokens )
187
+ return false unless ok && path_value_given?( value, @params.tokens.join( ' ' ) )
188
+
189
+ @tokens = @tokens.with_token( value.to_s )
190
+ @params = nil
191
+ return true
192
+ end
193
+
194
+ #
195
+ # A worked-out path must have some text; blank is reported (the
196
+ # group's text, as written, names it) and the verb doesn't run.
197
+ #
198
+ def path_value_given?( value, text )
199
+ return true unless value.to_s.strip.empty?
200
+
201
+ @engine.err format( BLANK_PATH_ERR, text.strip )
202
+ return false
203
+ end
204
+
205
+ #
206
+ # If the token at index i opens a group, the index of the token
207
+ # that closes it; nil if it doesn't open one or never closes. A
208
+ # group can be written ( p ), (p) or ('a.' b), so parentheses are
209
+ # counted in each token; a quoted token is text and isn't counted.
210
+ #
211
+ def path_group_end( i )
212
+ return nil unless @tokens.at( i )&.start_with?( '(' )
213
+
214
+ depth = 0
215
+ ( i...@tokens.token_count ).each do |j|
216
+ token = @tokens.at( j )
217
+ next if Gloo::Core::Tokens::QUOTE_CHARS.include?( token[ 0 ] )
218
+
219
+ depth += token.count( '(' ) - token.count( ')' )
220
+ return j if depth <= 0
221
+ end
222
+ return nil
223
+ end
224
+
225
+ #
226
+ # The text inside the group from token first to token last, with
227
+ # its outer parentheses taken off.
228
+ #
229
+ def path_group_text( first, last )
230
+ text = ( first..last ).map { |j| @tokens.at( j ) }.join( ' ' )
231
+ return text.strip[ 1..-2 ]
232
+ end
233
+
105
234
  #
106
235
  # Work out an expression from the given tokens. Returns the value
107
236
  # and whether it worked: false if the expression reported a
@@ -48,9 +48,13 @@ module Gloo
48
48
  #
49
49
  def self.action( engine, action )
50
50
  engine.exec_env.push_action action
51
- engine.log.debug "Sending message #{action.msg} to #{action.to.name}"
52
- action.dispatch
53
- engine.exec_env.pop_action
51
+ begin
52
+ engine.log.debug "Sending message #{action.msg} to #{action.to.name}"
53
+ action.dispatch
54
+ ensure
55
+ # Also when something unwinds the run (runaway recursion).
56
+ engine.exec_env.pop_action
57
+ end
54
58
  end
55
59
 
56
60
  end
@@ -0,0 +1,34 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2026 Eric Crane. All rights reserved.
3
+ #
4
+ # Scripts ran inside each other until Ruby ran out of stack: a script
5
+ # that runs itself (directly, or through others) with no end.
6
+ #
7
+ # It isn't a StandardError, on purpose: nothing on the way up may
8
+ # swallow it. It unwinds the run to the line that started the
9
+ # recursion, which reports it once (see Runner).
10
+ #
11
+
12
+ module Gloo
13
+ module Exec
14
+ class RunawayRecursion < Exception
15
+
16
+ MSG = 'Could not run %s: scripts ran %d deep, one inside ' \
17
+ 'another (runaway recursion?).'.freeze
18
+
19
+ attr_reader :location, :start_depth
20
+
21
+ #
22
+ # Note where it happened: the deepest script, how deep it was, and
23
+ # the depth (count of running scripts) of the line that started
24
+ # the recursion.
25
+ #
26
+ def initialize( script_pn, depth, location, start_depth = 0 )
27
+ super( format( MSG, script_pn, depth ) )
28
+ @location = location
29
+ @start_depth = start_depth
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -27,12 +27,58 @@ module Gloo
27
27
  # from a missing gem) isn't a StandardError, and would
28
28
  # otherwise stop gloo altogether.
29
29
  engine.handle_exception( ex )
30
+ rescue SystemStackError
31
+ runaway( engine, runaway_recursion( engine ) )
32
+ rescue Gloo::Exec::RunawayRecursion => ex
33
+ runaway( engine, ex )
34
+ rescue Interrupt
35
+ # Ctrl-C: note where it stopped, and let it unwind the run to
36
+ # whatever is waiting for it (see Engine#run_interruptible).
37
+ engine.note_interrupt_location
38
+ raise
30
39
  ensure
31
40
  engine.exec_env.verbs.pop
32
41
  end
33
42
  engine.heap.error.clear_if_no_errors
34
43
  end
35
44
 
45
+ #
46
+ # Ruby ran out of stack: scripts ran inside each other with no
47
+ # end. Note the deepest script, how deep, and where the recursion
48
+ # started.
49
+ #
50
+ def self.runaway_recursion( engine )
51
+ env = engine.exec_env
52
+ pn = env.running_script&.obj&.pn
53
+ return Gloo::Exec::RunawayRecursion.new(
54
+ pn, env.scripts.size, env.current_location, recursion_start( env ) )
55
+ end
56
+
57
+ #
58
+ # The depth of the line that started the recursion: the number of
59
+ # scripts running below the first script that runs again further
60
+ # up the stack. 0 (the outermost line) if none repeats.
61
+ #
62
+ def self.recursion_start( env )
63
+ objs = env.scripts.stack.map( &:obj )
64
+ counts = objs.tally
65
+ return objs.index { |o| counts[ o ] > 1 } || 0
66
+ end
67
+
68
+ #
69
+ # Runaway recursion unwinds the run to the line that started it,
70
+ # and is reported there, once; that line is abandoned like any
71
+ # failed line, and its script carries on. Every verb inside passes
72
+ # it on. The outermost verb reports it in any case.
73
+ #
74
+ def self.runaway( engine, ex )
75
+ env = engine.exec_env
76
+ raise ex unless env.scripts.size <= ex.start_depth || env.verbs.size == 1
77
+
78
+ engine.err ex.message, location: ex.location
79
+ engine.heap.it.set_to false
80
+ end
81
+
36
82
  #
37
83
  # Send 'run' message to the object.
38
84
  # Resolve the path_name and then send the run message.
@@ -27,7 +27,23 @@ module Gloo
27
27
  #
28
28
  def run
29
29
  @engine.exec_env.push_script self
30
+ begin
31
+ run_lines
32
+ rescue Interrupt
33
+ # Ctrl-C between verbs (eg. while a line is parsed): note this
34
+ # script as where it stopped, before it's popped.
35
+ @engine.note_interrupt_location
36
+ raise
37
+ ensure
38
+ # Also when something unwinds the run (runaway recursion).
39
+ @engine.exec_env.pop_script
40
+ end
41
+ end
30
42
 
43
+ #
44
+ # Run the script's lines, until the end or a break.
45
+ #
46
+ def run_lines
31
47
  if @obj.value.is_a? String
32
48
  @line = 1
33
49
  @engine.parser.run @obj.value
@@ -39,8 +55,6 @@ module Gloo
39
55
  @engine.parser.run line
40
56
  end
41
57
  end
42
-
43
- @engine.exec_env.pop_script
44
58
  end
45
59
 
46
60
  #
@@ -9,6 +9,9 @@ module Gloo
9
9
  class Expression
10
10
 
11
11
  DIVIDE_BY_ZERO_ERR = 'Division by zero.'.freeze
12
+ EMPTY_GROUP_ERR = 'Empty parentheses.'.freeze
13
+ OPEN_PAREN = '('.freeze
14
+ CLOSE_PAREN = ')'.freeze
12
15
 
13
16
  # ---------------------------------------------------------------------
14
17
  # Constructor
@@ -50,11 +53,39 @@ module Gloo
50
53
  end
51
54
  missing_value( @op ) if @op
52
55
 
53
- return @left.value if @left.is_a? Gloo::Core::Literal
54
- return @left.value if @left.is_a? Gloo::Expr::Call
55
- return resolve_ref @left if @left.is_a? Gloo::Core::Pn
56
+ return evaluate_sym( @left )
57
+ end
58
+
59
+ #
60
+ # Split grouping parentheses off the tokens, so each is a token
61
+ # of its own: '(3' and '4)' become '(' '3' and '4' ')'. Quoted
62
+ # text and inline calls (invoke( ... )) are left whole.
63
+ #
64
+ def self.split_parens( tokens )
65
+ return tokens.flat_map do |t|
66
+ next [ t ] unless t.is_a?( String )
67
+ next [ t ] if Gloo::Core::Tokens::QUOTE_CHARS.include?( t[ 0 ] )
68
+ next [ t ] if Gloo::Expr::Call.call?( t )
69
+
70
+ split_paren_token( t )
71
+ end
72
+ end
56
73
 
57
- return @left
74
+ #
75
+ # Split the leading '(' and trailing ')' off one token.
76
+ #
77
+ def self.split_paren_token( token )
78
+ opens = []
79
+ while token.length > 1 && token.start_with?( OPEN_PAREN )
80
+ opens << OPEN_PAREN
81
+ token = token[ 1..-1 ]
82
+ end
83
+ closes = []
84
+ while token.length > 1 && token.end_with?( CLOSE_PAREN )
85
+ closes << CLOSE_PAREN
86
+ token = token[ 0..-2 ]
87
+ end
88
+ return opens + [ token ] + closes
58
89
  end
59
90
 
60
91
  # ---------------------------------------------------------------------
@@ -81,6 +112,7 @@ module Gloo
81
112
  # result is no value. A missing value (nil) was already reported.
82
113
  #
83
114
  def apply_op( op, left, right )
115
+ op.engine = @engine
84
116
  result = op.perform( left, right )
85
117
  if op.is_a?( Gloo::Expr::OpDiv ) && result.is_a?( Float ) &&
86
118
  ( result.nan? || result.infinite? )
@@ -110,6 +142,8 @@ module Gloo
110
142
  return sym.value if sym.is_a? Gloo::Core::Literal
111
143
  return sym.value if sym.is_a? Gloo::Expr::Call
112
144
  return resolve_ref sym if sym.is_a? Gloo::Core::Pn
145
+ # A group: worked out when it's reached, left to right.
146
+ return sym.evaluate if sym.is_a? Gloo::Expr::Expression
113
147
 
114
148
  return sym
115
149
  end
@@ -134,9 +168,46 @@ module Gloo
134
168
  # Identify each token in the list.
135
169
  #
136
170
  def identify_tokens
137
- @tokens.each do |o|
138
- @symbols << identify_token( o )
171
+ tokens = Expression.split_parens( @tokens )
172
+ i = 0
173
+ while i < tokens.length
174
+ token = tokens[ i ]
175
+ if token == OPEN_PAREN
176
+ close = matching_close( tokens, i )
177
+ @symbols << group( tokens[ i + 1...close ] )
178
+ i = close + 1
179
+ else
180
+ # A stray ')' was reported as a syntax error with the
181
+ # command; the best guess is to leave it out.
182
+ @symbols << identify_token( token ) unless token == CLOSE_PAREN
183
+ i += 1
184
+ end
185
+ end
186
+ end
187
+
188
+ #
189
+ # The index of the ')' that closes the '(' at open_index. An
190
+ # unclosed group (reported as a syntax error with the command)
191
+ # runs to the end, as the best guess.
192
+ #
193
+ def matching_close( tokens, open_index )
194
+ depth = 0
195
+ ( open_index...tokens.length ).each do |j|
196
+ depth += 1 if tokens[ j ] == OPEN_PAREN
197
+ depth -= 1 if tokens[ j ] == CLOSE_PAREN
198
+ return j if depth.zero?
139
199
  end
200
+ return tokens.length
201
+ end
202
+
203
+ #
204
+ # A group in the expression: its own expression, worked out when
205
+ # it is reached. An empty group is a syntax error, and no value.
206
+ #
207
+ def group( tokens )
208
+ @engine.syntax_err EMPTY_GROUP_ERR if tokens.empty?
209
+
210
+ return Expression.new( @engine, tokens )
140
211
  end
141
212
 
142
213
  #
@@ -8,14 +8,30 @@ module Gloo
8
8
  module Expr
9
9
  class LDecimal < Gloo::Core::Literal
10
10
 
11
+ # A decimal as written: an optional sign; digits with an optional
12
+ # fraction, or just a fraction (.5); an optional exponent (1.0e3,
13
+ # 2e-5). Not 5. (a path start, like 'list.'), and not 1_000 or
14
+ # 0x1A. Plain digits match the pattern too, but they're an integer
15
+ # (see decimal?).
16
+ PATTERN = /\A[-+]?(\d+(\.\d+)?|\.\d+)([eE][-+]?\d+)?\z/
17
+
11
18
  #
12
- # Is the given token a decimal?
19
+ # Is the given token a decimal: a number with a fraction or an
20
+ # exponent? A plain integer isn't (see LInteger).
13
21
  #
14
22
  def self.decimal?( token )
15
23
  return true if token.is_a? Numeric
16
24
 
17
25
  s = token.strip
18
- return s.to_f.to_s == s
26
+ return PATTERN.match?( s ) && !LInteger.integer?( s )
27
+ end
28
+
29
+ #
30
+ # Is the given text a number a decimal can hold: a decimal or an
31
+ # integer, as written in a literal?
32
+ #
33
+ def self.number?( text )
34
+ return decimal?( text ) || LInteger.integer?( text )
19
35
  end
20
36
 
21
37
  #
@@ -8,14 +8,17 @@ module Gloo
8
8
  module Expr
9
9
  class LInteger < Gloo::Core::Literal
10
10
 
11
+ # An integer as written: an optional sign, then digits. Leading
12
+ # zeros are fine (007 is 7, never octal).
13
+ PATTERN = /\A[-+]?\d+\z/
14
+
11
15
  #
12
16
  # Is the given token an integer?
13
17
  #
14
18
  def self.integer?( token )
15
19
  return true if token.is_a? Integer
16
20
 
17
- s = token.strip
18
- return s.to_i.to_s == s
21
+ return PATTERN.match?( token.strip )
19
22
  end
20
23
 
21
24
  #
@@ -14,6 +14,10 @@ module Gloo
14
14
  # Perform the operation and return the result.
15
15
  #
16
16
  def perform( left, right )
17
+ # Numbers, and text used as a number: promote, then work them out.
18
+ nums = math_numbers( left, right )
19
+ return nums[ 0 ] / nums[ 1 ] if nums
20
+
17
21
  return left / right.to_i if left.is_a? Integer
18
22
 
19
23
  return left / right.to_f if left.is_a? Numeric
@@ -18,6 +18,10 @@ module Gloo
18
18
  cmp = DtTools.compare_dt( left, right )
19
19
  return cmp == 0 unless cmp == :not_dt
20
20
 
21
+ # Numbers and text: compared by the shared rule.
22
+ cmp = compare( left, right )
23
+ return cmp.zero? if cmp
24
+
21
25
  return left == right.to_s if left.is_a? String
22
26
 
23
27
  return left == right.to_i if left.is_a? Integer
@@ -17,6 +17,10 @@ module Gloo
17
17
  cmp = DtTools.compare_dt( left, right )
18
18
  return cmp.is_a?( Integer ) && cmp.positive? unless cmp == :not_dt
19
19
 
20
+ # Numbers and text: compared by the shared rule.
21
+ cmp = compare( left, right )
22
+ return cmp.positive? if cmp
23
+
20
24
  return left > right.to_i if left.is_a? Integer
21
25
 
22
26
  return left > right.to_f if left.is_a? Numeric
@@ -17,6 +17,10 @@ module Gloo
17
17
  cmp = DtTools.compare_dt( left, right )
18
18
  return cmp.is_a?( Integer ) && !cmp.negative? unless cmp == :not_dt
19
19
 
20
+ # Numbers and text: compared by the shared rule.
21
+ cmp = compare( left, right )
22
+ return !cmp.negative? if cmp
23
+
20
24
  return left >= right.to_i if left.is_a? Integer
21
25
 
22
26
  return left >= right.to_f if left.is_a? Numeric
@@ -17,6 +17,10 @@ module Gloo
17
17
  cmp = DtTools.compare_dt( left, right )
18
18
  return cmp.is_a?( Integer ) && cmp != 0 unless cmp == :not_dt
19
19
 
20
+ # Numbers and text: compared by the shared rule.
21
+ cmp = compare( left, right )
22
+ return !cmp.zero? if cmp
23
+
20
24
  return left != right.to_s if left.is_a? String
21
25
 
22
26
  return left != right.to_i if left.is_a? Integer
@@ -17,6 +17,10 @@ module Gloo
17
17
  cmp = DtTools.compare_dt( left, right )
18
18
  return cmp.is_a?( Integer ) && cmp.negative? unless cmp == :not_dt
19
19
 
20
+ # Numbers and text: compared by the shared rule.
21
+ cmp = compare( left, right )
22
+ return cmp.negative? if cmp
23
+
20
24
  return left < right.to_i if left.is_a? Integer
21
25
 
22
26
  return left < right.to_f if left.is_a? Numeric
@@ -17,6 +17,10 @@ module Gloo
17
17
  cmp = DtTools.compare_dt( left, right )
18
18
  return cmp.is_a?( Integer ) && !cmp.positive? unless cmp == :not_dt
19
19
 
20
+ # Numbers and text: compared by the shared rule.
21
+ cmp = compare( left, right )
22
+ return !cmp.positive? if cmp
23
+
20
24
  return left <= right.to_i if left.is_a? Integer
21
25
 
22
26
  return left <= right.to_f if left.is_a? Numeric
@@ -14,6 +14,10 @@ module Gloo
14
14
  # Perform the operation and return the result.
15
15
  #
16
16
  def perform( left, right )
17
+ # Numbers, and text used as a number: promote, then work them out.
18
+ nums = math_numbers( left, right )
19
+ return nums[ 0 ] - nums[ 1 ] if nums
20
+
17
21
  return left - right.to_i if left.is_a? Integer
18
22
 
19
23
  return left - right.to_f if left.is_a? Numeric
@@ -14,13 +14,9 @@ module Gloo
14
14
  # Perform the operation and return the result.
15
15
  #
16
16
  def perform( left, right )
17
- if ( left.is_a? Integer ) && ( right.is_a? Integer )
18
- return left * right
19
- end
20
-
21
- if (left.is_a? Numeric) && (right.is_a? Numeric)
22
- return left * right
23
- end
17
+ # Numbers, and text used as a number: promote, then work them out.
18
+ nums = math_numbers( left, right )
19
+ return nums[ 0 ] * nums[ 1 ] if nums
24
20
 
25
21
  return left * right.to_i if left.is_a? Integer
26
22
 
@@ -17,7 +17,14 @@ module Gloo
17
17
  # Perform the operation and return the result.
18
18
  #
19
19
  def perform( left, right )
20
- return left + right.to_s if left.is_a? String
20
+ # Text on either side: join, as text.
21
+ if left.is_a?( String ) || right.is_a?( String )
22
+ return left.to_s + right.to_s
23
+ end
24
+
25
+ # Two numbers: promote, then work them out as numbers.
26
+ nums = promote( left, right )
27
+ return nums[ 0 ] + nums[ 1 ] if nums
21
28
 
22
29
  return left + right.to_i if left.is_a? Integer
23
30
 
@@ -95,7 +95,12 @@ module Gloo
95
95
  :messages => [
96
96
  'resolve — Check to see if the object referenced exists. Sets it to true or false.'
97
97
  ],
98
- :notes => 'The alias also reflects (forwards) the messages of the object it points to.',
98
+ :notes => 'The alias also reflects (forwards) the messages of the object it points to. ' \
99
+ 'For a path built and used on one line, a computed path needs no alias: ' \
100
+ "create ( 'list.' n ) as string. Putting an alias in parentheses adds a step: " \
101
+ '( ln ) follows the alias and uses its target\'s value as the path, while ' \
102
+ '( ln* ) uses the path the alias holds, the same as ln. ' \
103
+ 'See doc language_syntax, Computed Arguments.',
99
104
  :examples => <<~EXAMPLES.strip
100
105
  #
101
106
  # Alias object.
@@ -13,6 +13,7 @@ module Gloo
13
13
  TRUE = 'true'.freeze
14
14
  FALSE = 'false'.freeze
15
15
  BOOLEAN_STRINGS = [ TRUE, FALSE, 't', 'f' ].freeze
16
+ BAD_VALUE_WARN = "'%s' is not true or false; using false.".freeze
16
17
 
17
18
  #
18
19
  # The name of the object type.
@@ -32,10 +33,17 @@ module Gloo
32
33
  # Set the value with any necessary type conversions.
33
34
  #
34
35
  def set_value( new_value )
35
- self.value = Gloo::Objs::Boolean.coerse_to_bool( new_value )
36
- return unless Gloo::Objs::Boolean.bad_value?( new_value )
36
+ self.value = Gloo::Objs::Boolean.to_bool( @engine, new_value )
37
+ end
37
38
 
38
- @engine.warn "'#{new_value}' is not true or false; using #{self.value}."
39
+ #
40
+ # Convert a value to true or false, warning about text that is
41
+ # neither. The one rule for what counts as true: for a [bool]'s
42
+ # value and for every condition (if, unless, until).
43
+ #
44
+ def self.to_bool( engine, value )
45
+ engine.warn format( BAD_VALUE_WARN, value ) if bad_value?( value )
46
+ return coerse_to_bool( value )
39
47
  end
40
48
 
41
49
  #
@@ -63,8 +71,9 @@ module Gloo
63
71
  return false if new_value.strip.downcase == FALSE
64
72
  return true if new_value.strip.downcase == 't'
65
73
  return false if new_value.strip.downcase == 'f'
66
- elsif new_value.class.name == 'Integer'
67
- return new_value.zero? ? false : true
74
+ elsif new_value.is_a?( ::Numeric )
75
+ # Any number but zero is true, decimals included.
76
+ return !new_value.zero?
68
77
  end
69
78
 
70
79
  return new_value == true
@@ -147,7 +156,7 @@ module Gloo
147
156
  'true — Set the boolean to true.',
148
157
  'false — Set the boolean to false.'
149
158
  ],
150
- :notes => 'Recognized values are true, false, t and f (in any case), and integers (0 is false). Any other string is false, with a warning: "\'maybe\' is not true or false; using false." A blank value is false.',
159
+ :notes => 'Recognized values are true, false, t and f (in any case), and numbers (0 is false; any other number, decimals included, is true). Any other string is false, with a warning: "\'maybe\' is not true or false; using false." A blank value is false. Conditions (if, unless, until) use the same rule; see doc language_syntax, What Counts as True.',
151
160
  :examples => <<~EXAMPLES.strip
152
161
  b [can] :
153
162
  flag [boolean] : true