alphalang 0.1.6 → 0.1.7
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/bin/alphalang +1 -1
- data/lib/alpha.rb +1 -3
- data/lib/lang_creator.rb +1 -7
- data/lib/nodes/basenodes.rb +2 -1
- data/lib/nodes/stmtnodes.rb +3 -0
- data/lib/rdparse.rb +73 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f69af7ab6e40605d9118d7125caf0c99ea961bd20108210a91d77ea790e0489
|
4
|
+
data.tar.gz: 0bd9593abf719ba7e5704a873f3d5d14aff15a20d424bcc858e7d9a7e45b22f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34c909f692a34e3eae601ec4eddcb6361e46480d74a857b277fdbe652d65b2cfa99b6c427661fea5c64720a2122b28e8644f079df2e76b267e53c9bf11c8d26f
|
7
|
+
data.tar.gz: 0aebab81771209c1f955abd3954e0ba7b9d4c8544fe2d308779d56d19669085b8cb925e6fbdda1cedd3c6b4a7755b95caa17b509bc9f948e85359025aefaf530
|
data/bin/alphalang
CHANGED
@@ -3,7 +3,7 @@ require 'optparse'
|
|
3
3
|
require File.expand_path('../lib/alpha', __dir__)
|
4
4
|
require_relative '../lib/rdparse'
|
5
5
|
ALPHA_VER = '0.1.5'.freeze
|
6
|
-
ABORT_ANSWERS = [' ', '', 'none', 'abort'].freeze
|
6
|
+
ABORT_ANSWERS = [' ', '', 'none', 'abort'].freeze
|
7
7
|
LOCALES_PATH = File.join(__dir__, '../lib/locales')
|
8
8
|
PROTECTED_LOCALES = ['.', '..', 'locale_template', 'default', 'default.old', 'en', 'sv', 'de'].freeze
|
9
9
|
|
data/lib/alpha.rb
CHANGED
@@ -2,7 +2,6 @@ require_relative './nodes/scopemanager'
|
|
2
2
|
|
3
3
|
class LangParser
|
4
4
|
def initialize(locale = 'default', debug_mode = false)
|
5
|
-
|
6
5
|
@langParser = Parser.new('lang parser', debug_mode, locale) do
|
7
6
|
token(/;;.*$/)
|
8
7
|
token(/while/) { |_| :WHILE }
|
@@ -24,7 +23,7 @@ class LangParser
|
|
24
23
|
token(/./) { |m| m }
|
25
24
|
|
26
25
|
start :program do
|
27
|
-
match(:comp_stmt)
|
26
|
+
match(:comp_stmt)
|
28
27
|
match(:terminal)
|
29
28
|
end
|
30
29
|
|
@@ -137,7 +136,6 @@ class LangParser
|
|
137
136
|
match(/\d+/, '.', /\d+/) { |a, dot, b| NumberNode.new((a+dot+b)) }
|
138
137
|
match('-', /\d+/) { |neg, a| NumberNode.new(neg + a) }
|
139
138
|
match(/\d+/) { |a| NumberNode.new(a) }
|
140
|
-
match(/(false|true)/) { |a| BoolNode.new(a) }
|
141
139
|
match(ScopeManager.true_value) { |a| BoolNode.new(a) }
|
142
140
|
match(ScopeManager.false_value) { |a| BoolNode.new(a) }
|
143
141
|
match(:PRINT, :member) { |_, a| PrintNode.new(a) }
|
data/lib/lang_creator.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative 'locale_lister'
|
3
3
|
|
4
|
-
# Function to read user input for translation
|
5
4
|
def read_translation(line)
|
6
5
|
puts "Enter the translation for: '#{line}' <RET> to accept '#{line}'"
|
7
6
|
translation = gets.chomp
|
@@ -73,21 +72,16 @@ def create_locale_file()
|
|
73
72
|
return
|
74
73
|
end
|
75
74
|
|
76
|
-
# prompt user for translations
|
77
75
|
prompt_user(new_locale_file_path)
|
78
|
-
|
79
|
-
# Clear the screen
|
80
76
|
system('clear')
|
81
77
|
|
82
|
-
# Display the contents of the translation file
|
83
78
|
locale_as_array = clean_locale_file_to_array(new_locale_name)
|
84
79
|
print_clean_locale_array(new_locale_name, locale_as_array)
|
85
80
|
|
86
|
-
# Ask user if the translation is correct
|
87
81
|
puts 'Is this correct? [Y/n]'
|
88
82
|
answer = gets.chomp
|
89
83
|
|
90
|
-
if answer.downcase
|
84
|
+
if answer.downcase.match? /y|Y/ or answer.empty?
|
91
85
|
puts "Locale is saved as #{new_locale_name} in #{LOCALES_PATH}"
|
92
86
|
else
|
93
87
|
puts 'Translation removed'
|
data/lib/nodes/basenodes.rb
CHANGED
@@ -149,12 +149,13 @@ class CompStmtNode < Node
|
|
149
149
|
|
150
150
|
def evaluate
|
151
151
|
@comp_statements[0].evaluate
|
152
|
-
@comp_statements[1].evaluate
|
152
|
+
@comp_statements[1].evaluate
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
####################################################
|
157
157
|
|
158
|
+
#Arraynoden är ofärdig, används inte korrekt
|
158
159
|
class ArrayNode < Node
|
159
160
|
attr_accessor :lhs, :rhs
|
160
161
|
|
data/lib/nodes/stmtnodes.rb
CHANGED
@@ -72,12 +72,14 @@ class FuncCallNode < Node
|
|
72
72
|
ScopeManager.decrement_scope_level
|
73
73
|
|
74
74
|
# If function return value is an "Assign" then we declare that variable in the global scope.
|
75
|
+
# This should be a ScopeManager method, add_variable_to_global_scope is missing.
|
75
76
|
old_scope_lvl = ScopeManager.scope_lvl
|
76
77
|
if func_return_value.is_a?(VariableDecNode)
|
77
78
|
ScopeManager.scope_lvl = 0
|
78
79
|
func_return_value.evaluate
|
79
80
|
ScopeManager.scope_lvl = old_scope_lvl
|
80
81
|
end
|
82
|
+
|
81
83
|
return func_return_value
|
82
84
|
end
|
83
85
|
end
|
@@ -196,6 +198,7 @@ class PauseNode < Node
|
|
196
198
|
end
|
197
199
|
|
198
200
|
def evaluate
|
201
|
+
@value = 0 if @value.evaluate.negative?
|
199
202
|
sleep @value.evaluate
|
200
203
|
end
|
201
204
|
end
|
data/lib/rdparse.rb
CHANGED
@@ -132,6 +132,7 @@ class Parser
|
|
132
132
|
@rules = {}
|
133
133
|
@start = nil
|
134
134
|
@language_name = language_name
|
135
|
+
@file_string = ''
|
135
136
|
|
136
137
|
create_tokens_from_locale(locale)
|
137
138
|
|
@@ -145,7 +146,7 @@ class Parser
|
|
145
146
|
instance_eval(&block)
|
146
147
|
end
|
147
148
|
|
148
|
-
# Recreate the tokenlist using
|
149
|
+
# Recreate the tokenlist using the chosen locale file
|
149
150
|
def create_tokens_from_locale(locale)
|
150
151
|
if locale == 'default'
|
151
152
|
lang_file = File.read("#{LOCALES_PATH}/#{locale}")
|
@@ -186,9 +187,78 @@ class Parser
|
|
186
187
|
end # until
|
187
188
|
end
|
188
189
|
|
190
|
+
def find_faulty_expression_within_block(block_start_line, block_end_line, problematic_token)
|
191
|
+
index = 0
|
192
|
+
result = []
|
193
|
+
@file_string.each_line do |line|
|
194
|
+
if index > block_start_line and index < block_end_line
|
195
|
+
|
196
|
+
if line.match?(/;;.*$/)
|
197
|
+
line = line.split(';;')[0]
|
198
|
+
end
|
199
|
+
|
200
|
+
if line.match?(/#{problematic_token}\s+$/)
|
201
|
+
result << "ParseError, #{line.strip}() is missing an expression on line #{index + 1}"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
index += 1
|
205
|
+
end
|
206
|
+
raise ParseError, result[-1]
|
207
|
+
end
|
208
|
+
|
209
|
+
def find_faulty_expression_within_ends
|
210
|
+
puts 'TODO: Implement search for faulty token between two of the same guides'
|
211
|
+
raise ParseError, "Most likely mismatched '#{@token_list['END'.downcase]}' token."
|
212
|
+
end
|
213
|
+
|
214
|
+
def find_faulty_line
|
215
|
+
problematic_token = "#{@tokens[@max_pos - 1].downcase}"
|
216
|
+
before_problem = "#{@tokens[@max_pos - 2].downcase}"
|
217
|
+
after_problem = "#{@tokens[@max_pos - 0].downcase}"
|
218
|
+
|
219
|
+
if @max_pos - 5 <= 0
|
220
|
+
puts 'problem in the beginning of file, figure it out'
|
221
|
+
return
|
222
|
+
elsif @max_pos + 5 < @max_pos
|
223
|
+
puts 'problem in the end of file, figure it out'
|
224
|
+
return
|
225
|
+
end
|
226
|
+
|
227
|
+
translated_problematic_token = @token_list[problematic_token]
|
228
|
+
|
229
|
+
if translated_problematic_token.is_a?(NilClass)
|
230
|
+
raise ParseError, "Faulty expression likely between two '#{@token_list['END'.downcase]}' tokens."
|
231
|
+
end
|
232
|
+
|
233
|
+
index = 0
|
234
|
+
problem_match_hash = {}
|
235
|
+
found_end = false
|
236
|
+
@file_string.each_line do |line|
|
237
|
+
if line.match?(before_problem) && found_end == false
|
238
|
+
problem_match_hash[before_problem] = index
|
239
|
+
end
|
240
|
+
|
241
|
+
if line.match?(after_problem) && index > problem_match_hash[before_problem]
|
242
|
+
problem_match_hash[after_problem] = index
|
243
|
+
found_end = true
|
244
|
+
end
|
245
|
+
index += 1
|
246
|
+
end
|
247
|
+
|
248
|
+
non_empty_line_before_problem = problem_match_hash[before_problem]
|
249
|
+
non_empty_line_after_problem = problem_match_hash[after_problem]
|
250
|
+
|
251
|
+
unless after_problem == before_problem
|
252
|
+
find_faulty_expression_within_block(non_empty_line_before_problem, non_empty_line_after_problem, problematic_token)
|
253
|
+
else
|
254
|
+
find_faulty_expression_within_ends
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
189
258
|
def parse(string)
|
190
259
|
# First, split the string according to the "token" instructions given.
|
191
260
|
# Afterwards @tokens contains all tokens that are to be parsed.
|
261
|
+
@file_string = string
|
192
262
|
tokenize(string)
|
193
263
|
|
194
264
|
# These variables are used to match if the total number of tokens
|
@@ -205,7 +275,8 @@ class Parser
|
|
205
275
|
raise ParseError, 'Mismatched parenthesis! In Emacs: M-x check-parens RET'
|
206
276
|
end
|
207
277
|
|
208
|
-
raise ParseError, "Parse error. expected: '#{@expected.join(', ')}', found '#{@tokens[@max_pos]}'"
|
278
|
+
# raise ParseError, "Parse error. expected: '#{@expected.join(', ')}', found '#{@tokens[@max_pos]}'"
|
279
|
+
return find_faulty_line
|
209
280
|
end
|
210
281
|
return result
|
211
282
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphalang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- mattias
|
7
|
+
- mattias, victor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|