1 #!/usr/bin/ruby 2 # encoding: utf-8 3 require 'antlr3' 4 require 'antlr3/tree' 5 6 module ANTLR3 7 module ASTBuilder 8 extend ClassMacros 9 10 def self.included( klass ) 11 def klass.return_scope_members 12 super.push( :tree ) 13 end 14 end 15 16 def initialize( input, options = {} ) 17 @adaptor = options[ :adaptor ] ||= begin 18 ( input.adaptor rescue nil ) or 19 AST::CommonTreeAdaptor.new( token_class ) 20 end 21 super( input, options ) 22 end 23 24 shared_attribute( :adaptor ) 25 26 private 27 28 def subtree_stream( desc, element = nil ) 29 AST::RewriteRuleSubtreeStream.new( @adaptor, desc, element ) 30 end 31 32 def token_stream( desc, element = nil ) 33 AST::RewriteRuleTokenStream.new( @adaptor, desc, element ) 34 end 35 36 def node_stream( desc, element = nil ) 37 AST::RewriteRuleNodeStream.new( @adaptor, desc, element ) 38 end 39 end 40 end 41