gloo-lang 0.9.2 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/gloo-lang.gemspec +1 -0
  4. data/lib/VERSION +1 -1
  5. data/lib/dependencies.rb +2 -2
  6. data/lib/gloo-lang.rb +1 -5
  7. data/lib/gloo_lang/app/args.rb +111 -0
  8. data/lib/gloo_lang/app/engine.rb +200 -0
  9. data/lib/gloo_lang/app/help.rb +117 -0
  10. data/lib/gloo_lang/app/info.rb +34 -0
  11. data/lib/gloo_lang/app/log.rb +81 -0
  12. data/lib/gloo_lang/app/mode.rb +27 -0
  13. data/lib/gloo_lang/app/platform.rb +75 -0
  14. data/lib/gloo_lang/app/settings.rb +185 -0
  15. data/lib/gloo_lang/convert/converter.rb +35 -0
  16. data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
  17. data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
  18. data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
  19. data/lib/gloo_lang/core/baseo.rb +30 -0
  20. data/lib/gloo_lang/core/dictionary.rb +181 -0
  21. data/lib/gloo_lang/core/error.rb +61 -0
  22. data/lib/gloo_lang/core/event_manager.rb +44 -0
  23. data/lib/gloo_lang/core/factory.rb +210 -0
  24. data/lib/gloo_lang/core/gloo_system.rb +266 -0
  25. data/lib/gloo_lang/core/heap.rb +52 -0
  26. data/lib/gloo_lang/core/here.rb +36 -0
  27. data/lib/gloo_lang/core/it.rb +36 -0
  28. data/lib/gloo_lang/core/literal.rb +30 -0
  29. data/lib/gloo_lang/core/obj.rb +303 -0
  30. data/lib/gloo_lang/core/obj_finder.rb +30 -0
  31. data/lib/gloo_lang/core/op.rb +40 -0
  32. data/lib/gloo_lang/core/parser.rb +59 -0
  33. data/lib/gloo_lang/core/pn.rb +188 -0
  34. data/lib/gloo_lang/core/tokens.rb +165 -0
  35. data/lib/gloo_lang/core/verb.rb +86 -0
  36. data/lib/gloo_lang/exec/action.rb +48 -0
  37. data/lib/gloo_lang/exec/dispatch.rb +40 -0
  38. data/lib/gloo_lang/exec/exec_env.rb +74 -0
  39. data/lib/gloo_lang/exec/runner.rb +45 -0
  40. data/lib/gloo_lang/exec/script.rb +49 -0
  41. data/lib/gloo_lang/exec/stack.rb +78 -0
  42. data/lib/gloo_lang/expr/expression.rb +118 -0
  43. data/lib/gloo_lang/expr/l_boolean.rb +36 -0
  44. data/lib/gloo_lang/expr/l_decimal.rb +39 -0
  45. data/lib/gloo_lang/expr/l_integer.rb +37 -0
  46. data/lib/gloo_lang/expr/l_string.rb +58 -0
  47. data/lib/gloo_lang/expr/op_div.rb +22 -0
  48. data/lib/gloo_lang/expr/op_minus.rb +22 -0
  49. data/lib/gloo_lang/expr/op_mult.rb +22 -0
  50. data/lib/gloo_lang/expr/op_plus.rb +24 -0
  51. data/lib/gloo_lang/help/app/application.txt +22 -0
  52. data/lib/gloo_lang/help/app/configuration.txt +7 -0
  53. data/lib/gloo_lang/help/app/default_help.txt +14 -0
  54. data/lib/gloo_lang/help/app/logging.txt +16 -0
  55. data/lib/gloo_lang/help/core/color.txt +31 -0
  56. data/lib/gloo_lang/help/core/error.txt +33 -0
  57. data/lib/gloo_lang/help/core/events.txt +21 -0
  58. data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
  59. data/lib/gloo_lang/help/core/here.txt +30 -0
  60. data/lib/gloo_lang/help/core/it.txt +23 -0
  61. data/lib/gloo_lang/help/core/ops.txt +16 -0
  62. data/lib/gloo_lang/help/core/pathname.txt +29 -0
  63. data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
  64. data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
  65. data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
  66. data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
  67. data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
  68. data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
  69. data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
  70. data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
  71. data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
  72. data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
  73. data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
  74. data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
  75. data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
  76. data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
  77. data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
  78. data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
  79. data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
  80. data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
  81. data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
  82. data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
  83. data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
  84. data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
  85. data/lib/gloo_lang/help/objs/data/query.txt +37 -0
  86. data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
  87. data/lib/gloo_lang/help/objs/data/table.txt +46 -0
  88. data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
  89. data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
  90. data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
  91. data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
  92. data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
  93. data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
  94. data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
  95. data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
  96. data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
  97. data/lib/gloo_lang/help/objs/system/file.txt +48 -0
  98. data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
  99. data/lib/gloo_lang/help/objs/system/system.txt +32 -0
  100. data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
  101. data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
  102. data/lib/gloo_lang/help/objs/web/json.txt +34 -0
  103. data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
  104. data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
  105. data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
  106. data/lib/gloo_lang/help/verbs/alert.txt +33 -0
  107. data/lib/gloo_lang/help/verbs/beep.txt +25 -0
  108. data/lib/gloo_lang/help/verbs/cls.txt +24 -0
  109. data/lib/gloo_lang/help/verbs/context.txt +43 -0
  110. data/lib/gloo_lang/help/verbs/create.txt +33 -0
  111. data/lib/gloo_lang/help/verbs/execute.txt +27 -0
  112. data/lib/gloo_lang/help/verbs/help.txt +34 -0
  113. data/lib/gloo_lang/help/verbs/if.txt +37 -0
  114. data/lib/gloo_lang/help/verbs/list.txt +34 -0
  115. data/lib/gloo_lang/help/verbs/load.txt +38 -0
  116. data/lib/gloo_lang/help/verbs/move.txt +42 -0
  117. data/lib/gloo_lang/help/verbs/put.txt +38 -0
  118. data/lib/gloo_lang/help/verbs/quit.txt +25 -0
  119. data/lib/gloo_lang/help/verbs/run.txt +41 -0
  120. data/lib/gloo_lang/help/verbs/save.txt +26 -0
  121. data/lib/gloo_lang/help/verbs/show.txt +30 -0
  122. data/lib/gloo_lang/help/verbs/tell.txt +34 -0
  123. data/lib/gloo_lang/help/verbs/unless.txt +38 -0
  124. data/lib/gloo_lang/help/verbs/version.txt +32 -0
  125. data/lib/gloo_lang/help/verbs/wait.txt +29 -0
  126. data/lib/gloo_lang/objs/basic/alias.rb +78 -0
  127. data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
  128. data/lib/gloo_lang/objs/basic/container.rb +65 -0
  129. data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
  130. data/lib/gloo_lang/objs/basic/integer.rb +73 -0
  131. data/lib/gloo_lang/objs/basic/script.rb +99 -0
  132. data/lib/gloo_lang/objs/basic/string.rb +77 -0
  133. data/lib/gloo_lang/objs/basic/text.rb +79 -0
  134. data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
  135. data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
  136. data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
  137. data/lib/gloo_lang/objs/data/markdown.rb +79 -0
  138. data/lib/gloo_lang/objs/data/mysql.rb +192 -0
  139. data/lib/gloo_lang/objs/data/query.rb +176 -0
  140. data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
  141. data/lib/gloo_lang/objs/data/table.rb +112 -0
  142. data/lib/gloo_lang/objs/dt/date.rb +50 -0
  143. data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
  144. data/lib/gloo_lang/objs/dt/time.rb +50 -0
  145. data/lib/gloo_lang/objs/ror/erb.rb +116 -0
  146. data/lib/gloo_lang/objs/ror/eval.rb +107 -0
  147. data/lib/gloo_lang/objs/web/http_get.rb +159 -0
  148. data/lib/gloo_lang/objs/web/http_post.rb +183 -0
  149. data/lib/gloo_lang/objs/web/json.rb +135 -0
  150. data/lib/gloo_lang/objs/web/slack.rb +130 -0
  151. data/lib/gloo_lang/objs/web/teams.rb +117 -0
  152. data/lib/gloo_lang/objs/web/uri.rb +148 -0
  153. data/lib/gloo_lang/persist/file_loader.rb +191 -0
  154. data/lib/gloo_lang/persist/file_saver.rb +49 -0
  155. data/lib/gloo_lang/persist/file_storage.rb +45 -0
  156. data/lib/gloo_lang/persist/line_splitter.rb +81 -0
  157. data/lib/gloo_lang/persist/persist_man.rb +120 -0
  158. data/lib/gloo_lang/utils/format.rb +21 -0
  159. data/lib/gloo_lang/utils/stats.rb +205 -0
  160. data/lib/gloo_lang/utils/words.rb +19 -0
  161. data/lib/gloo_lang/verbs/context.rb +62 -0
  162. data/lib/gloo_lang/verbs/create.rb +68 -0
  163. data/lib/gloo_lang/verbs/execute.rb +56 -0
  164. data/lib/gloo_lang/verbs/help.rb +264 -0
  165. data/lib/gloo_lang/verbs/if.rb +92 -0
  166. data/lib/gloo_lang/verbs/list.rb +98 -0
  167. data/lib/gloo_lang/verbs/load.rb +45 -0
  168. data/lib/gloo_lang/verbs/move.rb +89 -0
  169. data/lib/gloo_lang/verbs/put.rb +94 -0
  170. data/lib/gloo_lang/verbs/quit.rb +40 -0
  171. data/lib/gloo_lang/verbs/run.rb +75 -0
  172. data/lib/gloo_lang/verbs/save.rb +39 -0
  173. data/lib/gloo_lang/verbs/show.rb +64 -0
  174. data/lib/gloo_lang/verbs/tell.rb +79 -0
  175. data/lib/gloo_lang/verbs/unless.rb +92 -0
  176. data/lib/gloo_lang/verbs/version.rb +37 -0
  177. data/lib/gloo_lang/verbs/wait.rb +42 -0
  178. metadata +192 -2
@@ -0,0 +1,210 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object factory.
5
+ #
6
+
7
+ module GlooLang
8
+ module Core
9
+ class Factory < Baseo
10
+
11
+ # ---------------------------------------------------------------------
12
+ # Initializer
13
+ # ---------------------------------------------------------------------
14
+
15
+ #
16
+ # Set up the object factory.
17
+ #
18
+ def initialize
19
+ $log.debug 'object factory intialized...'
20
+ end
21
+
22
+ # ---------------------------------------------------------------------
23
+ # Factory Helpers
24
+ # ---------------------------------------------------------------------
25
+
26
+ #
27
+ # Helper shortcut to create an alias child object.
28
+ #
29
+ def create_alias( name, value, parent )
30
+ params = { :name => name,
31
+ :type => 'alias',
32
+ :value => value,
33
+ :parent => parent }
34
+ create params
35
+ end
36
+
37
+ #
38
+ # Helper shortcut to create a string child object.
39
+ #
40
+ def create_untyped( name, value, parent )
41
+ params = { :name => name,
42
+ :type => 'untyped',
43
+ :value => value,
44
+ :parent => parent }
45
+ create params
46
+ end
47
+
48
+ #
49
+ # Helper shortcut to create a string child object.
50
+ #
51
+ def create_string( name, value, parent )
52
+ params = { :name => name,
53
+ :type => 'string',
54
+ :value => value,
55
+ :parent => parent }
56
+ create params
57
+ end
58
+
59
+ #
60
+ # Helper shortcut to create a text child object.
61
+ #
62
+ def create_text( name, value, parent )
63
+ params = { :name => name,
64
+ :type => 'text',
65
+ :value => value,
66
+ :parent => parent }
67
+ create params
68
+ end
69
+
70
+ #
71
+ # Helper shortcut to create an integer child object.
72
+ #
73
+ def create_int( name, value, parent )
74
+ params = { :name => name,
75
+ :type => 'integer',
76
+ :value => value,
77
+ :parent => parent }
78
+ create params
79
+ end
80
+
81
+ #
82
+ # Helper shortcut to create a boolean child object.
83
+ #
84
+ def create_bool( name, value, parent )
85
+ params = { :name => name,
86
+ :type => 'boolean',
87
+ :value => value,
88
+ :parent => parent }
89
+ create params
90
+ end
91
+
92
+ #
93
+ # Helper shortcut to create a container child object.
94
+ #
95
+ def create_can( name, parent )
96
+ params = { :name => name,
97
+ :type => 'container',
98
+ :value => nil,
99
+ :parent => parent }
100
+ create params
101
+ end
102
+
103
+ #
104
+ # Helper shortcut to create a script child object.
105
+ #
106
+ def create_script( name, value, parent )
107
+ params = { :name => name,
108
+ :type => 'script',
109
+ :value => value,
110
+ :parent => parent }
111
+ create params
112
+ end
113
+
114
+ #
115
+ # Helper shortcut to create a file child object.
116
+ #
117
+ def create_file( name, value, parent )
118
+ params = { :name => name,
119
+ :type => 'file',
120
+ :value => value,
121
+ :parent => parent }
122
+ create params
123
+ end
124
+
125
+ # ---------------------------------------------------------------------
126
+ # Object Factory
127
+ # ---------------------------------------------------------------------
128
+
129
+ # Create object with given name, type and value.
130
+ # One of either name or type is required.
131
+ # All values are optional when considered on their own.
132
+ # Parameter hash keys:
133
+ # :name - the name of the object
134
+ # :type - the name of the type
135
+ # :value - the initial object value
136
+ # :parent - the parent object
137
+ # :squash_duplicates - if the object exists, use it rather
138
+ # than creating a new one? Default = true
139
+ def create( params )
140
+ objtype = find_type params[ :type ]
141
+ return nil unless objtype
142
+
143
+ pn = GlooLang::Core::Pn.new params[ :name ]
144
+ parent = params[ :parent ]
145
+ if parent.nil?
146
+ parent = pn.get_parent
147
+ obj_name = pn.name
148
+ else
149
+ obj_name = params[ :name ]
150
+ end
151
+
152
+ if pn.exists? && params[ :squash_duplicates ]
153
+ $log.debug "Updating existing object: #{obj_name}"
154
+ return self.update_existing pn, params[ :value ]
155
+ end
156
+
157
+ $log.debug "Creating new object: #{obj_name}"
158
+ return create_new obj_name, params[ :value ], objtype, parent
159
+ end
160
+
161
+ #
162
+ # Create a new object.
163
+ #
164
+ def create_new( name, value, type, parent )
165
+ unless parent
166
+ $log.error "Could not create object. Bad path: #{name}"
167
+ return nil
168
+ end
169
+
170
+ o = type.new
171
+ o.name = name
172
+ o.set_value value
173
+ parent.add_child( o )
174
+ return o
175
+ end
176
+
177
+ #
178
+ # Find and Update an existing object.
179
+ #
180
+ def update_existing( pn, value )
181
+ o = pn.resolve
182
+ o.set_value value
183
+ return o
184
+ end
185
+
186
+ #
187
+ # Find the object type by name.
188
+ # Return nil if the object type cannot be found or
189
+ # cannot be created.
190
+ #
191
+ def find_type( type_name )
192
+ type_name = 'untyped' if type_name.nil? || type_name.strip.empty?
193
+ t = $engine.dictionary.find_obj( type_name )
194
+
195
+ if t.nil?
196
+ $log.warn "Could not find type, '#{type_name}'"
197
+ return nil
198
+ end
199
+
200
+ unless t.can_create?
201
+ $log.error "'#{type_name}' cannot be created."
202
+ return nil
203
+ end
204
+
205
+ return t
206
+ end
207
+
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,266 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The System Object.
5
+ # A virtual Object: the system object can be used to access
6
+ # system level variables and functions. But it is not
7
+ # actually an object in the normal sense of the word.
8
+ #
9
+ require 'tty-platform'
10
+
11
+ module GlooLang
12
+ module Core
13
+ class GlooSystem < Obj
14
+
15
+ KEYWORD = 'gloo'.freeze
16
+ KEYWORD_SHORT = '$'.freeze
17
+
18
+ attr_reader :pn
19
+
20
+ # Set up the object.
21
+ def initialize( pn )
22
+ @pn = pn
23
+ end
24
+
25
+ #
26
+ # The name of the object type.
27
+ #
28
+ def self.typename
29
+ return KEYWORD
30
+ end
31
+
32
+ #
33
+ # The short name of the object type.
34
+ #
35
+ def self.short_typename
36
+ return KEYWORD_SHORT
37
+ end
38
+
39
+ #
40
+ # The object type, suitable for display.
41
+ #
42
+ def type_display
43
+ return self.class.typename
44
+ end
45
+
46
+ # Is this the root object?
47
+ def root?
48
+ return false
49
+ end
50
+
51
+ # Can this object be created?
52
+ # This is true by default and only false for some special cases
53
+ # such as the System object.
54
+ def self.can_create?
55
+ false
56
+ end
57
+
58
+ # ---------------------------------------------------------------------
59
+ # Value
60
+ # ---------------------------------------------------------------------
61
+
62
+ #
63
+ # Get the parameter.
64
+ #
65
+ def param
66
+ return nil unless @pn && @pn.segments.count > 1
67
+
68
+ return @pn.segments[ 1..-1 ].join( '_' )
69
+ end
70
+
71
+ #
72
+ # Get the system value.
73
+ #
74
+ def value
75
+ return dispatch param
76
+ end
77
+
78
+ #
79
+ # There is no value object in the system.
80
+ #
81
+ def set_value( new_value )
82
+ # overriding base functionality with dummy function
83
+ end
84
+
85
+ #
86
+ # Get the value for display purposes.
87
+ #
88
+ def value_display
89
+ return value
90
+ end
91
+
92
+ #
93
+ # Is the value a String?
94
+ #
95
+ def value_string?
96
+ return true
97
+ end
98
+
99
+ #
100
+ # Is the value an Array?
101
+ #
102
+ def value_is_array?
103
+ return false
104
+ end
105
+
106
+ #
107
+ # Is the value a blank string?
108
+ #
109
+ def value_is_blank?
110
+ return true
111
+ end
112
+
113
+ # ---------------------------------------------------------------------
114
+ # Children
115
+ # ---------------------------------------------------------------------
116
+
117
+ # Does this object have children to add when an object
118
+ # is created in interactive mode?
119
+ # This does not apply during obj load, etc.
120
+ def add_children_on_create?
121
+ return false
122
+ end
123
+
124
+ # ---------------------------------------------------------------------
125
+ # Messages
126
+ # ---------------------------------------------------------------------
127
+
128
+ #
129
+ # Get a list of message names that this object receives.
130
+ #
131
+ def self.messages
132
+ return []
133
+ end
134
+
135
+ # Dispatch the message and get the value.
136
+ def dispatch( msg )
137
+ o = "msg_#{msg}"
138
+ return self.public_send( o ) if self.respond_to? o
139
+
140
+ $log.error "Message #{msg} not implemented"
141
+ return false
142
+ end
143
+
144
+ # Get the system hostname.
145
+ def msg_hostname
146
+ return Socket.gethostname
147
+ end
148
+
149
+ # Get the logged in User.
150
+ def msg_user
151
+ return ENV[ 'USER' ]
152
+ end
153
+
154
+ # Get the user's home directory.
155
+ def msg_user_home
156
+ return File.expand_path( '~' )
157
+ end
158
+
159
+ # Get the working directory.
160
+ def msg_working_dir
161
+ return Dir.pwd
162
+ end
163
+
164
+ # Get the Gloo home directory
165
+ def msg_gloo_home
166
+ return $settings.user_root
167
+ end
168
+
169
+ # Get the Gloo configuration directory
170
+ def msg_gloo_config
171
+ return $settings.config_path
172
+ end
173
+
174
+ # Get the Gloo projects directory
175
+ def msg_gloo_projects
176
+ return $settings.project_path
177
+ end
178
+
179
+ # Get the Gloo log directory
180
+ def msg_gloo_log
181
+ return $settings.log_path
182
+ end
183
+
184
+ # ---------------------------------------------------------------------
185
+ # Special chars
186
+ # ---------------------------------------------------------------------
187
+
188
+ # Carriage return (line feed)
189
+ def msg_line
190
+ return "\n"
191
+ end
192
+
193
+ # ---------------------------------------------------------------------
194
+ # Screen Messages
195
+ # ---------------------------------------------------------------------
196
+
197
+ # Get the number of lines on screen.
198
+ def msg_screen_lines
199
+ return GlooLang::App::Settings.lines
200
+ end
201
+
202
+ # Get the number of columns on screen.
203
+ def msg_screen_cols
204
+ return GlooLang::App::Settings.cols
205
+ end
206
+
207
+ # ---------------------------------------------------------------------
208
+ # Platform Messages
209
+ # ---------------------------------------------------------------------
210
+
211
+ # Get the platform CPU
212
+ def msg_platform_cpu
213
+ platform = TTY::Platform.new
214
+ return platform.cpu
215
+ end
216
+
217
+ # Get the platform Operating System
218
+ def msg_platform_os
219
+ platform = TTY::Platform.new
220
+ return platform.os
221
+ end
222
+
223
+ # Get the platform version
224
+ def msg_platform_version
225
+ platform = TTY::Platform.new
226
+ return platform.version
227
+ end
228
+
229
+ # Is the platform Windows?
230
+ def msg_platform_windows?
231
+ platform = TTY::Platform.new
232
+ return platform.windows?
233
+ end
234
+
235
+ # Is the platform Unix?
236
+ def msg_platform_unix?
237
+ platform = TTY::Platform.new
238
+ return platform.unix?
239
+ end
240
+
241
+ # Is the platform Linux?
242
+ def msg_platform_linux?
243
+ platform = TTY::Platform.new
244
+ return platform.linux?
245
+ end
246
+
247
+ # Is the platform Mac?
248
+ def msg_platform_mac?
249
+ platform = TTY::Platform.new
250
+ return platform.mac?
251
+ end
252
+
253
+ #
254
+ # Get the command to open a file on this platform.
255
+ #
256
+ def self.open_for_platform
257
+ platform = TTY::Platform.new
258
+ return 'open' if platform.mac?
259
+ return 'xdg-open' if platform.linux?
260
+
261
+ return nil
262
+ end
263
+
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,52 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The Object Heap.
5
+ # The collection of objects that are currently in play in
6
+ # the running engine.
7
+ #
8
+
9
+ module GlooLang
10
+ module Core
11
+ class Heap
12
+
13
+ # The context is a reference to an object, usually a container.
14
+ # The context will be the root by default.
15
+ attr_reader :context
16
+
17
+ attr_reader :it, :root, :error
18
+
19
+ #
20
+ # Set up the object heap.
21
+ #
22
+ def initialize
23
+ $log.debug 'object heap intialized...'
24
+
25
+ @root = GlooLang::Objs::Container.new
26
+ @root.name = 'root'
27
+
28
+ @context = Pn.root
29
+ @it = It.new
30
+ @error = Error.new
31
+ end
32
+
33
+ #
34
+ # Unload the given obj--remove it from the heap.
35
+ #
36
+ def unload( obj )
37
+ can = obj.parent.nil? ? @root : obj.parent
38
+ return unless can
39
+
40
+ can.remove_child obj
41
+ end
42
+
43
+ #
44
+ # Is there one or more errors?
45
+ #
46
+ def error?
47
+ return @error.error_count.positive?
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,36 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Here helper class,
5
+ # used to resolve relative referencing.
6
+ #
7
+
8
+ module GlooLang
9
+ module Core
10
+ class Here
11
+
12
+ HERE = '^'.freeze
13
+
14
+ #
15
+ # Does the pathname start with here reference?
16
+ #
17
+ def self.includes_here_ref?( elements )
18
+ return elements.first.start_with?( HERE )
19
+ end
20
+
21
+ #
22
+ # Expand here reference if present.
23
+ #
24
+ def self.expand_here( pn )
25
+ target = $engine.exec_env.here_obj
26
+
27
+ here = pn.elements.first
28
+ remainder = pn.elements[ 1..-1 ].join( '.' )
29
+
30
+ here.length.times { target = target.parent }
31
+ pn.set_to "#{target.pn}.#{remainder}"
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # It is the value of the last command that was run.
5
+ #
6
+
7
+ module GlooLang
8
+ module Core
9
+ class It
10
+
11
+ attr_accessor :value
12
+
13
+ #
14
+ # Set up the object.
15
+ #
16
+ def initialize
17
+ @value = nil
18
+ end
19
+
20
+ #
21
+ # Set the value of it.
22
+ #
23
+ def set_to( new_value )
24
+ @value = new_value
25
+ end
26
+
27
+ #
28
+ # Get the string representation of it.
29
+ #
30
+ def to_s
31
+ return @value.to_s
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # A Literal value.
5
+ # Base class for all literal values.
6
+ #
7
+
8
+ module GlooLang
9
+ module Core
10
+ class Literal
11
+
12
+ attr_reader :value
13
+
14
+ #
15
+ # Create the expression from a list of tokens.
16
+ #
17
+ def initialize( value )
18
+ set_value( value )
19
+ end
20
+
21
+ #
22
+ # Set the literal value.
23
+ #
24
+ def set_value( value )
25
+ @value = value
26
+ end
27
+
28
+ end
29
+ end
30
+ end