module SchemeStringsHelper
Helper functions for SchemeStrings
Public Instance Methods
arg_function_validator(other, vars = 1)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 35 def arg_function_validator(other, vars = 1) raise arg_err_build other.size, vars if other.size != vars res = other[0..vars - 1].reject(&:string?) raise type_err '<string>', res[0].type unless res.empty? res end
build_as_string_helper(other, idx)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 14 def build_as_string_helper(other, idx) value = other[0..idx].join(' ').gsub('( ', '(').gsub(' )', ')') [value, other[idx + 1..-1]] end
build_next_value_as_string(other)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 19 def build_next_value_as_string(other) idx = find_idx_for_list other if other[0] == '(' build_as_string_helper other, idx elsif other[0..1].join == '\'(' [(get_raw_value other[0..idx]), other[idx + 1..-1]] else [other[0], other[1..-1]] end end
find_delimeter(other)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 9 def find_delimeter(other) return ' ' if other.nil? other[1..-2] end
remove_carriage(str)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 30 def remove_carriage(str) str = str[1..-2] str.gsub('\n', '').gsub('\r', '').gsub('\t', '').strip.squeeze(' ') end
string_join_helper(other, dilimeter)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 42 def string_join_helper(other, dilimeter) values = split_list_as_string other.to_s delim_result = find_delimeter dilimeter '"' + (values.join delim_result) + '"' end
strjoin_validate(other)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 48 def strjoin_validate(other) raise arg_err_build '[1, 2]', other.size unless other.size.between? 1, 2 raise type_err '<list>', other[0].type unless other[0].to_s.list? end
substring_builder(str, from, to)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 3 def substring_builder(str, from, to) result = (str[1..-2])[from..(to.nil? ? -1 : to - 1)] return '""' if result.nil? '"' + result + '"' end
substring_validator(from, to)
click to toggle source
# File lib/lisp/interpreter/core/strings.rb, line 53 def substring_validator(from, to) valid = from.number? && (to.nil? || to.number?) type = [from, to].first { |t| t.type if t.type != 'number' } raise type_err '<number>', type unless valid end