Skip to content

Commit

Permalink
Removed ruby_parser.rb from manifest and worked into package rule ins…
Browse files Browse the repository at this point in the history
…tead.

Wrote README.txt content.
Fixed up Rakefile.
Polished up dead code and other crap.
Various small fixes for really small bugs.
Disabled NilClass#method_missing lest Kevin Clark hack my blog via my ipod.

[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 3716]
  • Loading branch information
zenspider committed Dec 20, 2007
1 parent 65f3999 commit 2749468
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 289 deletions.
2 changes: 1 addition & 1 deletion History.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
== 1.0.0 / 2007-11-14
== 1.0.0 / 2007-12-20

* 1 major enhancement
* Birthday!
Expand Down
2 changes: 1 addition & 1 deletion Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.autotest
History.txt
Manifest.txt
README.txt
Rakefile
lib/ruby_lexer.rb
lib/ruby_parser.rb
lib/ruby_parser.y
test/test_ruby_lexer.rb
test/test_ruby_parser.rb
38 changes: 27 additions & 11 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
RubyParser
by FIX (your name)
FIX (url)
ruby_parser
by Ryan Davis
http://parsetree.rubyforge.org/

== DESCRIPTION:

FIX (describe your package)

ruby_parser (RP) is a ruby parser written in pure ruby (utilizing
racc--which does by default use a C extension). RP's output is
the same as ParseTree's output: s-expressions using ruby's arrays and
base types.

== FEATURES/PROBLEMS:

* FIX (list of features or problems)

* Pure ruby, no compiles.
* Incredibly simple interface.
* Output is 100% equivalent to ParseTree.
* Can utilize PT's SexpProcessor and UnifiedRuby for language processing.
* Known Issue: Speed sucks currently. 5500 tests currently run in 21 min.
* Known Issue: Code is waaay ugly. Port of a port. Not my fault. Will fix RSN.
* Known Issue: I don't currently support newline nodes.
* Known Issue: Totally awesome.
* Known Issue: dasgn_curr decls can be out of order from ParseTree's.
* TODO: Add comment nodes.

== SYNOPSIS:

FIX (code sample of usage)
RubyParser.new.parse "1+1"
# => s(:call, s(:lit, 1), :+, s(:array, s(:lit, 1)))

== REQUIREMENTS:

* FIX (list of requirements)
* ruby. woot.
* ParseTree is needed for Sexp class... crap. I might break that out.
* ParseTree for testing.
* racc full package for parser development.

== INSTALL:

* FIX (sudo gem install, anything else)
* sudo gem install ruby_parser

== LICENSE:

(The MIT License)

Copyright (c) 2007 FIX
Copyright (c) 2007 Ryan Davis

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
24 changes: 16 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ require 'rubygems'
require 'hoe'
require './lib/ruby_lexer.rb'

Hoe.new('RubyParser', RubyParser::VERSION) do |p|
p.rubyforge_name = 'ruby_parser'
hoe = Hoe.new('ruby_parser', RubyParser::VERSION) do |p|
p.rubyforge_name = 'parsetree'
p.author = 'Ryan Davis'
p.email = 'ryand-ruby@zenspider.com'
p.summary = 'FIX'
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
p.summary = p.paragraphs_of('README.txt', 2).join("\n\n")
p.description = p.paragraphs_of('README.txt', 2..6).join("\n\n")
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[-1]
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
p.extra_deps << 'ParseTree'
end

hoe.spec.files += ['lib/ruby_parser.rb'] # jim.... cmon man

module Rake::TaskManager
def all_tasks
@tasks
Expand All @@ -23,13 +26,19 @@ end
Rake.application.all_tasks["default"].prerequisites.clear

task :default => :parser

task :test => :parser

path = "pkg/ruby_parser-#{RubyParser::VERSION}"
task path => :parser do
Dir.chdir path do
sh "rake parser"
end
end

task :parser => ["lib/ruby_parser.rb"]

rule '.rb' => '.y' do |t|
sh "racc -c -v -g --no-extentions -o #{t.name} #{t.source}"
sh "racc -g -o #{t.name} #{t.source}"
end

task :clean do
Expand All @@ -44,5 +53,4 @@ end
# t.test_files = FileList['test/test_ruby_lexer.rb']
# end


# vim: syntax=Ruby
40 changes: 24 additions & 16 deletions lib/ruby_lexer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require 'pp'
require 'stringio'
require 'racc/parser'

$: << File.expand_path("~/Work/p4/zss/src/ParseTree/dev/lib")
$: << File.expand_path("~/Work/p4/zss/src/ParseTree/dev/lib") # for me, not you.
require 'sexp'

############################################################
Expand Down Expand Up @@ -151,6 +150,13 @@ def node_assign(lhs, rhs)
lhs << rhs
when :attrasgn, :call then
args = lhs.array(true) || lhs.argscat(true) || lhs.splat(true) # FIX: fragile
# args = case lhs[1][1]
# when :array, :argscat, :splat then
# lhs.delete_at 1
# else
# nil # TODO: check - no clue what it should be, or even if
# end

lhs << arg_add(args, rhs)
end

Expand Down Expand Up @@ -303,6 +309,7 @@ def get_match_node lhs, rhs

def cond node
return nil if node.nil?
node = value_expr node

case node.first
when :dregex then
Expand Down Expand Up @@ -417,15 +424,15 @@ def ret_args node
end

node = node.last if node[0] == :array && node.size == 2
node = s(:svalue, node) if node[0] == :splat
node = s(:svalue, node) if node[0] == :splat and not node.paren # HACK matz wraps ONE of the FOUR splats in a newline to distinguish. I use paren for now. ugh
end

node
end

def value_expr node # HACK
node = remove_begin node
node[2] = value_expr(node[2]) if node[0] == :if
node[2] = value_expr(node[2]) if node and node[0] == :if
node
end

Expand Down Expand Up @@ -2144,7 +2151,8 @@ def parse_number c

self.yacc_value = token_buffer.join.to_i(10)
return :tINTEGER
when /[0-7_]/ then # octal
when /o/i, /[0-7_]/ then # octal
c = src.read if c =~ /o/i # prefixed octal - kill me
loop do
if c == '_' then
break if (nondigit != "\0")
Expand Down Expand Up @@ -2727,17 +2735,17 @@ def bitch
warn "bitch: you shouldn't be doing #{m}: from #{c[1]}"
end

class NilClass
def method_missing msg, *args
c = caller
warn "called #{msg} on nil (args = #{args.inspect}): from #{c[0]}"
nil
end
end

def d s # HACK
warn s.inspect
end
# class NilClass
# def method_missing msg, *args
# c = caller
# warn "called #{msg} on nil (args = #{args.inspect}): from #{c[0]}"
# nil
# end
# end

# def d s
# warn s.inspect
# end

# END HACK
############################################################
Loading

0 comments on commit 2749468

Please sign in to comment.