gloo-lang 0.9.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/lib/VERSION +1 -1
  3. data/lib/dependencies.rb +2 -2
  4. data/lib/{gloo_lang.rb → gloo-lang.rb} +7 -9
  5. data/lib/gloo_lang/app/args.rb +112 -0
  6. data/lib/gloo_lang/app/engine.rb +230 -0
  7. data/lib/gloo_lang/app/help.rb +156 -0
  8. data/lib/gloo_lang/app/log.rb +81 -0
  9. data/lib/gloo_lang/app/mode.rb +27 -0
  10. data/lib/gloo_lang/app/settings.rb +186 -0
  11. data/lib/gloo_lang/convert/converter.rb +35 -0
  12. data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
  13. data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
  14. data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
  15. data/lib/gloo_lang/core/baseo.rb +30 -0
  16. data/lib/gloo_lang/core/dictionary.rb +181 -0
  17. data/lib/gloo_lang/core/error.rb +61 -0
  18. data/lib/gloo_lang/core/event_manager.rb +44 -0
  19. data/lib/gloo_lang/core/factory.rb +210 -0
  20. data/lib/gloo_lang/core/gloo_system.rb +266 -0
  21. data/lib/gloo_lang/core/heap.rb +52 -0
  22. data/lib/gloo_lang/core/here.rb +36 -0
  23. data/lib/gloo_lang/core/it.rb +36 -0
  24. data/lib/gloo_lang/core/literal.rb +30 -0
  25. data/lib/gloo_lang/core/obj.rb +303 -0
  26. data/lib/gloo_lang/core/obj_finder.rb +30 -0
  27. data/lib/gloo_lang/core/op.rb +40 -0
  28. data/lib/gloo_lang/core/parser.rb +59 -0
  29. data/lib/gloo_lang/core/pn.rb +188 -0
  30. data/lib/gloo_lang/core/tokens.rb +165 -0
  31. data/lib/gloo_lang/core/verb.rb +86 -0
  32. data/lib/gloo_lang/exec/action.rb +48 -0
  33. data/lib/gloo_lang/exec/dispatch.rb +40 -0
  34. data/lib/gloo_lang/exec/exec_env.rb +74 -0
  35. data/lib/gloo_lang/exec/runner.rb +45 -0
  36. data/lib/gloo_lang/exec/script.rb +49 -0
  37. data/lib/gloo_lang/exec/stack.rb +78 -0
  38. data/lib/gloo_lang/expr/expression.rb +118 -0
  39. data/lib/gloo_lang/expr/l_boolean.rb +36 -0
  40. data/lib/gloo_lang/expr/l_decimal.rb +39 -0
  41. data/lib/gloo_lang/expr/l_integer.rb +37 -0
  42. data/lib/gloo_lang/expr/l_string.rb +58 -0
  43. data/lib/gloo_lang/expr/op_div.rb +22 -0
  44. data/lib/gloo_lang/expr/op_minus.rb +22 -0
  45. data/lib/gloo_lang/expr/op_mult.rb +22 -0
  46. data/lib/gloo_lang/expr/op_plus.rb +24 -0
  47. data/lib/gloo_lang/help/app/application.txt +22 -0
  48. data/lib/gloo_lang/help/app/configuration.txt +7 -0
  49. data/lib/gloo_lang/help/app/default_help.txt +14 -0
  50. data/lib/gloo_lang/help/app/logging.txt +16 -0
  51. data/lib/gloo_lang/help/core/color.txt +31 -0
  52. data/lib/gloo_lang/help/core/error.txt +33 -0
  53. data/lib/gloo_lang/help/core/events.txt +21 -0
  54. data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
  55. data/lib/gloo_lang/help/core/here.txt +30 -0
  56. data/lib/gloo_lang/help/core/it.txt +23 -0
  57. data/lib/gloo_lang/help/core/ops.txt +16 -0
  58. data/lib/gloo_lang/help/core/pathname.txt +29 -0
  59. data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
  60. data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
  61. data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
  62. data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
  63. data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
  64. data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
  65. data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
  66. data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
  67. data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
  68. data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
  69. data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
  70. data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
  71. data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
  72. data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
  73. data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
  74. data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
  75. data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
  76. data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
  77. data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
  78. data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
  79. data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
  80. data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
  81. data/lib/gloo_lang/help/objs/data/query.txt +37 -0
  82. data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
  83. data/lib/gloo_lang/help/objs/data/table.txt +46 -0
  84. data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
  85. data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
  86. data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
  87. data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
  88. data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
  89. data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
  90. data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
  91. data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
  92. data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
  93. data/lib/gloo_lang/help/objs/system/file.txt +48 -0
  94. data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
  95. data/lib/gloo_lang/help/objs/system/system.txt +32 -0
  96. data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
  97. data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
  98. data/lib/gloo_lang/help/objs/web/json.txt +34 -0
  99. data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
  100. data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
  101. data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
  102. data/lib/gloo_lang/help/verbs/alert.txt +33 -0
  103. data/lib/gloo_lang/help/verbs/beep.txt +25 -0
  104. data/lib/gloo_lang/help/verbs/cls.txt +24 -0
  105. data/lib/gloo_lang/help/verbs/context.txt +43 -0
  106. data/lib/gloo_lang/help/verbs/create.txt +33 -0
  107. data/lib/gloo_lang/help/verbs/execute.txt +27 -0
  108. data/lib/gloo_lang/help/verbs/help.txt +34 -0
  109. data/lib/gloo_lang/help/verbs/if.txt +37 -0
  110. data/lib/gloo_lang/help/verbs/list.txt +34 -0
  111. data/lib/gloo_lang/help/verbs/load.txt +38 -0
  112. data/lib/gloo_lang/help/verbs/move.txt +42 -0
  113. data/lib/gloo_lang/help/verbs/put.txt +38 -0
  114. data/lib/gloo_lang/help/verbs/quit.txt +25 -0
  115. data/lib/gloo_lang/help/verbs/run.txt +41 -0
  116. data/lib/gloo_lang/help/verbs/save.txt +26 -0
  117. data/lib/gloo_lang/help/verbs/show.txt +30 -0
  118. data/lib/gloo_lang/help/verbs/tell.txt +34 -0
  119. data/lib/gloo_lang/help/verbs/unless.txt +38 -0
  120. data/lib/gloo_lang/help/verbs/version.txt +32 -0
  121. data/lib/gloo_lang/help/verbs/wait.txt +29 -0
  122. data/lib/gloo_lang/objs/basic/alias.rb +78 -0
  123. data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
  124. data/lib/gloo_lang/objs/basic/container.rb +76 -0
  125. data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
  126. data/lib/gloo_lang/objs/basic/integer.rb +73 -0
  127. data/lib/gloo_lang/objs/basic/script.rb +99 -0
  128. data/lib/gloo_lang/objs/basic/string.rb +77 -0
  129. data/lib/gloo_lang/objs/basic/text.rb +87 -0
  130. data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
  131. data/lib/gloo_lang/objs/cli/banner.rb +108 -0
  132. data/lib/gloo_lang/objs/cli/bar.rb +133 -0
  133. data/lib/gloo_lang/objs/cli/colorize.rb +73 -0
  134. data/lib/gloo_lang/objs/cli/confirm.rb +96 -0
  135. data/lib/gloo_lang/objs/cli/menu.rb +206 -0
  136. data/lib/gloo_lang/objs/cli/menu_item.rb +95 -0
  137. data/lib/gloo_lang/objs/cli/pastel.rb +97 -0
  138. data/lib/gloo_lang/objs/cli/prompt.rb +110 -0
  139. data/lib/gloo_lang/objs/cli/select.rb +126 -0
  140. data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
  141. data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
  142. data/lib/gloo_lang/objs/data/markdown.rb +84 -0
  143. data/lib/gloo_lang/objs/data/mysql.rb +192 -0
  144. data/lib/gloo_lang/objs/data/query.rb +176 -0
  145. data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
  146. data/lib/gloo_lang/objs/data/table.rb +140 -0
  147. data/lib/gloo_lang/objs/dev/git.rb +140 -0
  148. data/lib/gloo_lang/objs/dev/stats.rb +120 -0
  149. data/lib/gloo_lang/objs/dt/date.rb +50 -0
  150. data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
  151. data/lib/gloo_lang/objs/dt/time.rb +50 -0
  152. data/lib/gloo_lang/objs/ror/erb.rb +116 -0
  153. data/lib/gloo_lang/objs/ror/eval.rb +107 -0
  154. data/lib/gloo_lang/objs/snd/play.rb +48 -0
  155. data/lib/gloo_lang/objs/snd/say.rb +98 -0
  156. data/lib/gloo_lang/objs/system/file_handle.rb +138 -0
  157. data/lib/gloo_lang/objs/system/ssh_exec.rb +126 -0
  158. data/lib/gloo_lang/objs/system/system.rb +136 -0
  159. data/lib/gloo_lang/objs/web/http_get.rb +159 -0
  160. data/lib/gloo_lang/objs/web/http_post.rb +183 -0
  161. data/lib/gloo_lang/objs/web/json.rb +135 -0
  162. data/lib/gloo_lang/objs/web/slack.rb +130 -0
  163. data/lib/gloo_lang/objs/web/teams.rb +117 -0
  164. data/lib/gloo_lang/objs/web/uri.rb +148 -0
  165. data/lib/gloo_lang/persist/file_loader.rb +191 -0
  166. data/lib/gloo_lang/persist/file_saver.rb +49 -0
  167. data/lib/gloo_lang/persist/file_storage.rb +45 -0
  168. data/lib/gloo_lang/persist/line_splitter.rb +81 -0
  169. data/lib/gloo_lang/persist/persist_man.rb +120 -0
  170. data/lib/gloo_lang/utils/format.rb +21 -0
  171. data/lib/gloo_lang/utils/stats.rb +205 -0
  172. data/lib/gloo_lang/utils/words.rb +19 -0
  173. data/lib/gloo_lang/verbs/alert.rb +79 -0
  174. data/lib/gloo_lang/verbs/beep.rb +40 -0
  175. data/lib/gloo_lang/verbs/cls.rb +37 -0
  176. data/lib/gloo_lang/verbs/context.rb +62 -0
  177. data/lib/gloo_lang/verbs/create.rb +68 -0
  178. data/lib/gloo_lang/verbs/execute.rb +56 -0
  179. data/lib/gloo_lang/verbs/help.rb +264 -0
  180. data/lib/gloo_lang/verbs/if.rb +92 -0
  181. data/lib/gloo_lang/verbs/list.rb +98 -0
  182. data/lib/gloo_lang/verbs/load.rb +45 -0
  183. data/lib/gloo_lang/verbs/move.rb +89 -0
  184. data/lib/gloo_lang/verbs/put.rb +94 -0
  185. data/lib/gloo_lang/verbs/quit.rb +40 -0
  186. data/lib/gloo_lang/verbs/run.rb +75 -0
  187. data/lib/gloo_lang/verbs/save.rb +39 -0
  188. data/lib/gloo_lang/verbs/show.rb +64 -0
  189. data/lib/gloo_lang/verbs/tell.rb +79 -0
  190. data/lib/gloo_lang/verbs/unless.rb +92 -0
  191. data/lib/gloo_lang/verbs/version.rb +37 -0
  192. data/lib/gloo_lang/verbs/wait.rb +42 -0
  193. metadata +191 -3
@@ -0,0 +1,165 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An ordered list of tokens.
5
+ # The list of tokens makes up a command.
6
+ #
7
+
8
+ module GlooLang
9
+ module Core
10
+ class Tokens
11
+
12
+ attr_reader :cmd, :tokens
13
+
14
+ # ---------------------------------------------------------------------
15
+ # Constructor
16
+ # ---------------------------------------------------------------------
17
+
18
+ #
19
+ # Set up the tokens.
20
+ # The command string is parsed into tokens during creation.
21
+ #
22
+ def initialize( cmd_string )
23
+ @cmd = cmd_string
24
+ @tokens = []
25
+ tokenize @cmd
26
+ end
27
+
28
+ # ---------------------------------------------------------------------
29
+ # Public functions
30
+ # ---------------------------------------------------------------------
31
+
32
+ #
33
+ # Get the number of tokens
34
+ #
35
+ def token_count
36
+ return @tokens.size
37
+ end
38
+
39
+ #
40
+ # Get the verb (the first word)
41
+ #
42
+ def verb
43
+ return first
44
+ end
45
+
46
+ #
47
+ # Get all tokens except the first.
48
+ #
49
+ def params
50
+ return @tokens[ 1..-1 ]
51
+ end
52
+
53
+ #
54
+ # Get the first token.
55
+ #
56
+ def first
57
+ return @tokens.first if @tokens
58
+ end
59
+
60
+ #
61
+ # Get the last token.
62
+ #
63
+ def last
64
+ return @tokens.last if @tokens
65
+ end
66
+
67
+ #
68
+ # Get the second token.
69
+ #
70
+ def second
71
+ return @tokens[ 1 ] if @tokens&.size&.positive?
72
+ end
73
+
74
+ #
75
+ # Get the token at the the requested index.
76
+ #
77
+ def at( index )
78
+ return @tokens[ index ] if @tokens && @tokens.size >= index
79
+ end
80
+
81
+ #
82
+ # Get the index of the given token.
83
+ #
84
+ def index_of( token )
85
+ return nil unless @tokens
86
+
87
+ return @tokens.find_index { |o| o.casecmp( token ).zero? }
88
+ end
89
+
90
+ #
91
+ # Get the list of tokens after the given token
92
+ #
93
+ def tokens_after( token )
94
+ i = index_of token
95
+ return @tokens[ i + 1..-1 ] if i && @tokens && @tokens.size > ( i + 1 )
96
+
97
+ return nil
98
+ end
99
+
100
+ #
101
+ # Get the expression after the given token
102
+ #
103
+ def expr_after( token )
104
+ str = ''
105
+ tokens_after( token ).each do |t|
106
+ str << ' ' unless str.empty?
107
+ str << t.to_s
108
+ end
109
+ return str
110
+ end
111
+
112
+ #
113
+ # Get the item after a given token.
114
+ #
115
+ def after_token( token )
116
+ i = index_of token
117
+ return @tokens[ i + 1 ] if i && @tokens && @tokens.size > ( i + 1 )
118
+
119
+ return nil
120
+ end
121
+
122
+ #
123
+ # Get the item after a given token.
124
+ #
125
+ def before_token( token )
126
+ i = index_of token
127
+ return @tokens[ 0..i - 1 ] if i && @tokens && @tokens.size >= i
128
+
129
+ return nil
130
+ end
131
+
132
+ # ---------------------------------------------------------------------
133
+ # Private functions
134
+ # ---------------------------------------------------------------------
135
+
136
+ private
137
+
138
+ #
139
+ # Create a list of token from the given string.
140
+ #
141
+ def tokenize( str )
142
+ if str.index( '"' )
143
+ i = str.index( '"' )
144
+ j = str.index( '"', i + 1 )
145
+ j ||= str.length
146
+
147
+ tokenize( str[ 0..i - 1 ] ) if i > 1
148
+ @tokens << str[ i..j ]
149
+ tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
150
+ elsif str.index( "'" )
151
+ i = str.index( "'" )
152
+ j = str.index( "'", i + 1 )
153
+ j ||= str.length
154
+
155
+ tokenize( str[ 0..i - 1 ] ) if i > 1
156
+ @tokens << str[ i..j ]
157
+ tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
158
+ else
159
+ str.strip.split( ' ' ).each { |t| @tokens << t }
160
+ end
161
+ end
162
+
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,86 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An abstract base verb.
5
+ # Derives from the Baseo object.
6
+ # It is a special type of object in that it can be run
7
+ # and can perform an action.
8
+ #
9
+
10
+ module GlooLang
11
+ module Core
12
+ class Verb < Baseo
13
+
14
+ attr_reader :tokens, :params
15
+
16
+ #
17
+ # Set up the verb.
18
+ #
19
+ def initialize( tokens, params = [] )
20
+ @tokens = tokens
21
+ @params = params
22
+ end
23
+
24
+ #
25
+ # Register verbs when they are loaded.
26
+ #
27
+ def self.inherited( subclass )
28
+ Dictionary.instance.register_verb( subclass )
29
+ end
30
+
31
+ #
32
+ # Run the verb.
33
+ #
34
+ # We'll mark the application as not running and let the
35
+ # engine stop gracefully next time through the loop.
36
+ #
37
+ def run
38
+ raise 'this method should be overriden'
39
+ end
40
+
41
+ #
42
+ # Get the Verb's keyword.
43
+ #
44
+ # The keyword will be in lower case only.
45
+ # It is used by the parser.
46
+ #
47
+ def self.keyword
48
+ raise 'this method should be overriden'
49
+ end
50
+
51
+ #
52
+ # Get the Verb's keyword shortcut.
53
+ #
54
+ def self.keyword_shortcut
55
+ raise 'this method should be overriden'
56
+ end
57
+
58
+ #
59
+ # The object type, suitable for display.
60
+ #
61
+ def type_display
62
+ return self.class.keyword
63
+ end
64
+
65
+ #
66
+ # Generic function to get display value.
67
+ # Can be used for debugging, etc.
68
+ #
69
+ def display_value
70
+ return self.class.keyword
71
+ end
72
+
73
+ # ---------------------------------------------------------------------
74
+ # Help
75
+ # ---------------------------------------------------------------------
76
+
77
+ #
78
+ # Get help for this verb.
79
+ #
80
+ def self.help
81
+ return 'No help found.'
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,48 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # An action is a message sent to an object with optional parameters.
5
+ #
6
+
7
+ module GlooLang
8
+ module Exec
9
+ class Action
10
+
11
+ attr_accessor :msg, :to, :params
12
+
13
+ #
14
+ # Set up the action.
15
+ #
16
+ def initialize( msg, to, params = nil )
17
+ @msg = msg
18
+ @to = to
19
+ @params = params
20
+ end
21
+
22
+ #
23
+ # The action is valid if the object can receive
24
+ # the message specified.
25
+ #
26
+ def valid?
27
+ return @to.can_receive_message?( @msg )
28
+ end
29
+
30
+ #
31
+ # Execute the action.
32
+ # Dispatch the message to the object.
33
+ #
34
+ def dispatch
35
+ @to.send_message @msg, @params
36
+ end
37
+
38
+ #
39
+ # Generic function to get display value.
40
+ # Can be used for debugging, etc.
41
+ #
42
+ def display_value
43
+ return "#{@msg} -> #{@to.pn}"
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Central Message Dispatch.
5
+ # Responsible for sending message to objects.
6
+ # All object messaging goes through here so we can uniformly
7
+ # manage things like checking to make sure object can
8
+ # receive the messages sent, handling errors, etc.
9
+ #
10
+
11
+ module GlooLang
12
+ module Exec
13
+ class Dispatch
14
+
15
+ #
16
+ # Dispatch the given message to the given object.
17
+ #
18
+ def self.message( msg, to_obj, params = nil )
19
+ $log.debug "Dispatch message #{msg} to #{to_obj.name}"
20
+ a = GlooLang::Exec::Action.new msg, to_obj, params
21
+ GlooLang::Exec::Dispatch.action a
22
+ end
23
+
24
+ #
25
+ # Dispatch an action.
26
+ #
27
+ def self.action( action )
28
+ unless action.valid?
29
+ $log.warn "Object #{action.to.name} does not respond to #{action.msg}"
30
+ end
31
+
32
+ $engine.exec_env.push_action action
33
+ $log.debug "Sending message #{action.msg} to #{action.to.name}"
34
+ action.dispatch
35
+ $engine.exec_env.pop_action
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,74 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # The execution environment.
5
+ # The current state of running scripts and messaging.
6
+ #
7
+
8
+ module GlooLang
9
+ module Exec
10
+ class ExecEnv
11
+
12
+ attr_accessor :verbs, :actions, :scripts, :here
13
+
14
+ VERB_STACK = 'verbs'.freeze
15
+ ACTION_STACK = 'actions'.freeze
16
+ SCRIPT_STACK = 'scripts'.freeze
17
+ HERE_STACK = 'here'.freeze
18
+
19
+ #
20
+ # Set up the execution environment.
21
+ #
22
+ def initialize
23
+ $log.debug 'exec env intialized...'
24
+
25
+ @verbs = GlooLang::Exec::Stack.new VERB_STACK
26
+ @actions = GlooLang::Exec::Stack.new ACTION_STACK
27
+ @scripts = GlooLang::Exec::Stack.new SCRIPT_STACK
28
+ @here = GlooLang::Exec::Stack.new HERE_STACK
29
+ end
30
+
31
+ #
32
+ # Get the here object.
33
+ #
34
+ def here_obj
35
+ return nil if @here.stack.empty?
36
+
37
+ return @here.stack.last
38
+ end
39
+
40
+ #
41
+ # Push a script onto the stack.
42
+ #
43
+ def push_script( script )
44
+ @scripts.push script
45
+ @here.push script.obj
46
+ end
47
+
48
+ #
49
+ # Pop a script off the stack.
50
+ #
51
+ def pop_script
52
+ @scripts.pop
53
+ @here.pop
54
+ end
55
+
56
+ #
57
+ # Push an action onto the stack.
58
+ #
59
+ def push_action( action )
60
+ @actions.push action
61
+ # @here.push action.to
62
+ end
63
+
64
+ #
65
+ # Pop an action off the stack.
66
+ #
67
+ def pop_action
68
+ @actions.pop
69
+ # @here.pop
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,45 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # The Runner is a static helper function.
5
+ # It is used to send the run command to verbs.
6
+ #
7
+
8
+ module GlooLang
9
+ module Exec
10
+ class Runner
11
+
12
+ #
13
+ # Dispatch run command to a verb.
14
+ # We abstract this out in case there are things
15
+ # that need to be done before or after a verb
16
+ # is done running.
17
+ #
18
+ def self.go( verb )
19
+ $log.debug "running verb #{verb.type_display}"
20
+ $engine.heap.error.start_tracking
21
+ $engine.exec_env.verbs.push verb
22
+ verb&.run
23
+ $engine.exec_env.verbs.pop
24
+ $engine.heap.error.clear_if_no_errors
25
+ end
26
+
27
+ #
28
+ # Send 'run' message to the object.
29
+ # Resolve the path_name and then send the run message.
30
+ #
31
+ def self.run( path_name )
32
+ $log.debug "running script at #{path_name}"
33
+ pn = GlooLang::Core::Pn.new path_name
34
+ o = pn.resolve
35
+
36
+ if o
37
+ o.send_message 'run'
38
+ else
39
+ $log.error "Could not send message to object. Bad path: #{path_name}"
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # A script to be run.
5
+ #
6
+
7
+ module GlooLang
8
+ module Exec
9
+ class Script
10
+
11
+ attr_accessor :obj
12
+
13
+ #
14
+ # Set up the script.
15
+ #
16
+ def initialize( obj )
17
+ @obj = obj
18
+ end
19
+
20
+ #
21
+ # Run the script.
22
+ # The script might be a single string or an array
23
+ # of lines.
24
+ #
25
+ def run
26
+ $engine.exec_env.push_script self
27
+
28
+ if @obj.value.is_a? String
29
+ $engine.parser.run @obj.value
30
+ elsif @obj.value.is_a? Array
31
+ @obj.value.each do |line|
32
+ $engine.parser.run line
33
+ end
34
+ end
35
+
36
+ $engine.exec_env.pop_script
37
+ end
38
+
39
+ #
40
+ # Generic function to get display value.
41
+ # Can be used for debugging, etc.
42
+ #
43
+ def display_value
44
+ return @obj.pn
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,78 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A stack of items, a call stack.
5
+ #
6
+
7
+ module GlooLang
8
+ module Exec
9
+ class Stack
10
+
11
+ attr_accessor :stack
12
+
13
+ #
14
+ # Set up the stack.
15
+ #
16
+ def initialize( name )
17
+ @name = name
18
+ clear_stack
19
+ $log.debug "#{name} stack intialized..."
20
+ end
21
+
22
+ #
23
+ # Push an item onto the stack.
24
+ #
25
+ def push( obj )
26
+ $log.debug "#{@name}:push #{obj.display_value}"
27
+ @stack.push obj
28
+ self.update_out_file if $settings.debug
29
+ end
30
+
31
+ #
32
+ # Pop an item from the stack.
33
+ #
34
+ def pop
35
+ o = @stack.pop
36
+ $log.debug "#{@name}:pop #{o.display_value}"
37
+ self.update_out_file if $settings.debug
38
+ end
39
+
40
+ #
41
+ # Get the current size of the call stack.
42
+ #
43
+ def size
44
+ return @stack.size
45
+ end
46
+
47
+ #
48
+ # Get stack data for output.
49
+ #
50
+ def out_data
51
+ return @stack.map( &:display_value ).join( "\n" )
52
+ end
53
+
54
+ #
55
+ # Get the file we'll write debug information for the stack.
56
+ #
57
+ def out_file
58
+ return File.join( $settings.debug_path, @name )
59
+ end
60
+
61
+ #
62
+ # Update the stack trace file.
63
+ #
64
+ def update_out_file
65
+ File.write( self.out_file, self.out_data )
66
+ end
67
+
68
+ #
69
+ # Clear the stack and the output file.
70
+ #
71
+ def clear_stack
72
+ @stack = []
73
+ self.update_out_file
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,118 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An Expression that can be evaluated.
5
+ #
6
+
7
+ module GlooLang
8
+ module Expr
9
+ class Expression
10
+
11
+ # ---------------------------------------------------------------------
12
+ # Constructor
13
+ # ---------------------------------------------------------------------
14
+
15
+ #
16
+ # Create the expression from a list of tokens.
17
+ #
18
+ def initialize( tokens )
19
+ @tokens = tokens
20
+ @symbols = []
21
+ @left = nil
22
+ @right = nil
23
+ @op = nil
24
+ end
25
+
26
+ # ---------------------------------------------------------------------
27
+ # Evaluate Expression
28
+ # ---------------------------------------------------------------------
29
+
30
+ #
31
+ # Evaluate the expression and return the value.
32
+ #
33
+ def evaluate
34
+ identify_tokens
35
+
36
+ @symbols.each do |sym|
37
+ if sym.is_a? GlooLang::Core::Op
38
+ @op = sym
39
+ elsif @left.nil?
40
+ @left = sym
41
+ else
42
+ @right = sym
43
+ end
44
+
45
+ perform_op if @left && @right
46
+ end
47
+
48
+ return @left.value if @left.is_a? GlooLang::Core::Literal
49
+ return resolve_ref @left if @left.is_a? GlooLang::Core::Pn
50
+
51
+ return @left
52
+ end
53
+
54
+ # ---------------------------------------------------------------------
55
+ # Private functions
56
+ # ---------------------------------------------------------------------
57
+
58
+ private
59
+
60
+ #
61
+ # Perform the operation.
62
+ #
63
+ def perform_op
64
+ @op ||= GlooLang::Core::Op.default_op
65
+ l = evaluate_sym @left
66
+ r = evaluate_sym @right
67
+ @left = @op.perform l, r
68
+ @right = nil
69
+ @op = nil
70
+ end
71
+
72
+ #
73
+ # Evaluate the symbol and get a simple value.
74
+ #
75
+ def evaluate_sym( sym )
76
+ return sym.value if sym.is_a? GlooLang::Core::Literal
77
+ return resolve_ref sym if sym.is_a? GlooLang::Core::Pn
78
+
79
+ return sym
80
+ end
81
+
82
+ #
83
+ # resolve an object reference and get the value.
84
+ #
85
+ def resolve_ref( ref )
86
+ return ref.src if ref.named_color?
87
+
88
+ ob = ref.resolve
89
+ return ob.value if ob
90
+ end
91
+
92
+ #
93
+ # Identify each token in the list.
94
+ #
95
+ def identify_tokens
96
+ @tokens.each do |o|
97
+ @symbols << identify_token( o )
98
+ end
99
+ end
100
+
101
+ #
102
+ # Identify the tokens and create appropriate symbols.
103
+ #
104
+ def identify_token( token )
105
+ return GlooLang::Core::Op.create_op( token ) if GlooLang::Core::Op.op?( token )
106
+
107
+ return LBoolean.new( token ) if LBoolean.boolean?( token )
108
+ return LInteger.new( token ) if LInteger.integer?( token )
109
+ return LString.new( token ) if LString.string?( token )
110
+ return LDecimal.new( token ) if LDecimal.decimal?( token )
111
+
112
+ # last chance: an Object reference
113
+ return GlooLang::Core::Pn.new( token )
114
+ end
115
+
116
+ end
117
+ end
118
+ end