apl 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 876b77ff5e261ec3615118a2231facab4d3acfbf
4
+ data.tar.gz: 797f56d5072c7792e66841416ebc700fe94697bd
5
+ SHA512:
6
+ metadata.gz: 0c3fd02499c477fa2cc810b57dea9d8de2b0e568a187938c2a9a22abf1e2d15ae63955b136a77728d7f6b4a662da95fabcda388b00c9e602f5ac36c31c90fd18
7
+ data.tar.gz: 19670ee0860f66d1a2ac52071bc2dbf79310908b5963afe6df1c09a88f5f1d0e692ea7fc8821c83ad63dbc526d026beb1965b98dda94f1f089a1876b970dca4c
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .ruby-version
14
+
15
+ # generated file
16
+ lib/apl/parser.rb
17
+ *.kpeg.rb
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.15.1
@@ -0,0 +1,8 @@
1
+ # Change log
2
+ Significant changes to this project are documented here, as recommended at http://www.keepachangelog.com.
3
+
4
+ ## Unreleased
5
+
6
+ ## 0.0.1 / 2017-06-19
7
+
8
+ - Get basic parsing, AST creation, and gem building working. [#1]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in apl.gemspec
4
+ gemspec
@@ -0,0 +1,71 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec", failed_mode: :keep do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+ dsl.watch_spec_files_for(%r{^(lib/.+)\.kpeg$})
43
+
44
+ # Rails files
45
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
46
+ dsl.watch_spec_files_for(rails.app_files)
47
+ dsl.watch_spec_files_for(rails.views)
48
+
49
+ watch(rails.controllers) do |m|
50
+ [
51
+ rspec.spec.call("routing/#{m[1]}_routing"),
52
+ rspec.spec.call("controllers/#{m[1]}_controller"),
53
+ rspec.spec.call("acceptance/#{m[1]}")
54
+ ]
55
+ end
56
+
57
+ # Rails config changes
58
+ watch(rails.spec_helper) { rspec.spec_dir }
59
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
60
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
61
+
62
+ # Capybara features specs
63
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
64
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
65
+
66
+ # Turnip features and steps
67
+ watch(%r{^spec/acceptance/(.+)\.feature$})
68
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
69
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
70
+ end
71
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Marnen E. Laibow-Koser <marnen@marnen.org>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # APL
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/apl`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'apl'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install apl
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marnen/apl-gem.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,24 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ PARSER_PATH = 'lib/apl/parser.kpeg.rb'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+
10
+ rule('.kpeg.rb' => -> (target) { target.chomp '.rb' }) do |file|
11
+ sh "bundle exec kpeg -f #{file.source} -o #{file.name}"
12
+ end
13
+
14
+ task build: 'parser:compile'
15
+
16
+ namespace :parser do
17
+ desc 'Compile the KPeg parser file to Ruby'
18
+ task compile: PARSER_PATH
19
+
20
+ desc 'Remove the compiled parser file'
21
+ task :clean do
22
+ rm PARSER_PATH
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "apl/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apl"
8
+ spec.version = APL::VERSION
9
+ spec.authors = ["Marnen Laibow-Koser"]
10
+ spec.email = ["marnen@marnen.org"]
11
+
12
+ spec.summary = 'Gem to allow APL array operations in Ruby'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/marnen/apl-gem'
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features|CHANGELOG)/}) || f.match(%r{\.kpeg$})
28
+ end << 'lib/apl/parser.kpeg.rb'
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ [
34
+ ["bundler", "~> 1.15"],
35
+ ["rake", "~> 10.0"],
36
+ 'byebug',
37
+ 'faker',
38
+ ['kpeg', '~> 1.0'],
39
+ ["rspec", "~> 3.0"],
40
+ 'guard-rspec'
41
+ ].each {|gem| spec.add_development_dependency *gem }
42
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apl"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ require "apl/version"
2
+ require 'apl/parser.kpeg.rb'
3
+ Dir[File.join File.dirname(__FILE__), "apl/ast/**/*.rb"].each {|file| require file }
4
+
5
+ module APL
6
+ def self.run(program)
7
+ parser = APL::Parser.new program
8
+ parser.parse # TODO: how should we handle errors?
9
+ parser.result.compute!
10
+ end
11
+ end
@@ -0,0 +1,68 @@
1
+ module APL
2
+ module AST
3
+ class Function
4
+ attr_reader :op, :x, :y
5
+
6
+ def initialize(op:, x:, y:)
7
+ @op = op
8
+ @x = x
9
+ @y = y
10
+ end
11
+
12
+ def compute!
13
+ ops = monadic? ? self.class.monadic : self.class.dyadic
14
+ block = ops[op] || raise(ArgumentError, "I don't know how to do the #{op} operation.")
15
+ computed_args = args.map do |arg|
16
+ begin
17
+ arg.compute!
18
+ rescue NoMethodError
19
+ arg
20
+ end
21
+ end
22
+ block.call *computed_args
23
+ end
24
+
25
+ def eql?(other)
26
+ [:op, :x, :y].all? {|field| self.send(field) == other.send(field) }
27
+ end
28
+
29
+ alias_method :==, :eql?
30
+
31
+ private
32
+
33
+ def self.monadic
34
+ @monadic ||= {
35
+ '+': ->(y) { y },
36
+ '-': ->(y) { -y },
37
+ '×': ->(y) do
38
+ if y == 0
39
+ 0
40
+ elsif y < 0
41
+ -1
42
+ else
43
+ 1
44
+ end
45
+ end,
46
+ '÷': ->(y) { 1.0 / y }
47
+ }
48
+ end
49
+
50
+ def self.dyadic
51
+ @dyadic ||= {
52
+ '+': ->(x, y) { x + y },
53
+ '-': ->(x, y) { x - y },
54
+ '×': ->(x, y) { x * y },
55
+ '÷': ->(x, y) { x.to_f / y }
56
+ }
57
+ end
58
+
59
+ def args
60
+ [x, y].compact
61
+ end
62
+
63
+ def monadic?
64
+ x.nil?
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module APL
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marnen Laibow-Koser
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: kpeg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Gem to allow APL array operations in Ruby
112
+ email:
113
+ - marnen@marnen.org
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - CHANGELOG.md
121
+ - Gemfile
122
+ - Guardfile
123
+ - LICENSE
124
+ - README.md
125
+ - Rakefile
126
+ - apl.gemspec
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/apl.rb
130
+ - lib/apl/ast/function.rb
131
+ - lib/apl/parser.kpeg.rb
132
+ - lib/apl/version.rb
133
+ homepage: https://github.com/marnen/apl-gem
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.5.1
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Gem to allow APL array operations in Ruby
157
+ test_files: []