Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make machete a gem + release version 0.1.0

  • Loading branch information...
commit d775e7cc18232b7cb13c688cd277aa1c0e1123ae 1 parent 1288cf5
@dmajda dmajda authored
View
1  .gitignore
@@ -1,3 +1,4 @@
+lib/machete/parser.rb
doc/
.yardoc
*.rbc
View
4 README.md
@@ -8,9 +8,7 @@ Installation
You need to install [Rubinius](http://rubini.us/) first. You can then install Machete:
- $ git clone git://github.com/openSUSE/machete.git
-
-The library is not available as a gem yet (this will come soon hopefully).
+ $ gem install machete
Usage
-----
View
1  VERSION
@@ -0,0 +1 @@
+0.1.0
View
1  lib/machete.rb
@@ -1,5 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/machete/matchers")
require File.expand_path(File.dirname(__FILE__) + "/machete/parser")
+require File.expand_path(File.dirname(__FILE__) + "/machete/version")
module Machete
# Matches a Rubinius AST node against a pattern.
View
346 lib/machete/parser.rb
@@ -1,346 +0,0 @@
-#
-# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.4.6
-# from Racc grammer file "".
-#
-
-require 'racc/parser.rb'
-module Machete
- class Parser < Racc::Parser
-
-module_eval(<<'...end parser.y/module_eval...', 'parser.y', 80)
-
-include Matchers
-
-class SyntaxError < StandardError; end
-
-def parse(input)
- @input = input
- @pos = 0
-
- do_parse
-end
-
-private
-
-SIMPLE_TOKENS = ["|", "<", ">", ",", "="]
-
-COMPLEX_TOKENS = [
- [:VAR_NAME, /^[a-z_][a-zA-Z0-9_]*/],
- [:CLASS_NAME, /^[A-Z][a-zA-Z0-9_]*/],
- [:SYMBOL, /^:[a-zA-Z_][a-zA-Z0-9_]*/],
- [
- :INTEGER,
- /^
- [+-]? # sign
- (
- 0[bB][01]+(_[01]+)* # binary (prefixed)
- |
- 0[oO][0-7]+(_[0-7]+)* # octal (prefixed)
- |
- 0[dD]\d+(_\d+)* # decimal (prefixed)
- |
- 0[xX][0-9a-fA-F]+(_[0-9a-fA-F]+)* # hexadecimal (prefixed)
- |
- 0[0-7]*(_[0-7]+)* # octal (unprefixed)
- |
- [1-9]\d*(_\d+)* # decimal (unprefixed)
- )
- /x
- ],
- [
- :STRING,
- /^
- (
- ' # sinqle-quoted string
- (
- \\[\\'] # escape
- |
- [^'] # regular character
- )*
- '
- |
- " # double-quoted string
- (
- \\ # escape
- (
- [\\"ntrfvaebs] # one-character escape
- |
- [0-7]{1,3} # octal number escape
- |
- x[0-9a-fA-F]{1,2} # hexadecimal number escape
- )
- |
- [^"] # regular character
- )*
- "
- )
- /x
- ]
-]
-
-def next_token
- skip_whitespace
-
- return false if remaining_input.empty?
-
- SIMPLE_TOKENS.each do |token|
- if remaining_input[0...token.length] == token
- @pos += token.length
- return [token, token]
- end
- end
-
- COMPLEX_TOKENS.each do |type, regexp|
- if remaining_input =~ regexp
- @pos += $&.length
- return [type, $&]
- end
- end
-
- raise SyntaxError, "Unexpected character: #{remaining_input[0..0].inspect}."
-end
-
-def skip_whitespace
- if remaining_input =~ /^[ \t\r\n]+/
- @pos += $&.length
- end
-end
-
-def remaining_input
- @input[@pos..-1]
-end
-
-def on_error(error_token_id, error_value, value_stack)
- raise SyntaxError, "Unexpected token: #{error_value.inspect}."
-end
-...end parser.y/module_eval...
-##### State transition tables begin ###
-
-racc_action_table = [
- 10, 2, 3, 4, 5, 17, 18, 11, 2, 3,
- 4, 5, 2, 3, 4, 5, 9, 14, 15, 19,
- 14, 11 ]
-
-racc_action_check = [
- 6, 0, 0, 0, 0, 12, 12, 6, 11, 11,
- 11, 11, 19, 19, 19, 19, 2, 9, 10, 14,
- 18, 21 ]
-
-racc_action_pointer = [
- -2, nil, 8, nil, nil, nil, 0, nil, nil, 15,
- 18, 5, -4, nil, 8, nil, nil, nil, 18, 9,
- nil, 14 ]
-
-racc_action_default = [
- -13, -4, -5, -10, -11, -12, -13, -1, -3, -13,
- -13, -13, -13, -7, -13, 22, -2, -6, -13, -13,
- -8, -9 ]
-
-racc_goto_table = [
- 6, 13, 16, 12, nil, nil, nil, nil, nil, nil,
- 20, nil, nil, nil, nil, nil, nil, nil, nil, 21 ]
-
-racc_goto_check = [
- 1, 6, 2, 5, nil, nil, nil, nil, nil, nil,
- 6, nil, nil, nil, nil, nil, nil, nil, nil, 1 ]
-
-racc_goto_pointer = [
- nil, 0, -9, nil, nil, -6, -8 ]
-
-racc_goto_default = [
- nil, nil, 7, 8, 1, nil, nil ]
-
-racc_reduce_table = [
- 0, 0, :racc_error,
- 1, 13, :_reduce_none,
- 3, 13, :_reduce_2,
- 1, 14, :_reduce_none,
- 1, 14, :_reduce_none,
- 1, 15, :_reduce_5,
- 4, 15, :_reduce_6,
- 1, 17, :_reduce_none,
- 3, 17, :_reduce_8,
- 3, 18, :_reduce_9,
- 1, 16, :_reduce_10,
- 1, 16, :_reduce_11,
- 1, 16, :_reduce_12 ]
-
-racc_reduce_n = 13
-
-racc_shift_n = 22
-
-racc_token_table = {
- false => 0,
- :error => 1,
- :VAR_NAME => 2,
- :CLASS_NAME => 3,
- :SYMBOL => 4,
- :INTEGER => 5,
- :STRING => 6,
- "|" => 7,
- "<" => 8,
- ">" => 9,
- "," => 10,
- "=" => 11 }
-
-racc_nt_base = 12
-
-racc_use_result_var = true
-
-Racc_arg = [
- racc_action_table,
- racc_action_check,
- racc_action_default,
- racc_action_pointer,
- racc_goto_table,
- racc_goto_check,
- racc_goto_default,
- racc_goto_pointer,
- racc_nt_base,
- racc_reduce_table,
- racc_token_table,
- racc_shift_n,
- racc_reduce_n,
- racc_use_result_var ]
-
-Racc_token_to_s_table = [
- "$end",
- "error",
- "VAR_NAME",
- "CLASS_NAME",
- "SYMBOL",
- "INTEGER",
- "STRING",
- "\"|\"",
- "\"<\"",
- "\">\"",
- "\",\"",
- "\"=\"",
- "$start",
- "expression",
- "primary",
- "node",
- "literal",
- "attrs",
- "attr" ]
-
-Racc_debug_parser = false
-
-##### State transition tables end #####
-
-# reduce 0 omitted
-
-# reduce 1 omitted
-
-module_eval(<<'.,.,', 'parser.y', 14)
- def _reduce_2(val, _values, result)
- result = if val[0].is_a?(ChoiceMatcher)
- ChoiceMatcher.new(val[0].alternatives << val[2])
- else
- ChoiceMatcher.new([val[0], val[2]])
- end
-
- result
- end
-.,.,
-
-# reduce 3 omitted
-
-# reduce 4 omitted
-
-module_eval(<<'.,.,', 'parser.y', 25)
- def _reduce_5(val, _values, result)
- result = NodeMatcher.new(val[0].to_sym)
-
- result
- end
-.,.,
-
-module_eval(<<'.,.,', 'parser.y', 28)
- def _reduce_6(val, _values, result)
- result = NodeMatcher.new(val[0].to_sym, val[2])
-
- result
- end
-.,.,
-
-# reduce 7 omitted
-
-module_eval(<<'.,.,', 'parser.y', 32)
- def _reduce_8(val, _values, result)
- result = val[0].merge(val[2])
- result
- end
-.,.,
-
-module_eval(<<'.,.,', 'parser.y', 34)
- def _reduce_9(val, _values, result)
- result = { val[0].to_sym => val[2] }
- result
- end
-.,.,
-
-module_eval(<<'.,.,', 'parser.y', 36)
- def _reduce_10(val, _values, result)
- result = LiteralMatcher.new(val[0][1..-1].to_sym)
- result
- end
-.,.,
-
-module_eval(<<'.,.,', 'parser.y', 38)
- def _reduce_11(val, _values, result)
- value = if val[0] =~ /^0[bB]/
- val[0][2..-1].to_i(2)
- elsif val[0] =~ /^0[oO]/
- val[0][2..-1].to_i(8)
- elsif val[0] =~ /^0[dD]/
- val[0][2..-1].to_i(10)
- elsif val[0] =~ /^0[xX]/
- val[0][2..-1].to_i(16)
- elsif val[0] =~ /^0/
- val[0][1..-1].to_i(8)
- else
- val[0].to_i
- end
- result = LiteralMatcher.new(value)
-
- result
- end
-.,.,
-
-module_eval(<<'.,.,', 'parser.y', 54)
- def _reduce_12(val, _values, result)
- quote = val[0][0..0]
- value = if quote == "'"
- val[0][1..-2].gsub("\\\\", "\\").gsub("\\'", "'")
- elsif quote == '"'
- val[0][1..-2].
- gsub("\\\\", "\\").
- gsub('\\"', '"').
- gsub("\\n", "\n").
- gsub("\\t", "\t").
- gsub("\\r", "\r").
- gsub("\\f", "\f").
- gsub("\\v", "\v").
- gsub("\\a", "\a").
- gsub("\\e", "\e").
- gsub("\\b", "\b").
- gsub("\\s", "\s").
- gsub(/\\([0-7]{1,3})/) { $1.to_i(8).chr }.
- gsub(/\\x([0-9a-fA-F]{1,2})/) { $1.to_i(16).chr }
- else
- raise "Unknown quote: #{quote.inspect}."
- end
- result = LiteralMatcher.new(value)
-
- result
- end
-.,.,
-
-def _reduce_none(val, _values, result)
- val[0]
-end
-
- end # class Parser
- end # module Machete
View
3  lib/machete/version.rb
@@ -0,0 +1,3 @@
+module Machete
+ VERSION = File.read(File.dirname(__FILE__) + "/../../VERSION").strip
+end
View
28 machete.gemspec
@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+
+require File.expand_path(File.dirname(__FILE__) + "/lib/machete/version")
+
+Gem::Specification.new do |s|
+ s.name = "machete"
+ s.version = Machete::VERSION
+ s.summary = "Simple tool for matching Rubinius AST nodes against patterns"
+ s.description = <<-EOT.split("\n").map(&:strip).join(" ")
+ Machete is a simple tool for matching Rubinius AST nodes against patterns.
+ You can use it if you are writing any kind of tool that processes Ruby code
+ and needs to do some work on specific types of nodes, needs to find patterns
+ in the code, etc.
+ EOT
+
+ s.author = "David Majda"
+ s.email = "dmajda@suse.de"
+ s.homepage = "https://github.com/openSUSE/machete"
+ s.license = "MIT"
+
+ s.files = `git ls-files`.split("\n") + ["lib/machete/parser.rb"]
+
+ s.add_development_dependency "racc"
+ s.add_development_dependency "rspec"
+ s.add_development_dependency "rdoc"
+ s.add_development_dependency "rdiscount"
+ s.add_development_dependency "yard"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.