[macruby-changes] [4014] MacRuby/trunk/lib/rdoc
source_changes at macosforge.org
source_changes at macosforge.org
Mon May 3 17:31:30 PDT 2010
Revision: 4014
http://trac.macosforge.org/projects/ruby/changeset/4014
Author: martinlagardette at apple.com
Date: 2010-05-03 17:31:27 -0700 (Mon, 03 May 2010)
Log Message:
-----------
Adding the old IRB lexer in RDoc directory, otherwise RDoc doens't compile
Modified Paths:
--------------
MacRuby/trunk/lib/rdoc/parser/ruby.rb
Added Paths:
-----------
MacRuby/trunk/lib/rdoc/lex/
MacRuby/trunk/lib/rdoc/lex/README.txt
MacRuby/trunk/lib/rdoc/lex/notifier.rb
MacRuby/trunk/lib/rdoc/lex/output-method.rb
MacRuby/trunk/lib/rdoc/lex/slex.rb
Added: MacRuby/trunk/lib/rdoc/lex/README.txt
===================================================================
--- MacRuby/trunk/lib/rdoc/lex/README.txt (rev 0)
+++ MacRuby/trunk/lib/rdoc/lex/README.txt 2010-05-04 00:31:27 UTC (rev 4014)
@@ -0,0 +1,3 @@
+As of MacRuby 0.7, IRB has been replaced by DietRB. However, RDoc uses the
+lexer defined in IRB, so this directory has been added to include the IRB lexer
+files RDoc requires.
\ No newline at end of file
Added: MacRuby/trunk/lib/rdoc/lex/notifier.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/lex/notifier.rb (rev 0)
+++ MacRuby/trunk/lib/rdoc/lex/notifier.rb 2010-05-04 00:31:27 UTC (rev 4014)
@@ -0,0 +1,144 @@
+#
+# notifier.rb - output methods used by irb
+# $Release Version: 0.9.5$
+# $Revision: 16810 $
+# by Keiju ISHITSUKA(keiju at ruby-lang.org)
+#
+# --
+#
+#
+#
+
+require "e2mmap"
+require "rdoc/lex/output-method"
+
+module IRB
+ module Notifier
+ extend Exception2MessageMapper
+ def_exception :ErrUndefinedNotifier,
+ "undefined notifier level: %d is specified"
+ def_exception :ErrUnrecognizedLevel,
+ "unrecognized notifier level: %s is specified"
+
+ def def_notifier(prefix = "", output_method = StdioOutputMethod.new)
+ CompositeNotifier.new(prefix, output_method)
+ end
+ module_function :def_notifier
+
+ class AbstructNotifier
+ def initialize(prefix, base_notifier)
+ @prefix = prefix
+ @base_notifier = base_notifier
+ end
+
+ attr_reader :prefix
+
+ def notify?
+ true
+ end
+
+ def print(*opts)
+ @base_notifier.print prefix, *opts if notify?
+ end
+
+ def printn(*opts)
+ @base_notifier.printn prefix, *opts if notify?
+ end
+
+ def printf(format, *opts)
+ @base_notifier.printf(prefix + format, *opts) if notify?
+ end
+
+ def puts(*objs)
+ if notify?
+ @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
+ end
+ end
+
+ def pp(*objs)
+ if notify?
+ @base_notifier.ppx @prefix, *objs
+ end
+ end
+
+ def ppx(prefix, *objs)
+ if notify?
+ @base_notifier.ppx @prefix+prefix, *objs
+ end
+ end
+
+ def exec_if
+ yield(@base_notifier) if notify?
+ end
+ end
+
+ class CompositeNotifier<AbstructNotifier
+ def initialize(prefix, base_notifier)
+ super
+
+ @notifiers = [D_NOMSG]
+ @level_notifier = D_NOMSG
+ end
+
+ attr_reader :notifiers
+
+ def def_notifier(level, prefix = "")
+ notifier = LeveledNotifier.new(self, level, prefix)
+ @notifiers[level] = notifier
+ notifier
+ end
+
+ attr_reader :level_notifier
+ alias level level_notifier
+
+ def level_notifier=(value)
+ case value
+ when AbstructNotifier
+ @level_notifier = value
+ when Integer
+ l = @notifiers[value]
+ Notifier.Raise ErrUndefinedNotifer, value unless l
+ @level_notifier = l
+ else
+ Notifier.Raise ErrUnrecognizedLevel, value unless l
+ end
+ end
+
+ alias level= level_notifier=
+ end
+
+ class LeveledNotifier<AbstructNotifier
+ include Comparable
+
+ def initialize(base, level, prefix)
+ super(prefix, base)
+
+ @level = level
+ end
+
+ attr_reader :level
+
+ def <=>(other)
+ @level <=> other.level
+ end
+
+ def notify?
+ @base_notifier.level >= self
+ end
+ end
+
+ class NoMsgNotifier<LeveledNotifier
+ def initialize
+ @base_notifier = nil
+ @level = 0
+ @prefix = ""
+ end
+
+ def notify?
+ false
+ end
+ end
+
+ D_NOMSG = NoMsgNotifier.new
+ end
+end
Added: MacRuby/trunk/lib/rdoc/lex/output-method.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/lex/output-method.rb (rev 0)
+++ MacRuby/trunk/lib/rdoc/lex/output-method.rb 2010-05-04 00:31:27 UTC (rev 4014)
@@ -0,0 +1,69 @@
+#
+# output-method.rb - optput methods used by irb
+# $Release Version: 0.9.5$
+# $Revision: 14912 $
+# by Keiju ISHITSUKA(keiju at ruby-lang.org)
+#
+# --
+#
+#
+#
+
+require "e2mmap"
+
+module IRB
+ # OutputMethod
+ # StdioOutputMethod
+
+ class OutputMethod
+ @RCS_ID='-$Id: output-method.rb 14912 2008-01-06 15:49:38Z akr $-'
+
+ def print(*opts)
+ IRB.fail NotImplementError, "print"
+ end
+
+ def printn(*opts)
+ print opts.join(" "), "\n"
+ end
+
+ # extend printf
+ def printf(format, *opts)
+ if /(%*)%I/ =~ format
+ format, opts = parse_printf_format(format, opts)
+ end
+ print sprintf(format, *opts)
+ end
+
+ # %
+ # <flag> [#0- +]
+ # <minimum field width> (\*|\*[1-9][0-9]*\$|[1-9][0-9]*)
+ # <precision>.(\*|\*[1-9][0-9]*\$|[1-9][0-9]*|)?
+ # #<length modifier>(hh|h|l|ll|L|q|j|z|t)
+ # <conversion specifier>[diouxXeEfgGcsb%]
+ def parse_printf_format(format, opts)
+ return format, opts if $1.size % 2 == 1
+ end
+
+ def puts(*objs)
+ for obj in objs
+ print(*obj)
+ print "\n"
+ end
+ end
+
+ def pp(*objs)
+ puts(*objs.collect{|obj| obj.inspect})
+ end
+
+ def ppx(prefix, *objs)
+ puts(*objs.collect{|obj| prefix+obj.inspect})
+ end
+
+ end
+
+ class StdioOutputMethod<OutputMethod
+ def print(*opts)
+ STDOUT.print(*opts)
+ end
+ end
+end
Added: MacRuby/trunk/lib/rdoc/lex/slex.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/lex/slex.rb (rev 0)
+++ MacRuby/trunk/lib/rdoc/lex/slex.rb 2010-05-04 00:31:27 UTC (rev 4014)
@@ -0,0 +1,282 @@
+#
+# irb/slex.rb - simple lex analyzer
+# $Release Version: 0.9.5$
+# $Revision: 16810 $
+# by Keiju ISHITSUKA(keiju at ruby-lang.org)
+#
+# --
+#
+#
+#
+
+require "e2mmap"
+require "rdoc/lex/notifier"
+
+module IRB
+ class SLex
+ @RCS_ID='-$Id: slex.rb 16810 2008-06-04 09:37:38Z matz $-'
+
+ extend Exception2MessageMapper
+ def_exception :ErrNodeNothing, "node nothing"
+ def_exception :ErrNodeAlreadyExists, "node already exists"
+
+ DOUT = Notifier::def_notifier("SLex::")
+ D_WARN = DOUT::def_notifier(1, "Warn: ")
+ D_DEBUG = DOUT::def_notifier(2, "Debug: ")
+ D_DETAIL = DOUT::def_notifier(4, "Detail: ")
+
+ DOUT.level = Notifier::D_NOMSG
+
+ def initialize
+ @head = Node.new("")
+ end
+
+ def def_rule(token, preproc = nil, postproc = nil, &block)
+ D_DETAIL.pp token
+
+ postproc = block if block_given?
+ node = create(token, preproc, postproc)
+ end
+
+ def def_rules(*tokens, &block)
+ if block_given?
+ p = block
+ end
+ for token in tokens
+ def_rule(token, nil, p)
+ end
+ end
+
+ def preproc(token, proc)
+ node = search(token)
+ node.preproc=proc
+ end
+
+ #要チェック?
+ def postproc(token)
+ node = search(token, proc)
+ node.postproc=proc
+ end
+
+ def search(token)
+ @head.search(token.split(//))
+ end
+
+ def create(token, preproc = nil, postproc = nil)
+ @head.create_subnode(token.split(//), preproc, postproc)
+ end
+
+ def match(token)
+ case token
+ when Array
+ when String
+ return match(token.split(//))
+ else
+ return @head.match_io(token)
+ end
+ ret = @head.match(token)
+ D_DETAIL.exec_if{D_DEATIL.printf "match end: %s:%s\n", ret, token.inspect}
+ ret
+ end
+
+ def inspect
+ format("<SLex: @head = %s>", @head.inspect)
+ end
+
+ #----------------------------------------------------------------------
+ #
+ # class Node -
+ #
+ #----------------------------------------------------------------------
+ class Node
+ # if postproc is nil, this node is an abstract node.
+ # if postproc is non-nil, this node is a real node.
+ def initialize(preproc = nil, postproc = nil)
+ @Tree = {}
+ @preproc = preproc
+ @postproc = postproc
+ end
+
+ attr_accessor :preproc
+ attr_accessor :postproc
+
+ def search(chrs, opt = nil)
+ return self if chrs.empty?
+ ch = chrs.shift
+ if node = @Tree[ch]
+ node.search(chrs, opt)
+ else
+ if opt
+ chrs.unshift ch
+ self.create_subnode(chrs)
+ else
+ SLex.fail ErrNodeNothing
+ end
+ end
+ end
+
+ def create_subnode(chrs, preproc = nil, postproc = nil)
+ if chrs.empty?
+ if @postproc
+ D_DETAIL.pp node
+ SLex.fail ErrNodeAlreadyExists
+ else
+ D_DEBUG.puts "change abstract node to real node."
+ @preproc = preproc
+ @postproc = postproc
+ end
+ return self
+ end
+
+ ch = chrs.shift
+ if node = @Tree[ch]
+ if chrs.empty?
+ if node.postproc
+ DebugLogger.pp node
+ DebugLogger.pp self
+ DebugLogger.pp ch
+ DebugLogger.pp chrs
+ SLex.fail ErrNodeAlreadyExists
+ else
+ D_WARN.puts "change abstract node to real node"
+ node.preproc = preproc
+ node.postproc = postproc
+ end
+ else
+ node.create_subnode(chrs, preproc, postproc)
+ end
+ else
+ if chrs.empty?
+ node = Node.new(preproc, postproc)
+ else
+ node = Node.new
+ node.create_subnode(chrs, preproc, postproc)
+ end
+ @Tree[ch] = node
+ end
+ node
+ end
+
+ #
+ # chrs: String
+ # character array
+ # io must have getc()/ungetc(); and ungetc() must be
+ # able to be called arbitrary number of times.
+ #
+ def match(chrs, op = "")
+ D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
+ if chrs.empty?
+ if @preproc.nil? || @preproc.call(op, chrs)
+ DOUT.printf(D_DETAIL, "op1: %s\n", op)
+ @postproc.call(op, chrs)
+ else
+ nil
+ end
+ else
+ ch = chrs.shift
+ if node = @Tree[ch]
+ if ret = node.match(chrs, op+ch)
+ return ret
+ else
+ chrs.unshift ch
+ if @postproc and @preproc.nil? || @preproc.call(op, chrs)
+ DOUT.printf(D_DETAIL, "op2: %s\n", op.inspect)
+ ret = @postproc.call(op, chrs)
+ return ret
+ else
+ return nil
+ end
+ end
+ else
+ chrs.unshift ch
+ if @postproc and @preproc.nil? || @preproc.call(op, chrs)
+ DOUT.printf(D_DETAIL, "op3: %s\n", op)
+ @postproc.call(op, chrs)
+ return ""
+ else
+ return nil
+ end
+ end
+ end
+ end
+
+ def match_io(io, op = "")
+ if op == ""
+ ch = io.getc
+ if ch == nil
+ return nil
+ end
+ else
+ ch = io.getc_of_rests
+ end
+ if ch.nil?
+ if @preproc.nil? || @preproc.call(op, io)
+ D_DETAIL.printf("op1: %s\n", op)
+ @postproc.call(op, io)
+ else
+ nil
+ end
+ else
+ if node = @Tree[ch]
+ if ret = node.match_io(io, op+ch)
+ ret
+ else
+ io.ungetc ch
+ if @postproc and @preproc.nil? || @preproc.call(op, io)
+ DOUT.exec_if{D_DETAIL.printf "op2: %s\n", op.inspect}
+ @postproc.call(op, io)
+ else
+ nil
+ end
+ end
+ else
+ io.ungetc ch
+ if @postproc and @preproc.nil? || @preproc.call(op, io)
+ D_DETAIL.printf("op3: %s\n", op)
+ @postproc.call(op, io)
+ else
+ nil
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+if $0 == __FILE__
+ # Tracer.on
+ case $1
+ when "1"
+ tr = SLex.new
+ print "0: ", tr.inspect, "\n"
+ tr.def_rule("=") {print "=\n"}
+ print "1: ", tr.inspect, "\n"
+ tr.def_rule("==") {print "==\n"}
+ print "2: ", tr.inspect, "\n"
+
+ print "case 1:\n"
+ print tr.match("="), "\n"
+ print "case 2:\n"
+ print tr.match("=="), "\n"
+ print "case 3:\n"
+ print tr.match("=>"), "\n"
+
+ when "2"
+ tr = SLex.new
+ print "0: ", tr.inspect, "\n"
+ tr.def_rule("=") {print "=\n"}
+ print "1: ", tr.inspect, "\n"
+ tr.def_rule("==", proc{false}) {print "==\n"}
+ print "2: ", tr.inspect, "\n"
+
+ print "case 1:\n"
+ print tr.match("="), "\n"
+ print "case 2:\n"
+ print tr.match("=="), "\n"
+ print "case 3:\n"
+ print tr.match("=>"), "\n"
+ end
+ exit
+end
+
Modified: MacRuby/trunk/lib/rdoc/parser/ruby.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/parser/ruby.rb 2010-05-03 23:45:39 UTC (rev 4013)
+++ MacRuby/trunk/lib/rdoc/parser/ruby.rb 2010-05-04 00:31:27 UTC (rev 4014)
@@ -8,7 +8,7 @@
#
require 'e2mmap'
-require 'irb/slex'
+require 'rdoc/lex/slex'
require 'rdoc/code_objects'
require 'rdoc/tokenstream'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100503/79d5e52f/attachment-0001.html>
More information about the macruby-changes
mailing list