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.
- checksums.yaml +4 -4
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +2 -2
- data/lib/{gloo_lang.rb → gloo-lang.rb} +7 -9
- data/lib/gloo_lang/app/args.rb +112 -0
- data/lib/gloo_lang/app/engine.rb +230 -0
- data/lib/gloo_lang/app/help.rb +156 -0
- data/lib/gloo_lang/app/log.rb +81 -0
- data/lib/gloo_lang/app/mode.rb +27 -0
- data/lib/gloo_lang/app/settings.rb +186 -0
- data/lib/gloo_lang/convert/converter.rb +35 -0
- data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
- data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
- data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
- data/lib/gloo_lang/core/baseo.rb +30 -0
- data/lib/gloo_lang/core/dictionary.rb +181 -0
- data/lib/gloo_lang/core/error.rb +61 -0
- data/lib/gloo_lang/core/event_manager.rb +44 -0
- data/lib/gloo_lang/core/factory.rb +210 -0
- data/lib/gloo_lang/core/gloo_system.rb +266 -0
- data/lib/gloo_lang/core/heap.rb +52 -0
- data/lib/gloo_lang/core/here.rb +36 -0
- data/lib/gloo_lang/core/it.rb +36 -0
- data/lib/gloo_lang/core/literal.rb +30 -0
- data/lib/gloo_lang/core/obj.rb +303 -0
- data/lib/gloo_lang/core/obj_finder.rb +30 -0
- data/lib/gloo_lang/core/op.rb +40 -0
- data/lib/gloo_lang/core/parser.rb +59 -0
- data/lib/gloo_lang/core/pn.rb +188 -0
- data/lib/gloo_lang/core/tokens.rb +165 -0
- data/lib/gloo_lang/core/verb.rb +86 -0
- data/lib/gloo_lang/exec/action.rb +48 -0
- data/lib/gloo_lang/exec/dispatch.rb +40 -0
- data/lib/gloo_lang/exec/exec_env.rb +74 -0
- data/lib/gloo_lang/exec/runner.rb +45 -0
- data/lib/gloo_lang/exec/script.rb +49 -0
- data/lib/gloo_lang/exec/stack.rb +78 -0
- data/lib/gloo_lang/expr/expression.rb +118 -0
- data/lib/gloo_lang/expr/l_boolean.rb +36 -0
- data/lib/gloo_lang/expr/l_decimal.rb +39 -0
- data/lib/gloo_lang/expr/l_integer.rb +37 -0
- data/lib/gloo_lang/expr/l_string.rb +58 -0
- data/lib/gloo_lang/expr/op_div.rb +22 -0
- data/lib/gloo_lang/expr/op_minus.rb +22 -0
- data/lib/gloo_lang/expr/op_mult.rb +22 -0
- data/lib/gloo_lang/expr/op_plus.rb +24 -0
- data/lib/gloo_lang/help/app/application.txt +22 -0
- data/lib/gloo_lang/help/app/configuration.txt +7 -0
- data/lib/gloo_lang/help/app/default_help.txt +14 -0
- data/lib/gloo_lang/help/app/logging.txt +16 -0
- data/lib/gloo_lang/help/core/color.txt +31 -0
- data/lib/gloo_lang/help/core/error.txt +33 -0
- data/lib/gloo_lang/help/core/events.txt +21 -0
- data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
- data/lib/gloo_lang/help/core/here.txt +30 -0
- data/lib/gloo_lang/help/core/it.txt +23 -0
- data/lib/gloo_lang/help/core/ops.txt +16 -0
- data/lib/gloo_lang/help/core/pathname.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
- data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
- data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
- data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
- data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
- data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
- data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
- data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
- data/lib/gloo_lang/help/objs/data/query.txt +37 -0
- data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
- data/lib/gloo_lang/help/objs/data/table.txt +46 -0
- data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
- data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
- data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
- data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
- data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
- data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
- data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
- data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
- data/lib/gloo_lang/help/objs/system/file.txt +48 -0
- data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
- data/lib/gloo_lang/help/objs/system/system.txt +32 -0
- data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
- data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
- data/lib/gloo_lang/help/objs/web/json.txt +34 -0
- data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
- data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
- data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
- data/lib/gloo_lang/help/verbs/alert.txt +33 -0
- data/lib/gloo_lang/help/verbs/beep.txt +25 -0
- data/lib/gloo_lang/help/verbs/cls.txt +24 -0
- data/lib/gloo_lang/help/verbs/context.txt +43 -0
- data/lib/gloo_lang/help/verbs/create.txt +33 -0
- data/lib/gloo_lang/help/verbs/execute.txt +27 -0
- data/lib/gloo_lang/help/verbs/help.txt +34 -0
- data/lib/gloo_lang/help/verbs/if.txt +37 -0
- data/lib/gloo_lang/help/verbs/list.txt +34 -0
- data/lib/gloo_lang/help/verbs/load.txt +38 -0
- data/lib/gloo_lang/help/verbs/move.txt +42 -0
- data/lib/gloo_lang/help/verbs/put.txt +38 -0
- data/lib/gloo_lang/help/verbs/quit.txt +25 -0
- data/lib/gloo_lang/help/verbs/run.txt +41 -0
- data/lib/gloo_lang/help/verbs/save.txt +26 -0
- data/lib/gloo_lang/help/verbs/show.txt +30 -0
- data/lib/gloo_lang/help/verbs/tell.txt +34 -0
- data/lib/gloo_lang/help/verbs/unless.txt +38 -0
- data/lib/gloo_lang/help/verbs/version.txt +32 -0
- data/lib/gloo_lang/help/verbs/wait.txt +29 -0
- data/lib/gloo_lang/objs/basic/alias.rb +78 -0
- data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
- data/lib/gloo_lang/objs/basic/container.rb +76 -0
- data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
- data/lib/gloo_lang/objs/basic/integer.rb +73 -0
- data/lib/gloo_lang/objs/basic/script.rb +99 -0
- data/lib/gloo_lang/objs/basic/string.rb +77 -0
- data/lib/gloo_lang/objs/basic/text.rb +87 -0
- data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
- data/lib/gloo_lang/objs/cli/banner.rb +108 -0
- data/lib/gloo_lang/objs/cli/bar.rb +133 -0
- data/lib/gloo_lang/objs/cli/colorize.rb +73 -0
- data/lib/gloo_lang/objs/cli/confirm.rb +96 -0
- data/lib/gloo_lang/objs/cli/menu.rb +206 -0
- data/lib/gloo_lang/objs/cli/menu_item.rb +95 -0
- data/lib/gloo_lang/objs/cli/pastel.rb +97 -0
- data/lib/gloo_lang/objs/cli/prompt.rb +110 -0
- data/lib/gloo_lang/objs/cli/select.rb +126 -0
- data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
- data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
- data/lib/gloo_lang/objs/data/markdown.rb +84 -0
- data/lib/gloo_lang/objs/data/mysql.rb +192 -0
- data/lib/gloo_lang/objs/data/query.rb +176 -0
- data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
- data/lib/gloo_lang/objs/data/table.rb +140 -0
- data/lib/gloo_lang/objs/dev/git.rb +140 -0
- data/lib/gloo_lang/objs/dev/stats.rb +120 -0
- data/lib/gloo_lang/objs/dt/date.rb +50 -0
- data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
- data/lib/gloo_lang/objs/dt/time.rb +50 -0
- data/lib/gloo_lang/objs/ror/erb.rb +116 -0
- data/lib/gloo_lang/objs/ror/eval.rb +107 -0
- data/lib/gloo_lang/objs/snd/play.rb +48 -0
- data/lib/gloo_lang/objs/snd/say.rb +98 -0
- data/lib/gloo_lang/objs/system/file_handle.rb +138 -0
- data/lib/gloo_lang/objs/system/ssh_exec.rb +126 -0
- data/lib/gloo_lang/objs/system/system.rb +136 -0
- data/lib/gloo_lang/objs/web/http_get.rb +159 -0
- data/lib/gloo_lang/objs/web/http_post.rb +183 -0
- data/lib/gloo_lang/objs/web/json.rb +135 -0
- data/lib/gloo_lang/objs/web/slack.rb +130 -0
- data/lib/gloo_lang/objs/web/teams.rb +117 -0
- data/lib/gloo_lang/objs/web/uri.rb +148 -0
- data/lib/gloo_lang/persist/file_loader.rb +191 -0
- data/lib/gloo_lang/persist/file_saver.rb +49 -0
- data/lib/gloo_lang/persist/file_storage.rb +45 -0
- data/lib/gloo_lang/persist/line_splitter.rb +81 -0
- data/lib/gloo_lang/persist/persist_man.rb +120 -0
- data/lib/gloo_lang/utils/format.rb +21 -0
- data/lib/gloo_lang/utils/stats.rb +205 -0
- data/lib/gloo_lang/utils/words.rb +19 -0
- data/lib/gloo_lang/verbs/alert.rb +79 -0
- data/lib/gloo_lang/verbs/beep.rb +40 -0
- data/lib/gloo_lang/verbs/cls.rb +37 -0
- data/lib/gloo_lang/verbs/context.rb +62 -0
- data/lib/gloo_lang/verbs/create.rb +68 -0
- data/lib/gloo_lang/verbs/execute.rb +56 -0
- data/lib/gloo_lang/verbs/help.rb +264 -0
- data/lib/gloo_lang/verbs/if.rb +92 -0
- data/lib/gloo_lang/verbs/list.rb +98 -0
- data/lib/gloo_lang/verbs/load.rb +45 -0
- data/lib/gloo_lang/verbs/move.rb +89 -0
- data/lib/gloo_lang/verbs/put.rb +94 -0
- data/lib/gloo_lang/verbs/quit.rb +40 -0
- data/lib/gloo_lang/verbs/run.rb +75 -0
- data/lib/gloo_lang/verbs/save.rb +39 -0
- data/lib/gloo_lang/verbs/show.rb +64 -0
- data/lib/gloo_lang/verbs/tell.rb +79 -0
- data/lib/gloo_lang/verbs/unless.rb +92 -0
- data/lib/gloo_lang/verbs/version.rb +37 -0
- data/lib/gloo_lang/verbs/wait.rb +42 -0
- metadata +191 -3
@@ -0,0 +1,148 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A URI (URL).
|
5
|
+
#
|
6
|
+
require 'uri'
|
7
|
+
require 'net/http'
|
8
|
+
require 'openssl'
|
9
|
+
|
10
|
+
module GlooLang
|
11
|
+
module Objs
|
12
|
+
class Uri < GlooLang::Core::Obj
|
13
|
+
|
14
|
+
KEYWORD = 'uri'.freeze
|
15
|
+
KEYWORD_SHORT = 'url'.freeze
|
16
|
+
|
17
|
+
#
|
18
|
+
# The name of the object type.
|
19
|
+
#
|
20
|
+
def self.typename
|
21
|
+
return KEYWORD
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# The short name of the object type.
|
26
|
+
#
|
27
|
+
def self.short_typename
|
28
|
+
return KEYWORD_SHORT
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Set the value with any necessary type conversions.
|
33
|
+
#
|
34
|
+
def set_value( new_value )
|
35
|
+
self.value = new_value.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Does this object support multi-line values?
|
40
|
+
# Initially only true for scripts.
|
41
|
+
#
|
42
|
+
def multiline_value?
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
# ---------------------------------------------------------------------
|
47
|
+
# Messages
|
48
|
+
# ---------------------------------------------------------------------
|
49
|
+
|
50
|
+
#
|
51
|
+
# Get a list of message names that this object receives.
|
52
|
+
#
|
53
|
+
def self.messages
|
54
|
+
basic = %w[open]
|
55
|
+
gets = %w[get_scheme get_host get_path]
|
56
|
+
more = %w[get_query get_fragment get_cert_expires]
|
57
|
+
return super + basic + gets + more
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Get the expiration date for the certificate.
|
62
|
+
#
|
63
|
+
def msg_get_cert_expires
|
64
|
+
return unless value
|
65
|
+
o = value
|
66
|
+
uri = URI( value )
|
67
|
+
response = Net::HTTP.start( uri.host, uri.port, :use_ssl => true )
|
68
|
+
cert = response.peer_cert
|
69
|
+
o = cert.not_after
|
70
|
+
|
71
|
+
$engine.heap.it.set_to o
|
72
|
+
return o
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Get the URI fragment that comes after the '#'
|
77
|
+
# in the URL. Might be used to scroll down in the page.
|
78
|
+
#
|
79
|
+
def msg_get_fragment
|
80
|
+
return unless value
|
81
|
+
|
82
|
+
o = URI( value ).fragment
|
83
|
+
$engine.heap.it.set_to o
|
84
|
+
return o
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Get the URI query parameters.
|
89
|
+
# Example: id=121
|
90
|
+
#
|
91
|
+
def msg_get_query
|
92
|
+
return unless value
|
93
|
+
|
94
|
+
o = URI( value ).query
|
95
|
+
$engine.heap.it.set_to o
|
96
|
+
return o
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Get the URI path.
|
101
|
+
# Example: /posts
|
102
|
+
#
|
103
|
+
def msg_get_path
|
104
|
+
return unless value
|
105
|
+
|
106
|
+
o = URI( value ).path
|
107
|
+
$engine.heap.it.set_to o
|
108
|
+
return o
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Get the URI host.
|
113
|
+
# Example: google.com
|
114
|
+
#
|
115
|
+
def msg_get_host
|
116
|
+
return unless value
|
117
|
+
|
118
|
+
o = URI( value ).host
|
119
|
+
$engine.heap.it.set_to o
|
120
|
+
return o
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Get the URI Scheme.
|
125
|
+
# Example: http
|
126
|
+
#
|
127
|
+
def msg_get_scheme
|
128
|
+
return unless value
|
129
|
+
|
130
|
+
o = URI( value ).scheme
|
131
|
+
$engine.heap.it.set_to o
|
132
|
+
return o
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# Open the URI in the default browser.
|
137
|
+
#
|
138
|
+
def msg_open
|
139
|
+
return unless value
|
140
|
+
|
141
|
+
cmd = GlooLang::Core::GlooSystem.open_for_platform
|
142
|
+
cmd_with_param = "#{cmd} \"#{value}\""
|
143
|
+
`#{cmd_with_param}`
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Helper class used to load a file and create objects in the heap.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Persist
|
9
|
+
class FileLoader
|
10
|
+
|
11
|
+
BEGIN_BLOCK = 'BEGIN'.freeze
|
12
|
+
END_BLOCK = 'END'.freeze
|
13
|
+
SPACE_CNT = 2
|
14
|
+
|
15
|
+
attr_reader :obj
|
16
|
+
|
17
|
+
#
|
18
|
+
# Set up a file storage for an object.
|
19
|
+
#
|
20
|
+
def initialize( pn )
|
21
|
+
@pn = pn
|
22
|
+
@tabs = 0
|
23
|
+
@obj = nil
|
24
|
+
@in_multiline = false
|
25
|
+
@exiting_multiline = false
|
26
|
+
@in_block = false
|
27
|
+
@block_value = ''
|
28
|
+
@debug = false
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Load the objects from the file.
|
33
|
+
#
|
34
|
+
def load
|
35
|
+
unless File.exist?( @pn )
|
36
|
+
$log.error "File '#{@pn}' does not exist."
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
$log.debug "Loading file '#{@pn}'"
|
41
|
+
@tabs = 0
|
42
|
+
@parent_stack = []
|
43
|
+
@parent = $engine.heap.root
|
44
|
+
@parent_stack.push @parent
|
45
|
+
f = File.open( @pn, 'r' )
|
46
|
+
f.each_line do |line|
|
47
|
+
next if skip_line? line
|
48
|
+
|
49
|
+
handle_one_line line
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Process one one of the file we're loading.
|
55
|
+
#
|
56
|
+
def handle_one_line( line )
|
57
|
+
if line.strip.end_with? BEGIN_BLOCK
|
58
|
+
@in_block = true
|
59
|
+
@save_line = line
|
60
|
+
elsif @in_block
|
61
|
+
if line.strip == END_BLOCK
|
62
|
+
@in_block = false
|
63
|
+
determine_indent @save_line
|
64
|
+
process_line @save_line
|
65
|
+
else
|
66
|
+
@block_value << line
|
67
|
+
end
|
68
|
+
else
|
69
|
+
determine_indent line
|
70
|
+
process_line line
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Is this line a comment or a blank line?
|
76
|
+
# If so we'll skip it.
|
77
|
+
#
|
78
|
+
def skip_line?( line )
|
79
|
+
line = line.strip
|
80
|
+
return true if line.empty?
|
81
|
+
return true if line[ 0 ] == '#'
|
82
|
+
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Determine the relative indent level for the line.
|
88
|
+
#
|
89
|
+
def determine_indent( line )
|
90
|
+
tabs = tab_count( line )
|
91
|
+
@indent = 0 # same level as prior line
|
92
|
+
if tabs > @tabs # indent
|
93
|
+
# TODO: What if indent is more than one more level?
|
94
|
+
@tabs = tabs
|
95
|
+
@indent = 1
|
96
|
+
elsif tabs < @tabs # outdent
|
97
|
+
diff = @tabs - tabs
|
98
|
+
@tabs -= diff
|
99
|
+
@indent -= diff
|
100
|
+
end
|
101
|
+
puts "tabs: #{@tabs}, indent: #{@indent}, line: #{line}" if @debug
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Process one line and add objects.
|
106
|
+
#
|
107
|
+
def process_line( line )
|
108
|
+
# reset multiline unless we're actually indented
|
109
|
+
if @in_multiline && @multi_indent > @indent
|
110
|
+
puts "Done multiline mi: #{@multi_indent}, i: #{@indent}" if @debug
|
111
|
+
@in_multiline = false
|
112
|
+
@exiting_multiline = true
|
113
|
+
end
|
114
|
+
|
115
|
+
if @in_multiline
|
116
|
+
@last.add_line line
|
117
|
+
else
|
118
|
+
setup_process_obj_line
|
119
|
+
process_obj_line line
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Setup and get ready to process an object line.
|
125
|
+
#
|
126
|
+
def setup_process_obj_line
|
127
|
+
if @exiting_multiline
|
128
|
+
@exiting_multiline = false
|
129
|
+
@indent += 1
|
130
|
+
end
|
131
|
+
|
132
|
+
if @indent.positive?
|
133
|
+
@parent = @last
|
134
|
+
@parent_stack.push @parent
|
135
|
+
elsif @indent.negative?
|
136
|
+
@indent.abs.times do
|
137
|
+
@parent_stack.pop
|
138
|
+
@parent = @parent_stack.last
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# Process one line and add objects.
|
145
|
+
#
|
146
|
+
def process_obj_line( line )
|
147
|
+
name, type, value = split_line( line )
|
148
|
+
unless @block_value == ''
|
149
|
+
value = @block_value
|
150
|
+
@block_value = ''
|
151
|
+
end
|
152
|
+
params = { name: name, type: type, value: value, parent: @parent }
|
153
|
+
@last = $engine.factory.create( params )
|
154
|
+
|
155
|
+
if value.empty? && @last&.multiline_value?
|
156
|
+
@multi_indent = 0
|
157
|
+
@in_multiline = true
|
158
|
+
puts "*** Start multiline. multi_indent: #{@multi_indent}" if @debug
|
159
|
+
end
|
160
|
+
|
161
|
+
@obj = @last if @obj.nil?
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# Get the number of leading tabs.
|
166
|
+
#
|
167
|
+
def tab_count( line )
|
168
|
+
i = 0
|
169
|
+
|
170
|
+
if line[ i ] == ' '
|
171
|
+
i += 1 while line[ i ] == ' '
|
172
|
+
tab_equiv = ( i / SPACE_CNT ).to_i
|
173
|
+
puts "Found #{i} spaces => #{tab_equiv}" if @debug
|
174
|
+
return tab_equiv
|
175
|
+
end
|
176
|
+
|
177
|
+
i += 1 while line[ i ] == "\t"
|
178
|
+
return i
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# Split the line into 3 parts.
|
183
|
+
#
|
184
|
+
def split_line( line )
|
185
|
+
o = LineSplitter.new( line, @tabs )
|
186
|
+
return o.split
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
191
|
+
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
|
+
# Helper class used to save an object to a file..
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Persist
|
9
|
+
class FileSaver
|
10
|
+
|
11
|
+
#
|
12
|
+
# Set up a file storage for an object.
|
13
|
+
#
|
14
|
+
def initialize( pn, obj )
|
15
|
+
@pn = pn
|
16
|
+
@obj = obj
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Save the object to the file.
|
21
|
+
#
|
22
|
+
def save
|
23
|
+
data = get_obj( @obj )
|
24
|
+
File.write( @pn, data )
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Get string of tabs for indentation.
|
29
|
+
#
|
30
|
+
def tabs( indent = 0 )
|
31
|
+
return "\t" * indent
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Convert an object to textual representation.
|
36
|
+
# This is a recursive function.
|
37
|
+
#
|
38
|
+
def get_obj( obj, indent = 0 )
|
39
|
+
t = tabs( indent )
|
40
|
+
str = "#{t}#{obj.name} [#{obj.type_display}] : #{obj.value_display}\n"
|
41
|
+
obj.children.each do |child|
|
42
|
+
str << get_obj( child, indent + 1 )
|
43
|
+
end
|
44
|
+
return str
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Helper class takes an object and writes it to a file.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Persist
|
9
|
+
class FileStorage
|
10
|
+
|
11
|
+
attr_reader :obj, :pn
|
12
|
+
|
13
|
+
#
|
14
|
+
# Set up a file storage for an object.
|
15
|
+
#
|
16
|
+
def initialize( pn, obj = nil )
|
17
|
+
@obj = obj
|
18
|
+
@pn = pn
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Save the object to the file.
|
23
|
+
#
|
24
|
+
def save
|
25
|
+
fs = FileSaver.new @pn, @obj
|
26
|
+
fs.save
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Load the object from the file.
|
31
|
+
#
|
32
|
+
def load
|
33
|
+
fl = FileLoader.new @pn
|
34
|
+
fl.load
|
35
|
+
@obj = fl.obj
|
36
|
+
if @obj
|
37
|
+
$log.debug "Loaded object: #{@obj.name}"
|
38
|
+
else
|
39
|
+
$log.error "Error loading file at #{@pn}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Helper class used as part of file loading.
|
5
|
+
# It is responsible for splitting a line into components.
|
6
|
+
#
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Persist
|
10
|
+
class LineSplitter
|
11
|
+
|
12
|
+
BEGIN_BLOCK = 'BEGIN'.freeze
|
13
|
+
END_BLOCK = 'END'.freeze
|
14
|
+
|
15
|
+
attr_reader :obj
|
16
|
+
|
17
|
+
#
|
18
|
+
# Set up a line splitter
|
19
|
+
#
|
20
|
+
def initialize( line, tabs )
|
21
|
+
@line = line
|
22
|
+
@tabs = tabs
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Split the line into 3 parts.
|
27
|
+
#
|
28
|
+
def split
|
29
|
+
detect_name
|
30
|
+
detect_type
|
31
|
+
detect_value
|
32
|
+
|
33
|
+
return @name, @type, @value
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Detect the object name.
|
38
|
+
#
|
39
|
+
def detect_name
|
40
|
+
@line = @line.strip
|
41
|
+
@idx = @line.index( ' ' )
|
42
|
+
@name = @line[ 0..@idx - 1 ]
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Detect the object type.
|
47
|
+
#
|
48
|
+
def detect_type
|
49
|
+
@line = @line[ @idx + 1..-1 ]
|
50
|
+
@idx = @line.index( ' ' )
|
51
|
+
|
52
|
+
if @line[ 0 ] == ':'
|
53
|
+
@type = 'untyped'
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
@type = @line[ 0..( @idx ? @idx - 1 : -1 ) ]
|
58
|
+
@type = @type[ 1..-1 ] if @type[ 0 ] == '['
|
59
|
+
@type = @type[ 0..-2 ] if @type[ -1 ] == ']'
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Detect the object value.
|
64
|
+
# Use nil if there is no value specified.
|
65
|
+
#
|
66
|
+
def detect_value
|
67
|
+
if @idx
|
68
|
+
@value = @line[ @idx + 1..-1 ]
|
69
|
+
if @value[ 0..1 ] == ': '
|
70
|
+
@value = @value[ 2..-1 ]
|
71
|
+
elsif @value[ 0 ] == ':'
|
72
|
+
@value = @value[ 1..-1 ]
|
73
|
+
end
|
74
|
+
else
|
75
|
+
@value = nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# The persistance manager.
|
5
|
+
# Keeps a collection of object-file mappings, and then
|
6
|
+
# uses mappings to know how/where to save updated objects.
|
7
|
+
#
|
8
|
+
|
9
|
+
module GlooLang
|
10
|
+
module Persist
|
11
|
+
class PersistMan
|
12
|
+
|
13
|
+
attr_reader :maps
|
14
|
+
|
15
|
+
#
|
16
|
+
# Contructor for the persistence manager.
|
17
|
+
#
|
18
|
+
def initialize
|
19
|
+
@maps = []
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Save one object to the file.
|
24
|
+
#
|
25
|
+
def save( name = '' )
|
26
|
+
if name.nil? || name.strip.empty?
|
27
|
+
save_all
|
28
|
+
else
|
29
|
+
save_one name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Save one object to the file.
|
35
|
+
#
|
36
|
+
def save_all
|
37
|
+
@maps.each( &:save )
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Save one object to the file.
|
42
|
+
#
|
43
|
+
def save_one( name )
|
44
|
+
ref = GlooLang::Core::Pn.new name
|
45
|
+
obj = ref.resolve
|
46
|
+
pn = get_full_path_name name
|
47
|
+
fs = GlooLang::Persist::FileStorage.new( pn, obj )
|
48
|
+
fs.save
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Load the object from the file.
|
53
|
+
#
|
54
|
+
def load( name )
|
55
|
+
pns = get_full_path_names name
|
56
|
+
return unless pns
|
57
|
+
|
58
|
+
pns.each do |pn|
|
59
|
+
$log.debug "Load file(s) at: #{pn}"
|
60
|
+
fs = GlooLang::Persist::FileStorage.new( pn )
|
61
|
+
fs.load
|
62
|
+
@maps << fs
|
63
|
+
$engine.event_manager.on_load fs.obj
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Get the full path and name of the file.
|
69
|
+
#
|
70
|
+
def get_full_path_names( name )
|
71
|
+
return nil if name.strip.empty?
|
72
|
+
|
73
|
+
if name.strip[ -1 ] == '*'
|
74
|
+
pns = []
|
75
|
+
dir = File.join( $settings.project_path, name[ 0..-2 ] )
|
76
|
+
Dir.glob( "#{dir}*.gloo" ).each do |f|
|
77
|
+
pns << f
|
78
|
+
end
|
79
|
+
return pns
|
80
|
+
else
|
81
|
+
ext_path = File.expand_path( name )
|
82
|
+
return [ ext_path ] if self.gloo_file?( ext_path )
|
83
|
+
|
84
|
+
full_name = "#{name}#{file_ext}"
|
85
|
+
return [ File.join( $settings.project_path, full_name ) ]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Check to see if a given path name refers to a gloo object file.
|
91
|
+
#
|
92
|
+
def gloo_file?( name )
|
93
|
+
return false unless name
|
94
|
+
return false unless File.exist?( name )
|
95
|
+
return false unless File.file?( name )
|
96
|
+
return false unless name.end_with?( self.file_ext )
|
97
|
+
|
98
|
+
return true
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Get the default file extention.
|
103
|
+
#
|
104
|
+
def file_ext
|
105
|
+
return '.gloo'
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Print out all object - persistance mappings.
|
110
|
+
# This is a debugging tool.
|
111
|
+
#
|
112
|
+
def show_maps
|
113
|
+
@maps.each do |o|
|
114
|
+
puts " \t #{o.pn} \t #{o.obj.name}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Formatting utilities
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Utils
|
9
|
+
class Format
|
10
|
+
|
11
|
+
#
|
12
|
+
# Format number, adding comma separators.
|
13
|
+
# Ex: 1000 -> 1,000
|
14
|
+
#
|
15
|
+
def self.number( num )
|
16
|
+
return num.to_s.reverse.scan( /.{1,3}/ ).join( ',' ).reverse
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|