alphalang 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daa1ca143b51a415a7888d29f6cec78e41fddaa637685af3534708c40cc6de5a
4
- data.tar.gz: b2c26c887f7fcf6f14f4efab2787d61a1ce9f7df8e6cb872bfc0b2b7184fa961
3
+ metadata.gz: a9264317b60fae6805130ff9692189ba73bf08530c025d8a732c0c520b19a466
4
+ data.tar.gz: e7bff4ae6de5fbade8cbc6b0a779ddd06259fad639b3650239fbb5f39d0adff9
5
5
  SHA512:
6
- metadata.gz: f811511f84666e1148ea41d5706ed8289482dd8df76d2f0c3f25ebc8513ccf79b1869f83a35f586cbc6af0c1ded8f3ecf28403dc8495562a7f0d034daa0cc16b
7
- data.tar.gz: e62cf96b852544722eb6aa3c33e9cbbc32bb5eb3fa03aec71d89121736be7c78f2a027e0b1885419eec53385afa2787a1a8b9d5953aa6720cb8571bd3749b8d2
6
+ metadata.gz: 9c8f5078f5f91b224847c2c43134e84fb053d3ba6b5eb456104ae7a4f0f267009ee78077fc8e338e1bb5002616d16627491469df240492f045546b20d4a18c5a
7
+ data.tar.gz: daf389f2da9e82cd86a921639b5d8843ef4c45b33ef294d2c93a3281d64dfb0d6674c36f16aac04e76ef2f75c160865554e8325e57bb3c5864462a4739fc9f4f
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 # something here? Some cases empty means yes tho..
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) { |comp_stmt| 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 == /y|Y/ or answer.empty?
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'
@@ -149,12 +149,13 @@ class CompStmtNode < Node
149
149
 
150
150
  def evaluate
151
151
  @comp_statements[0].evaluate
152
- @comp_statements[1].evaluate # kanske bör loopas osv??? Root blir nu sista evalueringen.
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
 
@@ -37,7 +37,7 @@ class ScopeManager
37
37
  return @@scopes[temp_scope_lvl][name]
38
38
  end
39
39
  end
40
- raise ArgumentError, "Variable '#{name}' is not defined" unless @value
40
+ raise SyntaxError, "Variable '#{name}' is not defined" unless @value
41
41
  end
42
42
 
43
43
  def self.increment_scope_level
@@ -51,7 +51,7 @@ class ScopeManager
51
51
  end
52
52
 
53
53
  def self.lookup_func(name)
54
- raise ArgumentError, "Function '#{name}' is not defined" if @@scopes[0][name].is_a?(NilClass)
54
+ raise SyntaxError, "Function '#{name}' is not defined" if @@scopes[0][name].is_a?(NilClass)
55
55
  return @@scopes[0][name]
56
56
  end
57
57
 
@@ -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 locale_template and the chosen locale file
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,86 @@ 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
+ if block_start_line == nil || block_end_line == nil
192
+ raise ParseError, "Error with <#{problematic_token}> somewhere around line #{block_end_line}#{block_start_line}"
193
+ end
194
+ index = 0
195
+ result = []
196
+ @file_string.each_line do |line|
197
+ if index > block_start_line and index < block_end_line
198
+
199
+ if line.match?(/;;.*$/)
200
+ line = line.split(';;')[0]
201
+ end
202
+
203
+ if line.match?(/#{problematic_token}\s+$/)
204
+ result << "ParseError, #{line.strip}() is missing an expression on line #{index + 1}"
205
+ end
206
+ end
207
+ index += 1
208
+ end
209
+ raise ParseError, result[-1]
210
+ end
211
+
212
+ def find_faulty_expression_within_ends
213
+ puts 'TODO: Implement search for faulty token between two of the same guides'
214
+ raise ParseError, "Most likely mismatched '#{@token_list['END'.downcase]}' token."
215
+ end
216
+
217
+ def find_faulty_line
218
+ if @tokens[@max_pos-0].is_a?(NilClass)
219
+ if @max_pos >= 3
220
+ puts "Problem is in the end of the file after:\n #{@tokens[@max_pos - 3]}#{@tokens[@max_pos - 2]}#{@tokens[@max_pos - 1]}"
221
+ else
222
+ puts "Problem is right in the beginning of the file."
223
+ end
224
+ raise ParseError
225
+ end
226
+
227
+ problematic_token = "#{@tokens[@max_pos - 1].downcase}"
228
+ before_problem = "#{@tokens[@max_pos - 2].downcase}"
229
+ after_problem = "#{@tokens[@max_pos - 0].downcase}"
230
+
231
+ after_problem = "[" + after_problem + "]" if !after_problem.match?(/[a-z]/)
232
+ before_problem = "[" + before_problem + "]" if !before_problem.match?(/[a-z]/)
233
+
234
+ translated_problematic_token = @token_list[problematic_token]
235
+
236
+ if translated_problematic_token.is_a?(NilClass)
237
+ raise ParseError, "Faulty expression likely between two '#{@token_list['end']}' tokens."
238
+ end
239
+
240
+ index = 0
241
+ problem_match_hash = {}
242
+ found_end = false
243
+ @file_string.each_line do |line|
244
+
245
+ if line.match?(before_problem) && found_end == false
246
+ problem_match_hash[before_problem] = index
247
+ end
248
+
249
+ if line.match?(after_problem) && index > problem_match_hash[before_problem]
250
+ problem_match_hash[after_problem] = index
251
+ found_end = true
252
+ end
253
+ index += 1
254
+ end
255
+
256
+ non_empty_line_before_problem = problem_match_hash[before_problem]
257
+ non_empty_line_after_problem = problem_match_hash[after_problem]
258
+
259
+ unless after_problem == before_problem
260
+ find_faulty_expression_within_block(non_empty_line_before_problem, non_empty_line_after_problem, problematic_token)
261
+ else
262
+ find_faulty_expression_within_ends
263
+ end
264
+ end
265
+
189
266
  def parse(string)
190
267
  # First, split the string according to the "token" instructions given.
191
268
  # Afterwards @tokens contains all tokens that are to be parsed.
269
+ @file_string = string
192
270
  tokenize(string)
193
271
 
194
272
  # These variables are used to match if the total number of tokens
@@ -205,7 +283,8 @@ class Parser
205
283
  raise ParseError, 'Mismatched parenthesis! In Emacs: M-x check-parens RET'
206
284
  end
207
285
 
208
- raise ParseError, "Parse error. expected: '#{@expected.join(', ')}', found '#{@tokens[@max_pos]}'"
286
+ # raise ParseError, "Parse error. expected: '#{@expected.join(', ')}', found '#{@tokens[@max_pos]}'"
287
+ return find_faulty_line
209
288
  end
210
289
  return result
211
290
  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.6
4
+ version: 0.1.8
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-06 00:00:00.000000000 Z
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger