Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUB-18 Fixes from standard gem #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ source "https://rubygems.org"
# Specify your gem's dependencies in ruby-vernac-parser.gemspec
gemspec

gem 'rake', '~> 10.3.2'
gem "rake", "~> 10.3.2"

gem "yaml", "~> 0.2.0"
gem "fileutils", "~> 1.6"

group :development, :test do
gem 'rspec', "~> 3.12"
gem 'rspec-expectations', "~> 3.12"
gem 'rspec-mocks', '~> 3.12'
gem "rspec", "~> 3.12"
gem "rspec-expectations", "~> 3.12"
gem "rspec-mocks", "~> 3.12"

gem 'pry-nav', '~> 1.0'
gem "standard", "~> 1.31"
gem "pry-nav", "~> 1.0"

gem "dotenv", "~> 2.8"
gem "google-cloud-translate-v3", "~> 0.5"
Expand Down
44 changes: 44 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GEM
specs:
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.1.1)
coderay (1.1.3)
diff-lcs (1.5.0)
Expand Down Expand Up @@ -52,17 +53,28 @@ GEM
grpc (1.58.0-x86_64-linux)
google-protobuf (~> 3.23)
googleapis-common-protos-types (~> 1.0)
json (2.6.3)
jwt (2.7.1)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
method_source (1.0.0)
multi_json (1.15.0)
os (1.1.4)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-nav (1.0.0)
pry (>= 0.9.10, < 0.15)
public_suffix (5.0.3)
racc (1.7.1)
rainbow (3.1.1)
rake (10.3.2)
regexp_parser (2.8.2)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
Expand All @@ -76,12 +88,43 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.56.4)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
signet (0.18.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
standard (1.31.2)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.56.4)
standard-custom (~> 1.0.0)
standard-performance (~> 1.2)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.2.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.19.1)
unicode-display_width (2.5.0)
yaml (0.2.0)

PLATFORMS
Expand All @@ -98,6 +141,7 @@ DEPENDENCIES
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
ruby-vernac-parser!
standard (~> 1.31)
yaml (~> 0.2.0)

BUNDLED WITH
Expand Down
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require 'rake'
require 'rspec/core/rake_task'
require "rake"
require "rspec/core/rake_task"
require "standard/rake"

desc "Run all examples"
RSpec::Core::RakeTask.new(:spec)
Expand Down
3 changes: 1 addition & 2 deletions keyword_parser.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./lib/ruby-vernac-parser"
require_relative "lib/ruby-vernac-parser"

arg = ARGV
RubyVernacParser.new(
Expand All @@ -7,4 +7,3 @@
keywords_file: arg[2],
message_text: true
).execute

6 changes: 3 additions & 3 deletions language_gem_generator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require_relative "./lib/rubyvernac/generators/language_gem_generator"
require_relative "lib/rubyvernac/generators/language_gem_generator"

print "Ruby Vernac Language Gem Generator\n"
# print "Enter author name: "
# author_name = gets.chomp()
# print "Enter author email: "
# author_email = gets.chomp()
print "Enter prefered language: "
selected_language = gets.chomp()
selected_language = gets.chomp

Rubyvernac::Generators::LanguageGemGenerator.new(
language: selected_language,
language: selected_language
# author_email: author_email,
# author_name: author_name
).generate
55 changes: 26 additions & 29 deletions lib/ruby-vernac-parser.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require 'forwardable'
require 'yaml'
require "forwardable"
require "yaml"

require_relative "./rubyvernac/parser/language_parser"
require_relative "./rubyvernac/parser/language_alias_loader"
require_relative "rubyvernac/parser/language_parser"
require_relative "rubyvernac/parser/language_alias_loader"

class RubyVernacParser
extend Forwardable

def_delegators :@language_alias_loader, :create_aliases
attr_reader :keywords, :input_bytes, :message_text,
:source_file, :language, :keywords_file
:source_file, :language, :keywords_file

def initialize(source_file: nil, language: "ruby",
keywords_file: nil, message_text: false)
keywords_file: nil, message_text: false)
# @args = ARGV
@source_file = source_file
@message_text = message_text
Expand Down Expand Up @@ -46,7 +46,7 @@ def execute
File.delete(temp_file_path) if File.exist?(temp_file_path)
end
print "Script Output - \n" if message_text
print "#{output}"
print output
end

def parse
Expand All @@ -64,47 +64,44 @@ def validate_args
end

def read_input_file
begin
@input_bytes = File.read(source_file)
rescue => err
print "Error reading input file, #{err}\n"
raise
end
@input_bytes = File.read(source_file)
rescue => err
print "Error reading input file, #{err}\n"
raise
end

def read_keywords
_keywords = YAML.load_file(@keywords_file)
keywords = YAML.load_file(@keywords_file)

_keywords.each do |keyword_in_eng, keyword_in_non_eng|
keywords.each do |keyword_in_eng, keyword_in_non_eng|
@keywords[keyword_in_non_eng.to_s] = keyword_in_eng.to_s
end
end

def parsed_string
@parsed_string ||= Rubyvernac::Parser::LanguageParser.run(
byte_string: input_bytes,
keywords: keywords,
language: language
)
byte_string: input_bytes,
keywords: keywords,
language: language
)
end

def command
@command ||= case language
when "ruby"
"ruby"
else
"run"
end
@command ||= case language
when "ruby"
"ruby"
else
"run"
end
end

def temp_file_path
@temp_file_path ||= (
@temp_file_path ||= begin
file_path = "#{source_file}.tmp"
File.open(file_path, 'w') { |file| file.write(parsed_string) }
File.write(file_path, parsed_string)
file_path
)
end

@temp_file_path
end

end
4 changes: 0 additions & 4 deletions lib/rubyvernac/exceptions/language_not_available_exception.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
module Rubyvernac

class LanguageNotAvailableException < StandardError

def message
"Language not found"
end

end

end
17 changes: 7 additions & 10 deletions lib/rubyvernac/generators/language_classes_generator.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
require_relative '../utils/file_handler'
require 'yaml'
require_relative "../utils/file_handler"
require "yaml"

module Rubyvernac
module Generators

class LanguageClassesGenerator
CONFIG = {
classes: ["Array", "Class", "Object", "Integer", "Math", "Module"],
methods: {
public_methods: 'cpumethods',
private_methods: 'cprmethods',
instance_methods: 'ipumethods',
private_instance_methods: 'iprmethods'
public_methods: "cpumethods",
private_methods: "cprmethods",
instance_methods: "ipumethods",
private_instance_methods: "iprmethods"
}
}.freeze

Expand All @@ -30,7 +29,7 @@ def generate_class_files

# place to keep class's name -
content[class_name] = content[class_name] || {}
content[class_name]['cname'] = klass.name
content[class_name]["cname"] = klass.name

class_name = klass.name.downcase
CONFIG[:methods].each do |method, key|
Expand All @@ -44,8 +43,6 @@ def generate_class_files
@file_handler.append_to_file(translations_path, content.to_yaml)
end
end

end

end
end
10 changes: 3 additions & 7 deletions lib/rubyvernac/generators/language_gem_generator.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require_relative 'template_generator'
require_relative 'language_classes_generator'
require_relative '../validators/language_validator'
require_relative "template_generator"
require_relative "language_classes_generator"
require_relative "../validators/language_validator"

module Rubyvernac
module Generators

class LanguageGemGenerator
attr_reader :language, :author_name, :author_email

Expand All @@ -21,7 +20,6 @@ def initialize(language: "", author_name: "", author_email: "", validator: Rubyv
@language_classes_generator = Rubyvernac::Generators::LanguageClassesGenerator.new(language: @language, gem_path: gem_path)
end


def generate
@validator.validate(@language)

Expand All @@ -31,8 +29,6 @@ def generate
print "\n The new gem can be found in 'new_gems' folder\n"
# FileUtils.mv('/tmp/your_file', '/opt/new/location/your_file') # To move the output folder
end

end

end
end
Loading