eleetscript 0.0.12a → 0.0.13a
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/engine/engine.rb +7 -1
- data/lib/engine/ruby_to_eleet_wrapper.rb +1 -1
- data/lib/engine/values.rb +3 -1
- data/lib/lang/grammar.y +2 -1
- data/lib/lang/interpreter.rb +15 -9
- data/lib/lang/lexer.rb +4 -0
- data/lib/lang/nodes.rb +1 -0
- data/lib/lang/parser.rb +1142 -1123
- data/lib/lang/runtime/base_classes.rb +3 -2
- data/lib/lang/runtime/context.rb +9 -3
- data/lib/lang/runtime/eleetscript/object.es +4 -4
- data/lib/lang/runtime/eleetscript/symbol.es +5 -0
- data/lib/lang/runtime/memory.rb +7 -2
- data/lib/lang/runtime/ruby/list_methods.rb +27 -2
- data/lib/lang/runtime/ruby/string_methods.rb +4 -0
- data/lib/lang/runtime/ruby/symbol_methods.rb +26 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fc5d2a285f1c5be7ca29e652a4b778e75d10182
|
4
|
+
data.tar.gz: c49384478e2b92eea802bcb91ea7d57bae711f5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50925211b0865177514393bc13a642098177c2495cb432497c6c6d3387a6c38b0d3b61d004df9868ce476c32876c0c2d8edae84925770b55e1d6413b964bf9f4
|
7
|
+
data.tar.gz: 785b7bffb8338e1eceede4b9f283202adffee20a3239f48d26be4d35a00dfb07b34b6f24e39127cebf06e993914fb65c9b8e38d8bb36dcaf8662d27a157f02b0
|
data/lib/engine/engine.rb
CHANGED
@@ -122,10 +122,16 @@ module EleetScript
|
|
122
122
|
end
|
123
123
|
|
124
124
|
class SharedEngine < BaseEngine
|
125
|
+
class << self
|
126
|
+
def memory
|
127
|
+
@memory ||= Memory.new
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
125
131
|
def initialize; end
|
126
132
|
|
127
133
|
def memory
|
128
|
-
|
134
|
+
self.class.memory ||= Memory.new
|
129
135
|
end
|
130
136
|
|
131
137
|
def reset
|
data/lib/engine/values.rb
CHANGED
@@ -17,6 +17,8 @@ module EleetScript
|
|
17
17
|
ruby_obj.instance_variable_get("@eleet_obj")
|
18
18
|
elsif ruby_obj.kind_of?(String)
|
19
19
|
memory.root_namespace["String"].new_with_value(ruby_obj)
|
20
|
+
elsif ruby_obj.kind_of?(Symbol)
|
21
|
+
memory.root_namespace["Symbol"].new_with_value(ruby_obj)
|
20
22
|
elsif ruby_obj.kind_of?(Fixnum)
|
21
23
|
memory.root_namespace["Integer"].new_with_value(ruby_obj)
|
22
24
|
elsif ruby_obj.kind_of?(Float)
|
@@ -43,7 +45,7 @@ module EleetScript
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def to_ruby_value(eleet_obj, engine)
|
46
|
-
ruby_values = ["TrueClass", "FalseClass", "NilClass", "String", "Integer", "Float", "Regex"]
|
48
|
+
ruby_values = ["TrueClass", "FalseClass", "NilClass", "String", "Integer", "Float", "Regex", "Symbol"]
|
47
49
|
if eleet_obj.kind_of?(RubyToEleetWrapper)
|
48
50
|
eleet_obj.instance_variable_get("@ruby_obj")
|
49
51
|
elsif eleet_obj.class_name == "Lambda"
|
data/lib/lang/grammar.y
CHANGED
@@ -3,7 +3,7 @@ class Parser
|
|
3
3
|
token DO END CLASS LOAD IF WHILE NAMESPACE ELSE ELSIF RETURN BREAK NEXT TRUE
|
4
4
|
token YES ON FALSE NO OFF NIL SELF DEFINED PROPERTY RETURN
|
5
5
|
token CONSTANT GLOBAL CLASS_IDENTIFIER INSTANCE_IDENTIFIER IDENTIFIER
|
6
|
-
token FLOAT NUMBER STRING TERMINATOR EOF REGEX REGEX_FLAGS
|
6
|
+
token FLOAT NUMBER STRING TERMINATOR EOF REGEX REGEX_FLAGS SYMBOL
|
7
7
|
|
8
8
|
prechigh
|
9
9
|
left '.'
|
@@ -77,6 +77,7 @@ rule
|
|
77
77
|
| False { result = FalseNode.new }
|
78
78
|
| NIL { result = NilNode.new }
|
79
79
|
| Regex
|
80
|
+
| SYMBOL { result = SymbolNode.new(val[0]) }
|
80
81
|
;
|
81
82
|
|
82
83
|
Regex:
|
data/lib/lang/interpreter.rb
CHANGED
@@ -30,7 +30,7 @@ module EleetScript
|
|
30
30
|
|
31
31
|
module Helpers
|
32
32
|
def self.throw_eleet_error(context, error)
|
33
|
-
context["Errors"].call("<", [context["String"].new_with_value(error)])
|
33
|
+
context.root_ns["Errors"].call("<", [context.root_ns["String"].new_with_value(error)])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -124,7 +124,13 @@ module EleetScript
|
|
124
124
|
include Interpolatable
|
125
125
|
|
126
126
|
def eval(context)
|
127
|
-
context["String"].new_with_value(interpolate(value, context))
|
127
|
+
context.root_ns["String"].new_with_value(interpolate(value, context))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class SymbolNode
|
132
|
+
def eval(context)
|
133
|
+
context.root_ns["Symbol"].new_with_value(value)
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
@@ -133,19 +139,19 @@ module EleetScript
|
|
133
139
|
|
134
140
|
def eval(context)
|
135
141
|
f_arg = flags.length == 0 ? nil : flags
|
136
|
-
context["Regex"].new_with_value(ESRegex.new(interpolate(pattern, context), f_arg))
|
142
|
+
context.root_ns["Regex"].new_with_value(ESRegex.new(interpolate(pattern, context), f_arg))
|
137
143
|
end
|
138
144
|
end
|
139
145
|
|
140
146
|
class IntegerNode
|
141
147
|
def eval(context)
|
142
|
-
context["Integer"].new_with_value(value)
|
148
|
+
context.root_ns["Integer"].new_with_value(value)
|
143
149
|
end
|
144
150
|
end
|
145
151
|
|
146
152
|
class FloatNode
|
147
153
|
def eval(context)
|
148
|
-
context["Float"].new_with_value(value)
|
154
|
+
context.root_ns["Float"].new_with_value(value)
|
149
155
|
end
|
150
156
|
end
|
151
157
|
|
@@ -171,7 +177,7 @@ module EleetScript
|
|
171
177
|
class SetLocalNode
|
172
178
|
def eval(context)
|
173
179
|
if Lexer::RESERVED_WORDS.include?(name)
|
174
|
-
context["Errors"].call("<", [context["String"].new_with_value("Cannot assign a value to reserved word \"name\"")])
|
180
|
+
context.root_ns["Errors"].call("<", [context.root_ns["String"].new_with_value("Cannot assign a value to reserved word \"name\"")])
|
175
181
|
else
|
176
182
|
context.local_var(name, value.eval(context))
|
177
183
|
end
|
@@ -220,13 +226,13 @@ module EleetScript
|
|
220
226
|
|
221
227
|
class TrueNode
|
222
228
|
def eval(context)
|
223
|
-
context["true"]
|
229
|
+
context.root_ns["true"]
|
224
230
|
end
|
225
231
|
end
|
226
232
|
|
227
233
|
class FalseNode
|
228
234
|
def eval(context)
|
229
|
-
context["false"]
|
235
|
+
context.root_ns["false"]
|
230
236
|
end
|
231
237
|
end
|
232
238
|
|
@@ -285,7 +291,7 @@ module EleetScript
|
|
285
291
|
|
286
292
|
class LambdaNode
|
287
293
|
def eval(context)
|
288
|
-
context["Lambda"].new_with_value(EleetScriptMethod.new(params, body, context))
|
294
|
+
context.root_ns["Lambda"].new_with_value(EleetScriptMethod.new(params, body, context))
|
289
295
|
end
|
290
296
|
end
|
291
297
|
|
data/lib/lang/lexer.rb
CHANGED
@@ -26,6 +26,7 @@ module EleetScript
|
|
26
26
|
float: /\A([\d_]*?\.[\d_]+)/,
|
27
27
|
string: /\A\"(.*?)(?<!\\)\"/m,
|
28
28
|
regex: /\Ar\"(.*?)(?<!\\)\"([gim]*)/,
|
29
|
+
symbol: /\A:([a-z][\w\d]*?\b)/i,
|
29
30
|
comment: /\A#.*?(?=\n|$)/m
|
30
31
|
}
|
31
32
|
|
@@ -53,6 +54,9 @@ module EleetScript
|
|
53
54
|
elsif instance_var = chunk[TOKEN_RX[:instance_var]]
|
54
55
|
tokens << [:INSTANCE_IDENTIFIER, $1]
|
55
56
|
i += instance_var.length
|
57
|
+
elsif symbol = chunk[TOKEN_RX[:symbol]]
|
58
|
+
tokens << [:SYMBOL, $1.to_sym]
|
59
|
+
i += symbol.length
|
56
60
|
elsif regex = chunk[TOKEN_RX[:regex]]
|
57
61
|
pattern, flags = $1, $2
|
58
62
|
tokens << [:REGEX, pattern.gsub('\"', '"')]
|