Skip to content

Commit a139e70

Browse files
committed
initial commit, working through parser
0 parents  commit a139e70

20 files changed

+785
-0
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
10+
# rspec failure tracking
11+
.rspec_status
12+
13+
Gemfile.lock

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# v0.1.0
2+
3+
Initial release

Gemfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source "https://rubygems.org"
2+
3+
# Specify your gem's dependencies in babybel.gemspec
4+
gemspec
5+
6+
gem "pry"
7+
gem "rake", "~> 12.0"
8+
gem "rspec", "~> 3.0"

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Ryan Cook
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.

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Babybel
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/babybel`. 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 'babybel'
13+
```
14+
15+
And then execute:
16+
17+
$ bundle install
18+
19+
Or install it yourself as:
20+
21+
$ gem install babybel
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/[USERNAME]/babybel.
36+
37+
38+
## License
39+
40+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "bundler/gem_tasks"
2+
require "rspec/core/rake_task"
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
6+
task :default => :spec

babybel.gemspec

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require_relative 'lib/babybel/version'
2+
3+
Gem::Specification.new do |spec|
4+
spec.name = "babybel"
5+
spec.version = Babybel::VERSION
6+
spec.authors = ["Ryan Cook"]
7+
spec.email = ["cookrn@gmail.com"]
8+
9+
spec.summary = %q{Babybel is a Bel lisp implementation.}
10+
spec.description = %q{Babybel is a Bel lisp implementation.}
11+
spec.homepage = "https://github.com/cookrn/babybel"
12+
spec.license = "MIT"
13+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14+
15+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
16+
17+
spec.metadata["homepage_uri"] = spec.homepage
18+
spec.metadata["source_code_uri"] = spec.homepage
19+
spec.metadata["changelog_uri"] = "#{spec.homepage}/tree/master/CHANGELOG.md"
20+
21+
# Specify which files should be added to the gem when it is released.
22+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25+
end
26+
spec.bindir = "exe"
27+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28+
spec.require_paths = ["lib"]
29+
30+
spec.add_dependency "parslet", "~> 1.8"
31+
end

bin/bundle

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'bundle' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "rubygems"
12+
13+
m = Module.new do
14+
module_function
15+
16+
def invoked_as_script?
17+
File.expand_path($0) == File.expand_path(__FILE__)
18+
end
19+
20+
def env_var_version
21+
ENV["BUNDLER_VERSION"]
22+
end
23+
24+
def cli_arg_version
25+
return unless invoked_as_script? # don't want to hijack other binstubs
26+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27+
bundler_version = nil
28+
update_index = nil
29+
ARGV.each_with_index do |a, i|
30+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31+
bundler_version = a
32+
end
33+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34+
bundler_version = $1
35+
update_index = i
36+
end
37+
bundler_version
38+
end
39+
40+
def gemfile
41+
gemfile = ENV["BUNDLE_GEMFILE"]
42+
return gemfile if gemfile && !gemfile.empty?
43+
44+
File.expand_path("../../Gemfile", __FILE__)
45+
end
46+
47+
def lockfile
48+
lockfile =
49+
case File.basename(gemfile)
50+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51+
else "#{gemfile}.lock"
52+
end
53+
File.expand_path(lockfile)
54+
end
55+
56+
def lockfile_version
57+
return unless File.file?(lockfile)
58+
lockfile_contents = File.read(lockfile)
59+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60+
Regexp.last_match(1)
61+
end
62+
63+
def bundler_version
64+
@bundler_version ||=
65+
env_var_version || cli_arg_version ||
66+
lockfile_version
67+
end
68+
69+
def bundler_requirement
70+
return "#{Gem::Requirement.default}.a" unless bundler_version
71+
72+
bundler_gem_version = Gem::Version.new(bundler_version)
73+
74+
requirement = bundler_gem_version.approximate_recommendation
75+
76+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
77+
78+
requirement += ".a" if bundler_gem_version.prerelease?
79+
80+
requirement
81+
end
82+
83+
def load_bundler!
84+
ENV["BUNDLE_GEMFILE"] ||= gemfile
85+
86+
activate_bundler
87+
end
88+
89+
def activate_bundler
90+
gem_error = activation_error_handling do
91+
gem "bundler", bundler_requirement
92+
end
93+
return if gem_error.nil?
94+
require_error = activation_error_handling do
95+
require "bundler/version"
96+
end
97+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99+
exit 42
100+
end
101+
102+
def activation_error_handling
103+
yield
104+
nil
105+
rescue StandardError, LoadError => e
106+
e
107+
end
108+
end
109+
110+
m.load_bundler!
111+
112+
if m.invoked_as_script?
113+
load Gem.bin_path("bundler", "bundle")
114+
end

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "babybel"
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__)

bin/rspec

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rspec' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rspec-core", "rspec")

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -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

exe/babybel

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env ruby
2+
3+
require "babybel"

lib/babybel.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "babybel/version"
2+
3+
module Babybel
4+
class Error < StandardError; end
5+
end
6+
7+
require "babybel/minibel"

lib/babybel/minibel.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require "parslet"
2+
3+
module Babybel
4+
class Minibel < Parslet::Parser
5+
root :multi_expression
6+
rule(:multi_expression) { expression.repeat }
7+
8+
rule(:expression) do
9+
space? >> str("(") >> space? >> body >> str(")") >> space?
10+
end
11+
12+
rule(:pair) do
13+
space? >> str("(") >> space? >> (inner_body.repeat.as(:left) >> str(".") >> \
14+
space? >> inner_body.as(:right)).as(:pair) >> str(")") >> space?
15+
end
16+
17+
rule(:inner_body) do
18+
expression | pair | symbol | string
19+
end
20+
21+
rule(:body) do
22+
(quote? >> inner_body).repeat.as(:exp)
23+
end
24+
25+
rule(:space) { match('\s').repeat(1) }
26+
rule(:space?) { space.maybe }
27+
28+
rule(:symbol) do
29+
(match("[a-zA-Z=*+]") >> match("[a-zA-Z=*_]").repeat).as(:symbol) >> space?
30+
end
31+
32+
rule(:quote) { str("'").as(:quoted) }
33+
rule(:quote?) { quote.maybe }
34+
35+
rule(:string) do
36+
str('"') >> (
37+
str('\\') >> any |
38+
str('"').absent? >> any
39+
).repeat.as(:string) >> str('"') >> space?
40+
end
41+
end
42+
end

lib/babybel/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Babybel
2+
VERSION = "0.1.0"
3+
end

0 commit comments

Comments
 (0)