File: reader/ruby1.8/parser/common.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: TmDoc#10
  module: Reader
  module: Ruby18#12
  module: Parser#14
  module: Common#16
includes
  RubyToken ( Builtin-Module )
has properties
function: get_constant_with_optional_parens / 2 #21
function: get_constant / 2 #51

Code

   1  # $Id: common.rb,v 1.2 2011/11/28 11:06:05 machan Exp $
   2 
   3  require 'tmdoc/tmstd'
   4  require 'tmdoc/constant'
   5  require 'tmdoc/environment'
   6  require 'tmdoc/model/core'
   7  require 'tmdoc/reader/ruby1.8/scanner'
   8 
   9 
  10  module TmDoc
  11 
  12  module Reader::Ruby18
  13 
  14  module Parser
  15 
  16  module Common
  17      include RubyToken
  18 
  19  module_function
  20 
  21      def get_constant_with_optional_parens(scanner, env)
  22          ASSERT.kind_of  scanner,    Scanner
  23          ASSERT.kind_of  env,        ENV::Environment
  24 
  25          LOG::Debug.msgout "CALLED " if env.debug_parser?
  26 
  27          nest = 0
  28          tk = scanner.peek
  29          while tk.kind_of?(TkLPAREN) || tk.kind_of?(TkfLPAREN)
  30              scanner.get!
  31              scanner.skip_space_or_nl!
  32 
  33              nest += 1
  34              tk = scanner.peek
  35          end
  36 
  37          name = get_constant(scanner, env)
  38 
  39          while nest > 0
  40              scanner.skip_space_or_nl!
  41              tk = scanner.get!
  42              if tk.kind_of?(TkRPAREN)
  43                  nest -= 1
  44              end
  45          end
  46 
  47          ASSERT.kind_of name, String
  48      end
  49 
  50 
  51      def get_constant(scanner, env)
  52          ASSERT.kind_of  scanner,    Scanner
  53          ASSERT.kind_of  env,        ENV::Environment
  54 
  55          LOG::Debug.msgout "CALLED " if env.debug_parser?
  56 
  57          name = scanner.get_readed! {
  58              tk = scanner.get!
  59              while tk.kind_of?(TkCOLON2) ||
  60                      tk.kind_of?(TkCOLON3)   ||
  61                      tk.kind_of?(TkCONSTANT)   
  62                  tk = scanner.get!
  63              end
  64              scanner.unget! tk
  65          }
  66          LOG::Debug.log "TkCONSTANT: #{name} " +
  67                              "[##{__LINE__} in " +
  68                              "#{__FILE__}]" if env.debug_parser?
  69 
  70          ASSERT.kind_of name, String
  71      end
  72  end
  73 
  74  end # TmDoc::Reader::Ruby18::Parser
  75 
  76  end # TmDoc::Reader::Ruby18
  77 
  78  end # TmDoc