smtlaissezfaire-gazelle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -0
- data/ext/gazelle_ruby_bindings/extconf.rb +6 -0
- data/ext/gazelle_ruby_bindings/gazelle_ruby_bindings.c +119 -0
- data/ext/gazelle_ruby_bindings/gazelle_ruby_bindings.h +20 -0
- data/ext/gazelle_ruby_bindings/includes/bc_read_stream.c +872 -0
- data/ext/gazelle_ruby_bindings/includes/load_grammar.c +563 -0
- data/ext/gazelle_ruby_bindings/includes/parse.c +813 -0
- data/lib/gazelle.rb +11 -0
- data/lib/gazelle/gemspec.rb +39 -0
- data/lib/gazelle/parser.rb +31 -0
- data/spec/gazelle_integration_spec.rb +97 -0
- data/spec/hello.gzc +0 -0
- data/spec/hello.gzl +1 -0
- data/spec/invalid_format.gzc +0 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +5 -0
- data/tasks/c_extensions.rake +4 -0
- data/tasks/flog.rake +10 -0
- data/tasks/gem.rake +8 -0
- data/tasks/rspec.rake +20 -0
- data/tasks/sloc.rake +16 -0
- data/tasks/tags.rake +23 -0
- metadata +75 -0
data/lib/gazelle.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Gazelle
|
2
|
+
class Gemspec
|
3
|
+
def self.spec(&block)
|
4
|
+
new(&block).spec
|
5
|
+
end
|
6
|
+
|
7
|
+
PROJECT_NAME = "gazelle"
|
8
|
+
|
9
|
+
def initialize(*args, &block)
|
10
|
+
@spec = Gem::Specification.new do |s|
|
11
|
+
summary = "Ruby bindings for the Gazelle parser-generator"
|
12
|
+
|
13
|
+
s.name = PROJECT_NAME
|
14
|
+
s.summary = summary
|
15
|
+
s.description = summary
|
16
|
+
|
17
|
+
s.email = "scott@railsnewbie.com"
|
18
|
+
s.homepage = "http://github.com/smtlaissezfaire/#{PROJECT_NAME.downcase}"
|
19
|
+
s.authors = ["Scott Taylor"]
|
20
|
+
|
21
|
+
s.platform = Gem::Platform::RUBY
|
22
|
+
s.extensions = FileList["ext/**/extconf.rb"]
|
23
|
+
s.files = FileList[
|
24
|
+
"ext/**/*.rb",
|
25
|
+
"ext/**/*.c",
|
26
|
+
"ext/**/*.h",
|
27
|
+
"lib/**/*.rb",
|
28
|
+
"spec/**/**",
|
29
|
+
"Rakefile",
|
30
|
+
"tasks/**/*.rake"
|
31
|
+
]
|
32
|
+
|
33
|
+
yield(s) if block_given?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :spec
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Gazelle
|
2
|
+
class Parser
|
3
|
+
def initialize(filename)
|
4
|
+
file = expand_path(filename)
|
5
|
+
raise(Errno::ENOENT) unless File.exists?(file)
|
6
|
+
|
7
|
+
@filename = file
|
8
|
+
@on = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def on(sym, &block)
|
12
|
+
@on[sym] = block
|
13
|
+
end
|
14
|
+
|
15
|
+
def rules(&block)
|
16
|
+
instance_eval(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def run_rule(name, str)
|
22
|
+
@on[name.to_sym].call(str)
|
23
|
+
end
|
24
|
+
|
25
|
+
def expand_path(filename)
|
26
|
+
File.expand_path(filename)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
require File.dirname(__FILE__) + "/../gazelle_ruby_bindings"
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
module Gazelle
|
4
|
+
describe Parser do
|
5
|
+
describe "parse" do
|
6
|
+
it "should be true if it can parse the input" do
|
7
|
+
parser = Parser.new(File.dirname(__FILE__) + "/hello.gzc")
|
8
|
+
parser.parse?("(5)").should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be false if it cannot parse the input" do
|
12
|
+
parser = Parser.new(File.dirname(__FILE__) + "/hello.gzc")
|
13
|
+
parser.parse?("(()").should be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise an 'Errno::ENOENT' error if the file does not exist" do
|
17
|
+
file = "#{File.dirname(__FILE__)}/non-existant-file"
|
18
|
+
|
19
|
+
lambda {
|
20
|
+
parser = Parser.new(file)
|
21
|
+
}.should raise_error(Errno::ENOENT, "No such file or directory")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not parse when the file is not in a valid format" do
|
25
|
+
file = "#{File.dirname(__FILE__)}/invalid_format.gzc"
|
26
|
+
parser = Parser.new(file)
|
27
|
+
|
28
|
+
parser.parse?("foo").should be_false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "running an action" do
|
33
|
+
before do
|
34
|
+
@parser = Parser.new(File.dirname(__FILE__) + "/hello.gzc")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not run the action if it isn't triggered" do
|
38
|
+
run = false
|
39
|
+
|
40
|
+
@parser.on :hello do
|
41
|
+
run = true
|
42
|
+
end
|
43
|
+
|
44
|
+
@parser.parse("(()")
|
45
|
+
|
46
|
+
run.should be_false
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should run the action when it is triggered" do
|
50
|
+
run = false
|
51
|
+
|
52
|
+
@parser.on :hello do
|
53
|
+
run = true
|
54
|
+
end
|
55
|
+
|
56
|
+
@parser.parse("(5)")
|
57
|
+
|
58
|
+
run.should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should yield the text" do
|
62
|
+
yielded_text = nil
|
63
|
+
|
64
|
+
@parser.on :hello do |text|
|
65
|
+
yielded_text = text
|
66
|
+
end
|
67
|
+
|
68
|
+
@parser.parse("(5)")
|
69
|
+
yielded_text.should == "(5)"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should yield the correct text" do
|
73
|
+
yielded_text = nil
|
74
|
+
|
75
|
+
@parser.on :hello do |text|
|
76
|
+
yielded_text = text
|
77
|
+
end
|
78
|
+
|
79
|
+
@parser.parse("((1923423))")
|
80
|
+
yielded_text.should == "((1923423))"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should be able to parse a rule with a block" do
|
84
|
+
yielded_text = nil
|
85
|
+
|
86
|
+
@parser.rules do
|
87
|
+
on :hello do |text|
|
88
|
+
yielded_text = text
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
@parser.parse("(5)")
|
93
|
+
yielded_text.should == "(5)"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/spec/hello.gzc
ADDED
Binary file
|
data/spec/hello.gzl
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hello -> "(" hello ")" | .digits=/[0-9]+/;
|
File without changes
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
data/tasks/flog.rake
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
desc "Feel the pain of my code, and submit a refactoring patch"
|
2
|
+
task :flog do
|
3
|
+
puts %x(find lib | grep ".rb$" | xargs flog)
|
4
|
+
end
|
5
|
+
|
6
|
+
task :flog_to_disk => :create_doc_directory do
|
7
|
+
puts "Flogging..."
|
8
|
+
%x(find lib | grep ".rb$" | xargs flog > doc/flog.txt)
|
9
|
+
puts "Done Flogging...\n"
|
10
|
+
end
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lib/gazelle"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new(Gazelle::Gemspec.spec)
|
6
|
+
rescue LoadError
|
7
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
8
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
require 'spec/rake/verify_rcov'
|
3
|
+
|
4
|
+
desc 'Run the specs'
|
5
|
+
Spec::Rake::SpecTask.new do |t|
|
6
|
+
t.warning = false
|
7
|
+
t.spec_opts = ["--color"]
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Create the html specdoc"
|
11
|
+
Spec::Rake::SpecTask.new(:specdoc => :create_doc_directory) do |t|
|
12
|
+
t.spec_opts = ["--format", "html:doc/specdoc.html"]
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Run all examples with RCov"
|
16
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
17
|
+
t.rcov = true
|
18
|
+
t.rcov_opts = ['--exclude', 'spec']
|
19
|
+
t.rcov_dir = "doc/rcov"
|
20
|
+
end
|
data/tasks/sloc.rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
def sloc
|
2
|
+
`sloccount #{File.dirname(__FILE__)}/../lib #{File.dirname(__FILE__)}/../ext`
|
3
|
+
end
|
4
|
+
|
5
|
+
desc "Output sloccount report. You'll need sloccount installed."
|
6
|
+
task :sloc do
|
7
|
+
puts "Counting lines of code"
|
8
|
+
puts sloc
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Write sloccount report"
|
12
|
+
task :output_sloc => :create_doc_directory do
|
13
|
+
File.open(File.dirname(__FILE__) + "/doc/lines_of_code.txt", "w") do |f|
|
14
|
+
f << sloc
|
15
|
+
end
|
16
|
+
end
|
data/tasks/tags.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Build the TAGS file for Emacs
|
2
|
+
# Taken with slight modifications from
|
3
|
+
# http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs
|
4
|
+
#
|
5
|
+
# Thanks Jim Weirich
|
6
|
+
|
7
|
+
module Emacs
|
8
|
+
module Tags
|
9
|
+
def self.ruby_files
|
10
|
+
@ruby_files ||= FileList['**/*.rb'].exclude("pkg")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :tags do
|
16
|
+
task :emacs do
|
17
|
+
puts "Making Emacs TAGS file"
|
18
|
+
sh "ctags -e #{Emacs::Tags.ruby_files}", :verbose => false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Build the emacs tags file"
|
23
|
+
task :tags => ["tags:emacs"]
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smtlaissezfaire-gazelle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Taylor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-10 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby bindings for the Gazelle parser-generator
|
17
|
+
email: scott@railsnewbie.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/gazelle_ruby_bindings/extconf.rb
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- ext/gazelle_ruby_bindings/extconf.rb
|
27
|
+
- ext/gazelle_ruby_bindings/gazelle_ruby_bindings.c
|
28
|
+
- ext/gazelle_ruby_bindings/gazelle_ruby_bindings.h
|
29
|
+
- ext/gazelle_ruby_bindings/includes/bc_read_stream.c
|
30
|
+
- ext/gazelle_ruby_bindings/includes/load_grammar.c
|
31
|
+
- ext/gazelle_ruby_bindings/includes/parse.c
|
32
|
+
- lib/gazelle.rb
|
33
|
+
- lib/gazelle/gemspec.rb
|
34
|
+
- lib/gazelle/parser.rb
|
35
|
+
- spec/gazelle_integration_spec.rb
|
36
|
+
- spec/hello.gzc
|
37
|
+
- spec/hello.gzl
|
38
|
+
- spec/invalid_format.gzc
|
39
|
+
- spec/spec.opts
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- tasks/c_extensions.rake
|
42
|
+
- tasks/flog.rake
|
43
|
+
- tasks/gem.rake
|
44
|
+
- tasks/rspec.rake
|
45
|
+
- tasks/sloc.rake
|
46
|
+
- tasks/tags.rake
|
47
|
+
has_rdoc: false
|
48
|
+
homepage: http://github.com/smtlaissezfaire/gazelle
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Ruby bindings for the Gazelle parser-generator
|
73
|
+
test_files:
|
74
|
+
- spec/gazelle_integration_spec.rb
|
75
|
+
- spec/spec_helper.rb
|