eleetscript 0.0.17a → 0.0.18a
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.
- checksums.yaml +4 -4
- data/lib/lang/grammar.y +155 -150
- data/lib/lang/interpreter.rb +34 -6
- data/lib/lang/parser.output +8044 -7815
- data/lib/lang/parser.rb +779 -764
- data/lib/lang/runtime/class.rb +0 -4
- data/lib/lang/runtime/class_instance.rb +5 -2
- data/lib/lang/runtime/class_skeleton.rb +1 -1
- data/lib/lang/runtime/context.rb +8 -3
- data/lib/lang/runtime/eleetscript/random.es +57 -0
- data/lib/lang/runtime/memory.rb +2 -1
- data/lib/lang/runtime/ruby/float_methods.rb +23 -0
- data/lib/lang/runtime/ruby/integer_methods.rb +13 -0
- data/lib/lang/runtime/ruby/random_methods.rb +57 -0
- data/lib/lang/runtime/ruby/string_methods.rb +9 -1
- metadata +6 -2
data/lib/lang/runtime/class.rb
CHANGED
@@ -40,14 +40,17 @@ module EleetScript
|
|
40
40
|
to_s
|
41
41
|
end
|
42
42
|
|
43
|
-
def is_a?(
|
43
|
+
def is_a?(*values)
|
44
44
|
names = ["Object", runtime_class.name]
|
45
45
|
cur_class = runtime_class
|
46
46
|
while cur_class.super_class.name != "Object"
|
47
47
|
names << cur_class.super_class.name
|
48
48
|
cur_class = cur_class.super_class
|
49
49
|
end
|
50
|
-
|
50
|
+
values.each do |value|
|
51
|
+
return true if names.include?(value)
|
52
|
+
end
|
53
|
+
false
|
51
54
|
end
|
52
55
|
|
53
56
|
def class_name
|
data/lib/lang/runtime/context.rb
CHANGED
@@ -6,10 +6,11 @@ module EleetScript
|
|
6
6
|
attr_accessor :current_self, :current_class
|
7
7
|
|
8
8
|
class << self
|
9
|
-
|
9
|
+
attr_reader :init_funcs
|
10
10
|
|
11
11
|
def init_with(*func_symbols)
|
12
|
-
|
12
|
+
(@init_funcs ||= [])
|
13
|
+
@init_funcs += func_symbols
|
13
14
|
end
|
14
15
|
|
15
16
|
def init_funcs
|
@@ -58,6 +59,10 @@ module EleetScript
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
62
|
+
def local_constant(name)
|
63
|
+
constants[name] || es_nil
|
64
|
+
end
|
65
|
+
|
61
66
|
def [](key)
|
62
67
|
store = fetch_var_store(key)
|
63
68
|
if store[key]
|
@@ -196,7 +201,7 @@ module EleetScript
|
|
196
201
|
private
|
197
202
|
|
198
203
|
def init_namespace(root = nil)
|
199
|
-
if
|
204
|
+
if root.nil?
|
200
205
|
@root_ns = self
|
201
206
|
@global_vars = ProcessedKeyHash.new
|
202
207
|
@global_vars.set_key_preprocessor do |key|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Random
|
2
|
+
@@d4 do
|
3
|
+
int(1, 4)
|
4
|
+
end
|
5
|
+
|
6
|
+
@@d6 do
|
7
|
+
int(1, 6)
|
8
|
+
end
|
9
|
+
|
10
|
+
@@d8 do
|
11
|
+
int(1, 8)
|
12
|
+
end
|
13
|
+
|
14
|
+
@@d10 do
|
15
|
+
int(1, 10)
|
16
|
+
end
|
17
|
+
|
18
|
+
@@d12 do
|
19
|
+
int(1, 12)
|
20
|
+
end
|
21
|
+
|
22
|
+
@@d20 do
|
23
|
+
int(1, 20)
|
24
|
+
end
|
25
|
+
|
26
|
+
@@d100 do
|
27
|
+
int
|
28
|
+
end
|
29
|
+
|
30
|
+
d4 do
|
31
|
+
int(1, 4)
|
32
|
+
end
|
33
|
+
|
34
|
+
d6 do
|
35
|
+
int(1, 6)
|
36
|
+
end
|
37
|
+
|
38
|
+
d8 do
|
39
|
+
int(1, 8)
|
40
|
+
end
|
41
|
+
|
42
|
+
d10 do
|
43
|
+
int(1, 10)
|
44
|
+
end
|
45
|
+
|
46
|
+
d12 do
|
47
|
+
int(1, 12)
|
48
|
+
end
|
49
|
+
|
50
|
+
d20 do
|
51
|
+
int(1, 20)
|
52
|
+
end
|
53
|
+
|
54
|
+
d100 do
|
55
|
+
int
|
56
|
+
end
|
57
|
+
end
|
data/lib/lang/runtime/memory.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module EleetScript
|
2
|
+
Memory.define_core_methods do
|
3
|
+
float = root_namespace["Float"]
|
4
|
+
|
5
|
+
float.def :to_float do |receiver, _|
|
6
|
+
receiver
|
7
|
+
end
|
8
|
+
|
9
|
+
float.def :to_integer do |receiver, _, context|
|
10
|
+
root_namespace["Integer"].new_with_value(receiver.ruby_value.to_i, context.namespace_context)
|
11
|
+
end
|
12
|
+
|
13
|
+
float.def :round do |receiver, arguments, context|
|
14
|
+
if arguments.length == 0
|
15
|
+
root_namespace["Integer"].new_with_value(receiver.ruby_value.round, context.namespace_context)
|
16
|
+
elsif arguments.length >= 1 && arguments.first.is_a?("String", "Number")
|
17
|
+
root_namespace["Float"].new_with_value(receiver.ruby_value.round(arguments.first.calL(:to_integer).ruby_value), context.namespace_context)
|
18
|
+
else
|
19
|
+
root_namespace["nil"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module EleetScript
|
2
|
+
Memory.define_core_methods do
|
3
|
+
integer = root_namespace["Integer"]
|
4
|
+
|
5
|
+
integer.def :to_float do |receiver, _, context|
|
6
|
+
root_namespace["Float"].new_with_value(receiver.ruby_value.to_f, context.namespace_context)
|
7
|
+
end
|
8
|
+
|
9
|
+
integer.def :to_integer do |receiver, _, context|
|
10
|
+
receiver
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module EleetScript
|
2
|
+
Memory.define_core_methods do
|
3
|
+
random = root_namespace["Random"]
|
4
|
+
|
5
|
+
random.class_def :int do |_, arguments, context|
|
6
|
+
min, max = 1, 100
|
7
|
+
if arguments.length == 1 && arguments.first.is_a?("String", "Number")
|
8
|
+
min, max = 0, arguments.first.call(:to_integer).ruby_value
|
9
|
+
elsif arguments.length >= 2 && arguments.first.is_a?("String", "Number") && arguments[1].is_a?("String", "Number")
|
10
|
+
min, max = arguments.first.call(:to_integer).ruby_value, arguments[1].call(:to_integer).ruby_value
|
11
|
+
end
|
12
|
+
root_namespace["Integer"].new_with_value(rand(max - min) + min, context.namespace_context)
|
13
|
+
end
|
14
|
+
|
15
|
+
random.class_def :float do |_, _, context|
|
16
|
+
root_namespace["Float"].new_with_value(rand, context.namespace_context)
|
17
|
+
end
|
18
|
+
|
19
|
+
random.class_def :bool do |_, _, context|
|
20
|
+
t, f = root_namespace["True"], root_namespace["False"]
|
21
|
+
if rand > 0.5
|
22
|
+
t
|
23
|
+
else
|
24
|
+
f
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
random.class_def :new do |receiver, arguments, context|
|
29
|
+
first_arg = arguments.first
|
30
|
+
seed = first_arg.is_a?("String", "Number") ? first_arg.call(:to_integer).ruby_value : nil
|
31
|
+
random.new_with_value(Random.new(seed), context.namespace_context)
|
32
|
+
end
|
33
|
+
|
34
|
+
random.def :int do |receiver, arguments, context|
|
35
|
+
min, max = 1, 100
|
36
|
+
if arguments.length == 1 && arguments.first.is_a?("String", "Number")
|
37
|
+
min, max = 0, arguments.first.call(:to_integer).ruby_value
|
38
|
+
elsif arguments.length >= 2 && arguments.first.is_a?("String", "Number") && arguments[1].is_a?("String", "Number")
|
39
|
+
min, max = arguments.first.call(:to_integer).ruby_value, arguments[1].call(:to_integer).ruby_value
|
40
|
+
end
|
41
|
+
root_namespace["Integer"].new_with_value(receiver.ruby_value.rand(max - min) + min, context.namespace_context)
|
42
|
+
end
|
43
|
+
|
44
|
+
random.def :float do |receiver, _, context|
|
45
|
+
root_namespace["Float"].new_with_value(receiver.ruby_value.rand, context.namespace_context)
|
46
|
+
end
|
47
|
+
|
48
|
+
random.def :bool do |receiver, _, context|
|
49
|
+
t, f = root_namespace["True"], root_namespace["False"]
|
50
|
+
if receiver.ruby_value.rand > 0.5
|
51
|
+
t
|
52
|
+
else
|
53
|
+
f
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -90,7 +90,15 @@ module EleetScript
|
|
90
90
|
end
|
91
91
|
|
92
92
|
string.def :to_symbol do |receiver, arguments, context|
|
93
|
-
root_namespace["Symbol"].new_with_value(receiver.ruby_value.to_sym, context.namespace_context)
|
93
|
+
root_namespace["Symbol"].new_with_value(receiver.ruby_value.gsub(/\s+/, "_").to_sym, context.namespace_context)
|
94
|
+
end
|
95
|
+
|
96
|
+
string.def :to_integer do |receiver, arguments, context|
|
97
|
+
root_namespace["Integer"].new_with_value(receiver.ruby_value.to_i, context.namespace_context)
|
98
|
+
end
|
99
|
+
|
100
|
+
string.def :to_float do |receiver, arguments, context|
|
101
|
+
root_namespace["Float"].new_with_value(receiver.ruby_value.to_f, context.namespace_context)
|
94
102
|
end
|
95
103
|
|
96
104
|
string.def :replace do |receiver, arguments, context|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eleetscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18a
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Buck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: EleetScript scripting engine for use in Ruby applications
|
14
14
|
email: lordizuriel@gmail.com
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/lang/runtime/eleetscript/object.es
|
48
48
|
- lib/lang/runtime/eleetscript/pair.es
|
49
49
|
- lib/lang/runtime/eleetscript/que.es
|
50
|
+
- lib/lang/runtime/eleetscript/random.es
|
50
51
|
- lib/lang/runtime/eleetscript/regex.es
|
51
52
|
- lib/lang/runtime/eleetscript/stack.es
|
52
53
|
- lib/lang/runtime/eleetscript/string.es
|
@@ -56,12 +57,15 @@ files:
|
|
56
57
|
- lib/lang/runtime/method.rb
|
57
58
|
- lib/lang/runtime/method_hash.rb
|
58
59
|
- lib/lang/runtime/ruby/boolean_methods.rb
|
60
|
+
- lib/lang/runtime/ruby/float_methods.rb
|
61
|
+
- lib/lang/runtime/ruby/integer_methods.rb
|
59
62
|
- lib/lang/runtime/ruby/io_methods.rb
|
60
63
|
- lib/lang/runtime/ruby/lambda_methods.rb
|
61
64
|
- lib/lang/runtime/ruby/list_methods.rb
|
62
65
|
- lib/lang/runtime/ruby/nil_methods.rb
|
63
66
|
- lib/lang/runtime/ruby/number_methods.rb
|
64
67
|
- lib/lang/runtime/ruby/object_methods.rb
|
68
|
+
- lib/lang/runtime/ruby/random_methods.rb
|
65
69
|
- lib/lang/runtime/ruby/regex_methods.rb
|
66
70
|
- lib/lang/runtime/ruby/string_methods.rb
|
67
71
|
- lib/lang/runtime/ruby/symbol_methods.rb
|