1#
2# $Id: core.rb 36954 2012-09-12 23:04:41Z zzak $
3#
4# Copyright (c) 2003-2005 Minero Aoki
5#
6# This program is free software.
7# You can distribute and/or modify this program under the Ruby License.
8# For details of Ruby License, see ruby/COPYING.
9#
10
11require 'ripper.so'
12
13class Ripper
14
15  # Parses the given Ruby program read from +src+.
16  # +src+ must be a String or an IO or a object with a #gets method.
17  def Ripper.parse(src, filename = '(ripper)', lineno = 1)
18    new(src, filename, lineno).parse
19  end
20
21  # This array contains name of parser events.
22  PARSER_EVENTS = PARSER_EVENT_TABLE.keys
23
24  # This array contains name of scanner events.
25  SCANNER_EVENTS = SCANNER_EVENT_TABLE.keys
26
27  # This array contains name of all ripper events.
28  EVENTS = PARSER_EVENTS + SCANNER_EVENTS
29
30  private
31
32  #
33  # Parser Events
34  #
35
36  PARSER_EVENT_TABLE.each do |id, arity|
37    module_eval(<<-End, __FILE__, __LINE__ + 1)
38      def on_#{id}(#{ ('a'..'z').to_a[0, arity].join(', ') })
39        #{arity == 0 ? 'nil' : 'a'}
40      end
41    End
42  end
43
44  # This method is called when weak warning is produced by the parser.
45  # +fmt+ and +args+ is printf style.
46  def warn(fmt, *args)
47  end
48
49  # This method is called when strong warning is produced by the parser.
50  # +fmt+ and +args+ is printf style.
51  def warning(fmt, *args)
52  end
53
54  # This method is called when the parser found syntax error.
55  def compile_error(msg)
56  end
57
58  #
59  # Scanner Events
60  #
61
62  SCANNER_EVENTS.each do |id|
63    module_eval(<<-End, __FILE__, __LINE__ + 1)
64      def on_#{id}(token)
65        token
66      end
67    End
68  end
69
70end
71