alphalang 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/alphalang +3 -1
- data/lib/locale_defaulter.rb +9 -5
- data/lib/locale_lister.rb +5 -5
- data/lib/nodes/basenodes.rb +20 -20
- data/lib/nodes/scopemanager.rb +0 -2
- data/lib/nodes/stmtnodes.rb +25 -27
- data/lib/tester/assign.alpha +14 -0
- data/lib/tester/assign.alpha~ +5 -0
- data/lib/tester/fibonacci.alpha +12 -2
- data/lib/tester/test_unit.rb +61 -0
- metadata +4 -2
- /data/lib/{lang_creator.rb → locale_creator.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e9f2d6c36766c890ac954b41a9bf02f2fe70e1f4ac4a3d40843ff03c228b28
|
4
|
+
data.tar.gz: bd5b500b199a1e32964a311847a28f39ca3b6059c2f06e0e8fcbd608106a641a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad4f5de676ecdd7afc6d630c4a3934aba3d45623a8b45e19196574b7453641b077c5c5ac3a2d1c4edad06cacfaa17b28d7abf778fd894c7c4494c01a9d56654
|
7
|
+
data.tar.gz: 39f631c8dff1ecd6879786cee70656cb6c6b018db070d49d8c7e5cc6fccf8de018ba0ccf0608cdf11c00670f36d63eb2dcce5780c4cd2122b5b0a4cbc6e1ab9a
|
data/bin/alphalang
CHANGED
@@ -56,7 +56,7 @@ list_locales_flag = options[:listlocales]
|
|
56
56
|
list_locale_flag = options[:listlocale]
|
57
57
|
|
58
58
|
if create_locale_flag
|
59
|
-
require_relative '../lib/
|
59
|
+
require_relative '../lib/locale_creator'
|
60
60
|
create_locale_file
|
61
61
|
return
|
62
62
|
end
|
@@ -104,7 +104,9 @@ if verify_flag
|
|
104
104
|
puts 'Flag for verification found. Ignoring input file.'
|
105
105
|
sleep 1
|
106
106
|
end
|
107
|
+
TEST_UNIT_ACTIVE = true
|
107
108
|
require_relative '../lib/tester/test_unit'
|
108
109
|
else
|
110
|
+
TEST_UNIT_ACTIVE = false
|
109
111
|
LangParser.new(language_flag, verbose_flag).parse_file(ARGV[0])
|
110
112
|
end
|
data/lib/locale_defaulter.rb
CHANGED
@@ -5,11 +5,15 @@ require_relative 'locale_lister'
|
|
5
5
|
def set_default_locale(new_locale)
|
6
6
|
available_locales = get_locale_files
|
7
7
|
|
8
|
-
available_locales.each do |
|
9
|
-
if
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
available_locales.each do |available_locale|
|
9
|
+
if available_locale == new_locale
|
10
|
+
begin
|
11
|
+
File.open("#{LOCALES_PATH}/default", 'w') { |f| f.write(new_locale) }
|
12
|
+
puts "[alphalang] Default syntax locale is now set to #{new_locale}."
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
puts '[alphalang] Failed to change default locale. Likely permissions error on your machine.'
|
15
|
+
puts "Could not open #{LOCALES_PATH}/default}"
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
data/lib/locale_lister.rb
CHANGED
@@ -30,22 +30,24 @@ end
|
|
30
30
|
|
31
31
|
def print_clean_locale_array(locale_name, clean_array)
|
32
32
|
longest_word = clean_array.max_by(&:length).size
|
33
|
-
padding = ' ' * (longest_word/2-5)
|
33
|
+
padding = ' ' * (longest_word / 2 - 5)
|
34
34
|
|
35
35
|
header = "#{padding}[alphalang] Syntax for locale <#{locale_name}>.#{padding}"
|
36
36
|
puts header
|
37
37
|
puts '+' * (header.size - 2)
|
38
|
+
|
38
39
|
clean_line = ''
|
39
40
|
clean_array.each_with_index do |word, index|
|
40
41
|
if index.even?
|
41
42
|
clean_line += "+ #{word}"
|
42
43
|
else
|
43
|
-
clean_line += (' ' * (20 -clean_line.size)) + "#{word}"
|
44
|
+
clean_line += (' ' * (20 - clean_line.size)) + "#{word}"
|
44
45
|
clean_line += (' ' * (header.size - clean_line.size - 3) + '+')
|
45
46
|
puts clean_line
|
46
47
|
clean_line = ''
|
47
48
|
end
|
48
49
|
end
|
50
|
+
|
49
51
|
puts '+' * (header.size - 2)
|
50
52
|
end
|
51
53
|
|
@@ -53,9 +55,7 @@ def list_specific_locale_file()
|
|
53
55
|
list_locale_files
|
54
56
|
specific_locale = gets.chomp
|
55
57
|
|
56
|
-
if specific_locale == 'default'
|
57
|
-
specific_locale = File.read("#{LOCALES_PATH}/#{specific_locale}")
|
58
|
-
end
|
58
|
+
specific_locale = File.read("#{LOCALES_PATH}/#{specific_locale}") if specific_locale == 'default'
|
59
59
|
|
60
60
|
return if ABORT_ANSWERS.include?(specific_locale)
|
61
61
|
|
data/lib/nodes/basenodes.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
####################################################
|
1
|
+
###################### Base Nodes
|
4
2
|
|
5
3
|
class Node
|
6
4
|
attr_accessor :value
|
@@ -43,6 +41,8 @@ class BoolNode < Node
|
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
44
|
+
###################### Logic Gate Nodes
|
45
|
+
|
46
46
|
class AndNode < Node
|
47
47
|
def initialize(lhs, rhs)
|
48
48
|
@lhs, @rhs = lhs, rhs
|
@@ -83,7 +83,7 @@ class NotNode < Node
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
###################### Operation Nodes
|
87
87
|
|
88
88
|
class CompareNode < Node
|
89
89
|
attr_accessor :lhs, :op, :rhs
|
@@ -119,7 +119,7 @@ class BinaryOperationNode < Node
|
|
119
119
|
end
|
120
120
|
|
121
121
|
if @rhs.evaluate.is_a?(ArrayNode) or @rhs.evaluate.is_a?(Array) and @lhs.evaluate.is_a?(Numeric)
|
122
|
-
raise SyntaxError, "You can't subtract
|
122
|
+
raise SyntaxError, "You can't subtract an array from a number! #{@lhs.evaluate} #{@op} #{@rhs.name}"
|
123
123
|
end
|
124
124
|
|
125
125
|
if @op == '/'
|
@@ -130,21 +130,7 @@ class BinaryOperationNode < Node
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
class CompStmtNode < Node
|
136
|
-
def initialize(stmt_compstmt)
|
137
|
-
super
|
138
|
-
@comp_statements = stmt_compstmt
|
139
|
-
end
|
140
|
-
|
141
|
-
def evaluate
|
142
|
-
@comp_statements[0].evaluate
|
143
|
-
@comp_statements[1].evaluate
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
####################################################
|
133
|
+
###################### Array / Data Structure Nodes
|
148
134
|
|
149
135
|
class ArrayNode < Node
|
150
136
|
attr_accessor :lhs, :rhs
|
@@ -205,3 +191,17 @@ class ArrayNode < Node
|
|
205
191
|
self
|
206
192
|
end
|
207
193
|
end
|
194
|
+
|
195
|
+
###################### Root Program Node
|
196
|
+
|
197
|
+
class CompStmtNode < Node
|
198
|
+
def initialize(stmt_compstmt)
|
199
|
+
super
|
200
|
+
@comp_statements = stmt_compstmt
|
201
|
+
end
|
202
|
+
|
203
|
+
def evaluate
|
204
|
+
@comp_statements[0].evaluate
|
205
|
+
@comp_statements[1].evaluate
|
206
|
+
end
|
207
|
+
end
|
data/lib/nodes/scopemanager.rb
CHANGED
data/lib/nodes/stmtnodes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'basenodes'
|
2
2
|
|
3
|
-
|
3
|
+
###################### Variable Nodes
|
4
4
|
|
5
5
|
class VariableCallNode < Node
|
6
6
|
attr_accessor :name
|
@@ -29,7 +29,22 @@ class VariableDecNode < Node
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
class ArrayCallNode < Node
|
33
|
+
def initialize(array, index)
|
34
|
+
super(array)
|
35
|
+
@index = index.to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def evaluate
|
39
|
+
arr = ScopeManager.lookup_var(@value)
|
40
|
+
if @index > arr.size - 1
|
41
|
+
raise ArgumentError, "You are trying to access an out of bounds index. Here -> #{@value}[#{@index}]"
|
42
|
+
end
|
43
|
+
@value = arr[@index]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
###################### Function Nodes
|
33
48
|
|
34
49
|
class FunctionDecNode < Node
|
35
50
|
def initialize(node, value)
|
@@ -84,7 +99,7 @@ class FuncCallNode < Node
|
|
84
99
|
end
|
85
100
|
end
|
86
101
|
|
87
|
-
|
102
|
+
###################### If Statement Nodes
|
88
103
|
|
89
104
|
class IfNode < Node
|
90
105
|
attr_accessor :argument
|
@@ -138,7 +153,7 @@ class IfCompStmtNode < Node
|
|
138
153
|
end
|
139
154
|
end
|
140
155
|
|
141
|
-
|
156
|
+
###################### Loop Nodes
|
142
157
|
|
143
158
|
class WhileLoopNode < Node
|
144
159
|
attr_accessor :condition
|
@@ -156,24 +171,7 @@ class WhileLoopNode < Node
|
|
156
171
|
end
|
157
172
|
end
|
158
173
|
|
159
|
-
|
160
|
-
|
161
|
-
class ArrayCallNode < Node
|
162
|
-
def initialize(array, index)
|
163
|
-
super(array)
|
164
|
-
@index = index.to_i
|
165
|
-
end
|
166
|
-
|
167
|
-
def evaluate
|
168
|
-
arr = ScopeManager.lookup_var(@value)
|
169
|
-
if @index > arr.size - 1
|
170
|
-
raise ArgumentError, "You are trying to access an out of bounds index. Here -> #{@value}[#{@index}]"
|
171
|
-
end
|
172
|
-
@value = arr[@index]
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
####################################################
|
174
|
+
###################### Built-in Functions
|
177
175
|
|
178
176
|
class PrintNode
|
179
177
|
attr_accessor :value
|
@@ -184,11 +182,11 @@ class PrintNode
|
|
184
182
|
|
185
183
|
def evaluate
|
186
184
|
if @value.evaluate.is_a?(ArrayNode)
|
187
|
-
print "Array #{@value.name}: "
|
188
|
-
puts @value.evaluate
|
185
|
+
print "Array #{@value.name}: " unless TEST_UNIT_ACTIVE
|
186
|
+
puts @value.evaluate unless TEST_UNIT_ACTIVE
|
189
187
|
elsif @value.evaluate.is_a?(Array)
|
190
|
-
print "Array #{@value.name}: "
|
191
|
-
puts @value.evaluate.join(', ')
|
188
|
+
print "Array #{@value.name}: " unless TEST_UNIT_ACTIVE
|
189
|
+
puts @value.evaluate.join(', ') unless TEST_UNIT_ACTIVE
|
192
190
|
else
|
193
191
|
if @value.evaluate == PrintNode
|
194
192
|
if @value.value.is_a?(VariableCallNode)
|
@@ -197,7 +195,7 @@ class PrintNode
|
|
197
195
|
raise SyntaxError, "You have a duplicate 'print' statement! Printing #{@value.value} twice."
|
198
196
|
end
|
199
197
|
end
|
200
|
-
puts @value.evaluate
|
198
|
+
puts @value.evaluate unless TEST_UNIT_ACTIVE
|
201
199
|
end
|
202
200
|
self.class
|
203
201
|
end
|
data/lib/tester/fibonacci.alpha
CHANGED
data/lib/tester/test_unit.rb
CHANGED
@@ -239,3 +239,64 @@ class TesCompactIf < Test::Unit::TestCase
|
|
239
239
|
#{$end}"))
|
240
240
|
end
|
241
241
|
end
|
242
|
+
|
243
|
+
class TestPrograms < Test::Unit::TestCase
|
244
|
+
def test_fibonacci
|
245
|
+
program = "
|
246
|
+
a = 1
|
247
|
+
b = 1
|
248
|
+
|
249
|
+
#{$def} fib(x)
|
250
|
+
#{$if} 2 < x
|
251
|
+
|
252
|
+
temp = a + b
|
253
|
+
a = b
|
254
|
+
b = temp
|
255
|
+
|
256
|
+
fib(x - 1)
|
257
|
+
#{$else}
|
258
|
+
b
|
259
|
+
#{$end}
|
260
|
+
#{$end}
|
261
|
+
|
262
|
+
fib(11)
|
263
|
+
"
|
264
|
+
assert_equal(89, LangParser.new.calc_test(program))
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_func_with_while
|
268
|
+
program = "
|
269
|
+
x = 1
|
270
|
+
|
271
|
+
#{$def} foo(bar)
|
272
|
+
#{$while} bar < 20
|
273
|
+
#{$print} bar
|
274
|
+
bar = bar + 1
|
275
|
+
#{$end}
|
276
|
+
#{$end}
|
277
|
+
|
278
|
+
foo(x)
|
279
|
+
"
|
280
|
+
assert_equal(WhileLoopNode, LangParser.new.calc_test(program))
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_func_with_while_return_value
|
284
|
+
program = "
|
285
|
+
x = 1
|
286
|
+
|
287
|
+
#{$def} foo(bar)
|
288
|
+
y = 0
|
289
|
+
#{$while} bar < 20
|
290
|
+
#{$print} bar
|
291
|
+
bar = bar + 1
|
292
|
+
y = bar
|
293
|
+
#{$end}
|
294
|
+
#{$print} y
|
295
|
+
y
|
296
|
+
#{$end}
|
297
|
+
|
298
|
+
foo(x)
|
299
|
+
"
|
300
|
+
assert_equal(20, LangParser.new.calc_test(program))
|
301
|
+
end
|
302
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphalang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mattias, victor
|
@@ -60,7 +60,7 @@ extra_rdoc_files: []
|
|
60
60
|
files:
|
61
61
|
- bin/alphalang
|
62
62
|
- lib/alpha.rb
|
63
|
-
- lib/
|
63
|
+
- lib/locale_creator.rb
|
64
64
|
- lib/locale_defaulter.rb
|
65
65
|
- lib/locale_deleter.rb
|
66
66
|
- lib/locale_lister.rb
|
@@ -74,6 +74,8 @@ files:
|
|
74
74
|
- lib/nodes/scopemanager.rb
|
75
75
|
- lib/nodes/stmtnodes.rb
|
76
76
|
- lib/rdparse.rb
|
77
|
+
- lib/tester/assign.alpha
|
78
|
+
- lib/tester/assign.alpha~
|
77
79
|
- lib/tester/demo_de.alpha
|
78
80
|
- lib/tester/demo_emoji.alpha
|
79
81
|
- lib/tester/demo_emoji.alpha~
|
File without changes
|