### Home Classes Methods

### In Files

- lib/rdoc/ruby_lex.rb

### Parent

Object

### Namespace

- CLASS RDoc::RubyLex::Error

### Methods

- ::new
- ::tokenize

### Files

- CONTRIBUTING.rdoc
- CVE-2013-0256.rdoc
- ExampleRDoc.rdoc
- LICENSE.rdoc
- Manifest.txt
- README.rdoc
- RI.rdoc
- Rakefile
- TODO.rdoc

### Class/Module Index

Quicksearch

- RDoc
- RDoc::Alias
- RDoc::AnonClass
- RDoc::AnyMethod
- RDoc::Attr
- RDoc::ClassModule
- RDoc::CodeObject
- RDoc::Comment
- RDoc::Constant
- RDoc::Context
- RDoc::Context::Section
- RDoc::CrossReference
- RDoc::ERBIO
- RDoc::ERBPartial
- RDoc::Encoding
- RDoc::Error
- RDoc::Extend
- RDoc::Gauntlet
- RDoc::Generator
- RDoc::Generator::Darkfish
- RDoc::Generator::JsonIndex
- RDoc::Generator::Markup
- RDoc::Generator::RI
- RDoc::GhostMethod
- RDoc::Include
- RDoc::Markdown
- RDoc::Markdown::Literals
- RDoc::Markup
- RDoc::Markup::AttrChanger
- RDoc::Markup::AttrSpan
- RDoc::Markup::AttributeManager
- RDoc::Markup::Attributes
- RDoc::Markup::BlankLine
- RDoc::Markup::BlockQuote
- RDoc::Markup::Document
- RDoc::Markup::Formatter
- RDoc::Markup::FormatterTestCase
- RDoc::Markup::HardBreak
- RDoc::Markup::Include
- RDoc::Markup::IndentedParagraph
- RDoc::Markup::List
- RDoc::Markup::ListItem
- RDoc::Markup::Paragraph
- RDoc::Markup::Parser
- RDoc::Markup::Parser::Error
- RDoc::Markup::Parser::ParseError
- RDoc::Markup::PreProcess
- RDoc::Markup::Raw
- RDoc::Markup::Rule
- RDoc::Markup::Special
- RDoc::Markup::TextFormatterTestCase
- RDoc::Markup::ToAnsi
- RDoc::Markup::ToBs
- RDoc::Markup::ToHtml
- RDoc::Markup::ToHtmlCrossref
- RDoc::Markup::ToHtmlSnippet
- RDoc::Markup::ToJoinedParagraph
- RDoc::Markup::ToLabel
- RDoc::Markup::ToMarkdown
- RDoc::Markup::ToRdoc
- RDoc::Markup::ToTableOfContents
- RDoc::Markup::ToTest
- RDoc::Markup::ToTtOnly
- RDoc::Markup::Verbatim
- RDoc::MetaMethod
- RDoc::MethodAttr
- RDoc::Mixin
- RDoc::NormalClass
- RDoc::NormalModule
- RDoc::Options
- RDoc::Parser
- RDoc::Parser::C
- RDoc::Parser::ChangeLog
- RDoc::Parser::Markdown
- RDoc::Parser::RD
- RDoc::Parser::Ruby
- RDoc::Parser::RubyTools
- RDoc::Parser::Simple
- RDoc::Parser::Text
- RDoc::RD
- RDoc::RD::BlockParser
- RDoc::RD::Inline
- RDoc::RD::InlineParser
- RDoc::RDoc
- RDoc::RI
- RDoc::RI::Driver
- RDoc::RI::Driver::Error
- RDoc::RI::Driver::NotFoundError
- RDoc::RI::Error
- RDoc::RI::Paths
- RDoc::Require
- RDoc::RubyLex
- RDoc::RubyLex::Error
- RDoc::RubyToken
- RDoc::RubygemsHook
- RDoc::Servlet
- RDoc::SingleClass
- RDoc::Stats
- RDoc::Stats::Normal
- RDoc::Stats::Quiet
- RDoc::Stats::Verbose
- RDoc::Store
- RDoc::Store::Error
- RDoc::Store::MissingFileError
- RDoc::Task
- RDoc::Task
- RDoc::TestCase
- RDoc::TokenStream
- RDoc::TomDoc
- RDoc::TopLevel
- Object

No matching classes.

# RDoc::RubyLex

Ruby lexer adapted from irb.

The internals are not documented because they are scary.

### Public Class Methods

new(content, options) click to toggle source

Creates a new lexer for `content`. `options` is an RDoc::Options, only +tab_width is used.

    # File lib/rdoc/ruby_lex.rb, line 81
    def initialize(content, options)
      lex_init

      if /\t/ =~ content then
        tab_width = options.tab_width
        content = content.split(/\n/).map do |line|
          1 while line.gsub!(/\t+/) {
            ' ' * (tab_width*$&.length - $`.length % tab_width)
          }  && $~
          line
        end.join("\n")
      end

      content << "\n" unless content[-1, 1] == "\n"

      set_input StringIO.new content

      @base_char_no = 0
      @char_no = 0
      @exp_line_no = @line_no = 1
      @here_readed = []
      @readed = []
      @rests = []
      @seek = 0

      @here_header = false
      @indent = 0
      @indent_stack = []
      @lex_state = :EXPR_BEG
      @space_seen = false

      @continue = false
      @line = ""

      @skip_space = false
      @readed_auto_clean_up = false
      @exception_on_syntax_error = true

      @prompt = nil
      @prev_seek = nil
      @ltype = nil
    end

tokenize(ruby, options) click to toggle source

Returns an Array of `ruby` tokens. See ::new for a description of `options`.

    # File lib/rdoc/ruby_lex.rb, line 64
    def self.tokenize ruby, options
      tokens = []

      scanner = RDoc::RubyLex.new ruby, options
      scanner.exception_on_syntax_error = true

      while token = scanner.token do
        tokens << token
      end

      tokens
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.