sydney 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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sydney.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Geoff Harcourt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Sydney
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sydney'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sydney
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ require "sydney/version"
2
+
3
+ require "treetop"
4
+
5
+ module Sydney
6
+
7
+ # Load the Treetop grammar from the 'sexp_parser' file, and
8
+ # create a new instance of that parser as a class variable
9
+ # so we don't have to re-create it every time we need to
10
+ # parse a string
11
+ Treetop.load(File.join(
12
+ File.dirname(__FILE__),
13
+ "/sydney/sydney_alias_file/grammar_rules.treetop")
14
+ )
15
+ @@parser = SydneyAliasFileParser.new
16
+
17
+ def self.parse(data)
18
+ # Pass the data over to the parser instance
19
+ tree = @@parser.parse(data)
20
+
21
+ # If the AST is nil then there was an error during parsing
22
+ # we need to report a simple error message to help the user
23
+ if(tree.nil?)
24
+ raise Exception, "Parse error at offset: #{@@parser.index}"
25
+ end
26
+
27
+ return tree
28
+ end
29
+
30
+ end
31
+
32
+ require 'sydney/sydney_alias_file/node_extensions'
@@ -0,0 +1,49 @@
1
+ grammar SydneyAliasFile
2
+ rule document
3
+ section* <Document>
4
+ end
5
+
6
+ rule section
7
+ leading_whitespace:whitespace section_title:section_comment* content:alias_entry+ <Section>
8
+ end
9
+
10
+ rule section_comment
11
+ comment_code:comment_leader 2.. content:line <SectionComment>
12
+ end
13
+
14
+ rule alias_entry
15
+ entry_comments:alias_comment* definition:alias_definition <AliasEntry>
16
+ end
17
+
18
+ rule alias_comment
19
+ leading:comment_leader !comment_leader comment_text:line <AliasComment>
20
+ end
21
+
22
+ rule alias_definition
23
+ leading:'alias ' prefix:[A-Za-z\-\s\.]+ equal_sign:[\s]* '=' [\s]* aliased_command:text end_of_line:newline* <AliasDefinition>
24
+ end
25
+
26
+ rule quote_character
27
+ [\'\"]
28
+ end
29
+
30
+ rule line
31
+ content:text trailer:newline*
32
+ end
33
+
34
+ rule comment_leader
35
+ '#'
36
+ end
37
+
38
+ rule whitespace
39
+ [\s\n]*
40
+ end
41
+
42
+ rule text
43
+ [^\n]+
44
+ end
45
+
46
+ rule newline
47
+ [\n]+
48
+ end
49
+ end
@@ -0,0 +1,65 @@
1
+ module SydneyAliasFile
2
+ class SyntaxNode < Treetop::Runtime::SyntaxNode
3
+ def to_s
4
+ text_value
5
+ end
6
+ end
7
+
8
+ class Document < SyntaxNode
9
+ def sections
10
+ to_a
11
+ end
12
+
13
+ def to_a
14
+ elements.map{ |element| element }
15
+ end
16
+ end
17
+
18
+ class Section < SyntaxNode
19
+ def title
20
+ section_title.elements.map(&:to_s).join(' ')
21
+ end
22
+
23
+ def entries
24
+ content.elements
25
+ end
26
+ end
27
+
28
+ class SectionComment < SyntaxNode
29
+ def to_s
30
+ content.text_value.strip
31
+ end
32
+ end
33
+
34
+ class AliasEntry < SyntaxNode
35
+ def comments
36
+ entry_comments.elements
37
+ end
38
+
39
+ def comment
40
+ comments.map(&:to_s).join(' ')
41
+ end
42
+
43
+ def alias
44
+ definition
45
+ end
46
+ end
47
+
48
+ class AliasComment < SyntaxNode
49
+ def to_s
50
+ comment_text.text_value.strip
51
+ end
52
+ end
53
+
54
+ class AliasDefinition < SyntaxNode
55
+ def shortcut
56
+ prefix.text_value.strip
57
+ end
58
+
59
+ def command
60
+ stripped_command = aliased_command.to_s.strip
61
+ stripped_command[1,stripped_command.length - 2]
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,3 @@
1
+ module Sydney
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,39 @@
1
+
2
+ alias noop='noop -all'
3
+ ## Unix
4
+ ## Command Line Aliases
5
+ # Continuously tail file live.
6
+ # This can be useful when tracking activity.
7
+ alias tlf="tail -f"
8
+ alias ln='ln -v'
9
+ alias mkdir='mkdir -p'
10
+ alias ...='../..'
11
+ alias l='ls'
12
+ alias ll='ls -al'
13
+ alias lh='ls -Alh'
14
+
15
+ # Pipe to grep
16
+ alias -g G='| grep'
17
+ # Pipe to less
18
+ alias -g M='| less'
19
+ # Line count
20
+ alias -g L='| wc -l'
21
+ alias -g ONE="| awk '{ print \$1}'"
22
+
23
+ ## Git
24
+ alias g="git"
25
+ alias gci="git pull --rebase && rake && git push"
26
+
27
+ ## Bundler
28
+ alias b="bundle"
29
+
30
+ ## Tests and Specs
31
+ alias t="ruby -I test"
32
+ alias cuc="bundle exec cucumber"
33
+
34
+ ## Rubygems
35
+ alias gi="gem install"
36
+ alias giv="gem install -v"
37
+
38
+ ## Rails
39
+ alias migrate="rake db:migrate && rake db:rollback && rake db:migrate && rake db:test:prepare"
@@ -0,0 +1,13 @@
1
+ require 'sydney'
2
+
3
+ require 'rspec/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+
8
+ config.before(:all) do
9
+ @alias_file = IO.readlines('spec/fixtures/aliases').join
10
+ @parser_result = Sydney.parse(@alias_file)
11
+ end
12
+
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe SydneyAliasFile::AliasComment do
4
+
5
+ context "when the alias has a comment" do
6
+ before(:all) do
7
+ @comment = @parser_result.sections[1].entries.first.comment
8
+ end
9
+
10
+ describe "#to_s", :focus do
11
+ it "returns the comment text" do
12
+ @comment.to_s.should match(/Continuously tail file live\. This can be useful when tracking activity./)
13
+ end
14
+
15
+ it "trims the comment character from the front" do
16
+ @comment.to_s[0,1].should_not include(' ')
17
+ end
18
+
19
+ it "trims leading and trailing whitespace and newlines" do
20
+ @comment.to_s[0,2].should_not include(' ')
21
+ @comment.to_s[-3,3].should_not include(' ')
22
+ @comment.to_s.should_not match(/\n/)
23
+ end
24
+ end
25
+ end
26
+
27
+ context "when the alias does not have a comment" do
28
+ it "returns an empty string" do
29
+ @parser_result.sections.first.entries.first.comment.should eq('')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe SydneyAliasFile::AliasDefinition do
4
+ before(:all) do
5
+ @alias_definition = @parser_result.sections[1].entries.first.alias
6
+ end
7
+
8
+ describe "#shortcut" do
9
+ it "returns the alias to use at the command line with no leading or trailing whitespace" do
10
+ @alias_definition.shortcut.should eq('tlf')
11
+ end
12
+ end
13
+
14
+ describe "#command" do
15
+ it "returns the command to be aliased by the shortcut" do
16
+ @alias_definition.command.should eq('tail -f')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe SydneyAliasFile::AliasEntry do
4
+ before(:all) do
5
+ @alias_entry = @parser_result.sections[1].entries.first
6
+ end
7
+
8
+ describe '#comments' do
9
+ it "returns an array of all the AliasComment nodes" do
10
+ @alias_entry.comments.count.should eq(2)
11
+ @alias_entry.comments.first.class.should eq(SydneyAliasFile::AliasComment)
12
+ end
13
+ end
14
+
15
+ describe '#comment' do
16
+ it "returns a string with all the comments joined by a space" do
17
+ @alias_entry.comment.class.should eq(String)
18
+ @alias_entry.comment.should eq('Continuously tail file live. This can be useful when tracking activity.')
19
+ end
20
+ end
21
+
22
+ describe '#alias' do
23
+ it "returns an AliasDefinition node" do
24
+ @alias_entry.alias.class.should eq(SydneyAliasFile::AliasDefinition)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe SydneyAliasFile::Document do
4
+ describe "sections" do
5
+ it "divides the document into sections" do
6
+ @parser_result.sections.count.should eq(7)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe SydneyAliasFile::Section do
4
+ before(:all) { @section = @parser_result.sections[1]}
5
+
6
+ describe "#title" do
7
+ before(:each) { @title = @section.title }
8
+
9
+ it "returns the title text of the section" do
10
+ @title.should match(/Unix Command Line Aliases/)
11
+ end
12
+
13
+ it "removes the leading ## from the title" do
14
+ @title.should_not include('##')
15
+ end
16
+
17
+ it "removes leading and trailing whitespace from the title" do
18
+ @title[0,1].should_not include(' ')
19
+ @title[-1,1].should_not include(' ')
20
+ @title.should_not include("\n")
21
+ end
22
+ end
23
+
24
+ describe "#entries" do
25
+ it "returns one entry for each alias in the section" do
26
+ @section.entries.count.should eq(11)
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sydney do
4
+
5
+ context "with a valid alias file" do
6
+ it "parses the alias file" do
7
+ @parser_result.should be_true
8
+ end
9
+ end
10
+
11
+ context "with an invalid alias file" do
12
+ it "raises an exception and reports the offset where the problem occurred" do
13
+ expect {
14
+ Sydney.parse("blah blah")
15
+ }.to raise_error
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sydney/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sydney"
8
+ gem.version = Sydney::VERSION
9
+ gem.authors = ["Geoff Harcourt"]
10
+ gem.email = ["geoff.harcourt@gmail.com"]
11
+ gem.description = %q{A Treetop parser for alias files}
12
+ gem.summary = %q{Sydney parses alias files, dividing them into sections and alias entries, tying comments to entries.}
13
+ gem.homepage = "http://github.com/geoffharcourt/sydney"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(spec)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_runtime_dependency 'treetop', '~> 1.4.12'
20
+
21
+ gem.add_development_dependency 'rspec', '~> 2.12'
22
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sydney
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Geoff Harcourt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: treetop
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.4.12
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.12
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.12'
46
+ description: A Treetop parser for alias files
47
+ email:
48
+ - geoff.harcourt@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/sydney.rb
59
+ - lib/sydney/sydney_alias_file/grammar_rules.treetop
60
+ - lib/sydney/sydney_alias_file/node_extensions.rb
61
+ - lib/sydney/version.rb
62
+ - spec/fixtures/aliases
63
+ - spec/spec_helper.rb
64
+ - spec/sydney_alias_file/alias_comment_spec.rb
65
+ - spec/sydney_alias_file/alias_definition_spec.rb
66
+ - spec/sydney_alias_file/alias_entry_spec.rb
67
+ - spec/sydney_alias_file/document_spec.rb
68
+ - spec/sydney_alias_file/section_spec.rb
69
+ - spec/sydney_spec.rb
70
+ - sydney.gemspec
71
+ homepage: http://github.com/geoffharcourt/sydney
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.24
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Sydney parses alias files, dividing them into sections and alias entries,
95
+ tying comments to entries.
96
+ test_files:
97
+ - spec/fixtures/aliases
98
+ - spec/spec_helper.rb
99
+ - spec/sydney_alias_file/alias_comment_spec.rb
100
+ - spec/sydney_alias_file/alias_definition_spec.rb
101
+ - spec/sydney_alias_file/alias_entry_spec.rb
102
+ - spec/sydney_alias_file/document_spec.rb
103
+ - spec/sydney_alias_file/section_spec.rb
104
+ - spec/sydney_spec.rb