gloo 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +5 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +139 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/exe/gloo +4 -0
  13. data/exe/o +4 -0
  14. data/gloo.gemspec +38 -0
  15. data/lib/gloo.rb +19 -0
  16. data/lib/gloo/app/args.rb +71 -0
  17. data/lib/gloo/app/engine.rb +158 -0
  18. data/lib/gloo/app/help.rb +29 -0
  19. data/lib/gloo/app/info.rb +21 -0
  20. data/lib/gloo/app/log.rb +58 -0
  21. data/lib/gloo/app/mode.rb +25 -0
  22. data/lib/gloo/app/settings.rb +125 -0
  23. data/lib/gloo/core/baseo.rb +28 -0
  24. data/lib/gloo/core/dictionary.rb +101 -0
  25. data/lib/gloo/core/event_manager.rb +46 -0
  26. data/lib/gloo/core/factory.rb +67 -0
  27. data/lib/gloo/core/gloo_system.rb +190 -0
  28. data/lib/gloo/core/heap.rb +42 -0
  29. data/lib/gloo/core/it.rb +30 -0
  30. data/lib/gloo/core/literal.rb +25 -0
  31. data/lib/gloo/core/obj.rb +222 -0
  32. data/lib/gloo/core/obj_finder.rb +35 -0
  33. data/lib/gloo/core/op.rb +33 -0
  34. data/lib/gloo/core/parser.rb +52 -0
  35. data/lib/gloo/core/pn.rb +134 -0
  36. data/lib/gloo/core/script.rb +37 -0
  37. data/lib/gloo/core/tokens.rb +123 -0
  38. data/lib/gloo/core/verb.rb +63 -0
  39. data/lib/gloo/expr/expression.rb +103 -0
  40. data/lib/gloo/expr/l_boolean.rb +29 -0
  41. data/lib/gloo/expr/l_integer.rb +29 -0
  42. data/lib/gloo/expr/l_string.rb +53 -0
  43. data/lib/gloo/expr/op_div.rb +20 -0
  44. data/lib/gloo/expr/op_minus.rb +20 -0
  45. data/lib/gloo/expr/op_mult.rb +20 -0
  46. data/lib/gloo/expr/op_plus.rb +22 -0
  47. data/lib/gloo/objs/basic/boolean.rb +113 -0
  48. data/lib/gloo/objs/basic/container.rb +50 -0
  49. data/lib/gloo/objs/basic/integer.rb +65 -0
  50. data/lib/gloo/objs/basic/script.rb +101 -0
  51. data/lib/gloo/objs/basic/string.rb +65 -0
  52. data/lib/gloo/objs/basic/text.rb +64 -0
  53. data/lib/gloo/objs/basic/untyped.rb +42 -0
  54. data/lib/gloo/objs/cli/colorize.rb +73 -0
  55. data/lib/gloo/objs/cli/confirm.rb +92 -0
  56. data/lib/gloo/objs/cli/prompt.rb +92 -0
  57. data/lib/gloo/objs/ctrl/each.rb +212 -0
  58. data/lib/gloo/objs/dev/git.rb +112 -0
  59. data/lib/gloo/objs/ror/erb.rb +109 -0
  60. data/lib/gloo/objs/ror/eval.rb +92 -0
  61. data/lib/gloo/objs/system/file_handle.rb +86 -0
  62. data/lib/gloo/objs/system/system.rb +120 -0
  63. data/lib/gloo/objs/web/http_get.rb +128 -0
  64. data/lib/gloo/objs/web/http_post.rb +127 -0
  65. data/lib/gloo/objs/web/slack.rb +126 -0
  66. data/lib/gloo/objs/web/teams.rb +117 -0
  67. data/lib/gloo/persist/file_loader.rb +171 -0
  68. data/lib/gloo/persist/file_saver.rb +43 -0
  69. data/lib/gloo/persist/file_storage.rb +43 -0
  70. data/lib/gloo/persist/persist_man.rb +90 -0
  71. data/lib/gloo/utils/words.rb +19 -0
  72. data/lib/gloo/verbs/alert.rb +42 -0
  73. data/lib/gloo/verbs/context.rb +52 -0
  74. data/lib/gloo/verbs/create.rb +52 -0
  75. data/lib/gloo/verbs/help.rb +69 -0
  76. data/lib/gloo/verbs/if.rb +56 -0
  77. data/lib/gloo/verbs/list.rb +85 -0
  78. data/lib/gloo/verbs/load.rb +39 -0
  79. data/lib/gloo/verbs/put.rb +62 -0
  80. data/lib/gloo/verbs/quit.rb +40 -0
  81. data/lib/gloo/verbs/run.rb +46 -0
  82. data/lib/gloo/verbs/save.rb +37 -0
  83. data/lib/gloo/verbs/show.rb +55 -0
  84. data/lib/gloo/verbs/tell.rb +47 -0
  85. data/lib/gloo/verbs/unless.rb +56 -0
  86. data/lib/gloo/verbs/version.rb +37 -0
  87. data/lib/run.rb +13 -0
  88. metadata +254 -0
@@ -0,0 +1,37 @@
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 Gloo
8
+ module Core
9
+ class Script
10
+
11
+ # Set up the script.
12
+ def initialize obj
13
+ @obj = obj
14
+ end
15
+
16
+
17
+ # Run the script.
18
+ def run
19
+ if @obj.value.is_a? String
20
+ run_line @obj.value
21
+ elsif @obj.value.is_a? Array
22
+ @obj.value.each do |line|
23
+ run_line line
24
+ end
25
+ end
26
+ end
27
+
28
+ # Run a single line of the script.
29
+ def run_line line
30
+ i = $engine.parser.parse_immediate line
31
+ return unless i
32
+ i.run
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,123 @@
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 Gloo
9
+ module Core
10
+ class Tokens
11
+
12
+ attr_reader :cmd, :tokens
13
+
14
+ # Set up the tokens.
15
+ def initialize( cmd_string )
16
+ @cmd = cmd_string
17
+ @tokens = []
18
+ tokenize @cmd
19
+ end
20
+
21
+ # Create a list of token from the given string.
22
+ def tokenize str
23
+ if str.index( '"' )
24
+ i = str.index( '"' )
25
+ j = str.index( '"', i+1 )
26
+ j = str.length unless j
27
+
28
+ tokenize( str[ 0..i-1 ] ) if i > 1
29
+ @tokens << str[ i..j ]
30
+ tokenize( str[ j+1..-1 ] ) if j+1 < str.length
31
+ elsif str.index( "'" )
32
+ i = str.index( "'" )
33
+ j = str.index( "'", i+1 )
34
+ j = str.length unless j
35
+
36
+ tokenize( str[ 0..i-1 ] ) if i > 1
37
+ @tokens << str[ i..j ]
38
+ tokenize( str[ j+1..-1 ] ) if j+1 < str.length
39
+ else
40
+ str.strip.split( " " ).each { |t| @tokens << t }
41
+ end
42
+ end
43
+
44
+ # Get the number of tokens
45
+ def token_count
46
+ return @tokens.size
47
+ end
48
+
49
+ # Get the verb (the first word)
50
+ def verb
51
+ return first
52
+ end
53
+
54
+ # Get all tokens except the first.
55
+ def params
56
+ return @tokens[ 1..-1 ]
57
+ end
58
+
59
+ # Get the first token.
60
+ def first
61
+ return @tokens.first if @tokens
62
+ end
63
+
64
+ # Get the last token.
65
+ def last
66
+ return @tokens.last if @tokens
67
+ end
68
+
69
+ # Get the second token.
70
+ def second
71
+ return @tokens[1] if @tokens && @tokens.size > 0
72
+ end
73
+
74
+ def at index
75
+ return @tokens[index] if @tokens && @tokens.size >= index
76
+ end
77
+
78
+ # Get the index of the given token.
79
+ def index_of token
80
+ return nil unless @tokens
81
+ return @tokens.find_index { |o| o.casecmp( token ) == 0 }
82
+ end
83
+
84
+ # Get the list of tokens after the given token
85
+ def tokens_after token
86
+ i = index_of token
87
+ if i && @tokens && @tokens.size > ( i+1 )
88
+ return @tokens[ i+1..-1 ]
89
+ end
90
+ return nil
91
+ end
92
+
93
+ # Get the expression after the given token
94
+ def expr_after token
95
+ str = ""
96
+ tokens_after( token ).each do |t|
97
+ str << " " if ( str.length > 0 )
98
+ str << "#{t}"
99
+ end
100
+ return str
101
+ end
102
+
103
+ # Get the item after a given token.
104
+ def after_token token
105
+ i = index_of token
106
+ if i && @tokens && @tokens.size > ( i+1 )
107
+ return @tokens[ i+1 ]
108
+ end
109
+ return nil
110
+ end
111
+
112
+ # Get the item after a given token.
113
+ def before_token token
114
+ i = index_of token
115
+ if i && @tokens && @tokens.size >= ( i )
116
+ return @tokens[ 0..i-1 ]
117
+ end
118
+ return nil
119
+ end
120
+
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,63 @@
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 Gloo
11
+ module Core
12
+ class Verb < Baseo
13
+
14
+ attr_reader :tokens, :params
15
+
16
+ # Set up the verb.
17
+ def initialize( tokens, params=[] )
18
+ @tokens = tokens
19
+ @params = params
20
+ end
21
+
22
+ # Register verbs when they are loaded.
23
+ def self.inherited( subclass )
24
+ Dictionary.instance.register_verb( subclass )
25
+ end
26
+
27
+ #
28
+ # Run the verb.
29
+ #
30
+ # We'll mark the application as not running and let the
31
+ # engine stop gracefully next time through the loop.
32
+ #
33
+ def run
34
+ raise 'this method should be overriden'
35
+ end
36
+
37
+ #
38
+ # Get the Verb's keyword.
39
+ #
40
+ # The keyword will be in lower case only.
41
+ # It is used by the parser.
42
+ #
43
+ def self.keyword
44
+ raise 'this method should be overriden'
45
+ end
46
+
47
+ #
48
+ # Get the Verb's keyword shortcut.
49
+ #
50
+ def self.keyword_shortcut
51
+ raise 'this method should be overriden'
52
+ end
53
+
54
+ #
55
+ # The object type, suitable for display.
56
+ #
57
+ def type_display
58
+ return self.class.keyword
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,103 @@
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 Gloo
8
+ module Expr
9
+ class Expression
10
+
11
+ # Create the expression from a list of tokens.
12
+ def initialize tokens
13
+ @tokens = tokens
14
+ @symbols = []
15
+ @left = nil
16
+ @right = nil
17
+ @op = nil
18
+ end
19
+
20
+ # Evaluate the expression and return the value.
21
+ def evaluate
22
+ identify_tokens
23
+
24
+ @symbols.each do |sym|
25
+ if sym.is_a? Gloo::Core::Op
26
+ @op = sym
27
+ elsif @left == nil
28
+ @left = sym
29
+ else
30
+ @right = sym
31
+ end
32
+
33
+ perform_op if @left && @right
34
+ end
35
+
36
+ if @left.is_a? Gloo::Core::Literal
37
+ return @left.value
38
+ elsif @left.is_a? Gloo::Core::Pn
39
+ return resolve_ref @left
40
+ else
41
+ return @left
42
+ end
43
+ end
44
+
45
+ # Perform the operation.
46
+ def perform_op
47
+ @op = Gloo::Core::Op.default_op unless @op
48
+ l = evaluate_sym @left
49
+ r = evaluate_sym @right
50
+ @left = @op.perform l, r
51
+ @right = nil
52
+ @op = nil
53
+ end
54
+
55
+ # Evaluate the symbol and get a simple value.
56
+ def evaluate_sym sym
57
+ if sym.is_a? Gloo::Core::Literal
58
+ return sym.value
59
+ elsif sym.is_a? Gloo::Core::Pn
60
+ return resolve_ref sym
61
+ else
62
+ return sym
63
+ end
64
+ end
65
+
66
+ # resolve an object reference and get the value.
67
+ def resolve_ref ref
68
+ return ref.src if ref.is_color?
69
+
70
+ ob = ref.resolve
71
+ return ob.value if ob
72
+ end
73
+
74
+ # Identify each token in the list.
75
+ def identify_tokens
76
+ @tokens.each do |o|
77
+ @symbols << identify_token( o )
78
+ end
79
+
80
+ # @symbols.each do |o|
81
+ # puts o.class.name
82
+ # end
83
+ end
84
+
85
+ #
86
+ # Identify the tokens and create appropriate symbols.
87
+ #
88
+ def identify_token token
89
+ if Gloo::Core::Op.is_op?( token )
90
+ return Gloo::Core::Op.create_op( token )
91
+ end
92
+
93
+ return LBoolean.new( token ) if LBoolean.is_boolean?( token )
94
+ return LInteger.new( token ) if LInteger.is_integer?( token )
95
+ return LString.new( token ) if LString.is_string?( token )
96
+
97
+ # last chance: an Object reference
98
+ return Gloo::Core::Pn.new( token )
99
+ end
100
+
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,29 @@
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 Gloo
8
+ module Expr
9
+ class LBoolean < Gloo::Core::Literal
10
+
11
+ # Is the given token a boolean?
12
+ def self.is_boolean? token
13
+ return Gloo::Objs::Boolean.is_boolean? token
14
+ end
15
+
16
+ # Set the value, converting to an boolean.
17
+ def set_value value
18
+ @value = Gloo::Objs::Boolean.coerse_to_bool value
19
+ end
20
+
21
+ # Get string representation
22
+ def to_s
23
+ return "false" unless @value
24
+ return @value.to_s
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
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 Gloo
8
+ module Expr
9
+ class LInteger < Gloo::Core::Literal
10
+
11
+ # Is the given token an integer?
12
+ def self.is_integer? token
13
+ return true if token.is_a? Integer
14
+ s = token.strip
15
+ return s.to_i.to_s == s
16
+ end
17
+
18
+ # Set the value, converting to an integer.
19
+ def set_value value
20
+ @value = value.to_i
21
+ end
22
+
23
+ def to_s
24
+ return self.value.to_s
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
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 Gloo
8
+ module Expr
9
+ class LString < Gloo::Core::Literal
10
+
11
+ # Set the value, triming opening and closing
12
+ # quotations if necessary.
13
+ def set_value value
14
+ @value = value
15
+ return unless value
16
+ @value = LString.strip_quotes( @value )
17
+ end
18
+
19
+ # Is the given token a string?
20
+ def self.is_string? token
21
+ return false unless token.is_a? String
22
+ return true if token.start_with?( '"' )
23
+ return true if token.start_with?( "'" )
24
+ return false
25
+ end
26
+
27
+ #
28
+ # Given a string with leading and trailing quotes,
29
+ # strip them out.
30
+ #
31
+ def self.strip_quotes str
32
+ if str.start_with?( '"' )
33
+ str = str[ 1..-1 ]
34
+ if str.end_with?( '"' )
35
+ str = str[ 0..-2 ]
36
+ end
37
+ return str
38
+ elsif str.start_with?( "'" )
39
+ str = str[ 1..-1 ]
40
+ if str.end_with?( "'" )
41
+ str = str[ 0..-2 ]
42
+ end
43
+ return str
44
+ end
45
+ end
46
+
47
+ def to_s
48
+ return self.value
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Division operator.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class OpDiv < Gloo::Core::Op
10
+
11
+ # Perform the operation and return the result.
12
+ def perform left, right
13
+ if left.is_a? Integer
14
+ return left / right.to_i
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end