# ruby_parser-3.2.2 Documentation

home | github.com/seattlerb/ruby_parser
bugs | github.com/seattlerb/ruby_parser/issues
rdoc | docs.seattlerb.org/ruby_parser

## DESCRIPTION:

ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which does by default use a C extension). RP's output is the same as ParseTree's output: s-expressions using ruby's arrays and base types.

As an example:

    def conditional1 arg1
      return 1 if arg1 == 0
      return 0
    end

becomes:

    s(:defn, :conditional1, s(:args, :arg1),
      s(:if,
        s(:call, s(:lvar, :arg1), :==, s(:lit, 0)),
        s(:return, s(:lit, 1)),
        nil),
      s(:return, s(:lit, 0)))

Tested against 801,039 files from the latest of all rubygems (as of 2013-05):

- 1.8 parser is at 99.9739% accuracy, 3.651 sigma

- 1.9 parser is at 99.9940% accuracy, 4.013 sigma

- 2.0 parser is at 99.9939% accuracy, 4.008 sigma

## FEATURES/PROBLEMS:

- Pure ruby, no compiles.

- Includes preceding comment data for defn/defs/class/module nodes!

- Incredibly simple interface.

- Output is 100% equivalent to ParseTree.

  - Can utilize PT's SexpProcessor and UnifiedRuby for language processing.

- Known Issue: Speed is now pretty good, but can always improve:

  - RP parses a corpus of 3702 files in 125s (avg 108 Kb/s)

  - MRI+PT parsed the same in 67.38s (avg 200.89 Kb/s)

- Known Issue: Code is much better, but still has a long way to go.

- Known Issue: Totally awesome.

- Known Issue: line number values can be slightly off. Parsing LR sucks.

## SYNOPSIS:

    RubyParser.new.parse "1+1"
    # => s(:call, s(:lit, 1), :+, s(:lit, 1))

You can also use Ruby19Parser, Ruby18Parser, or RubyParser.for_current_ruby:

    RubyParser.for_current_ruby.parse "1+1"
    # => s(:call, s(:lit, 1), :+, s(:lit, 1))

## REQUIREMENTS:

- ruby. woot.

- sexp_processor for Sexp and SexpProcessor classes, and testing.

- racc full package for parser development (compiling .y to .rb).

## INSTALL:

- sudo gem install ruby_parser

## LICENSE:

(The MIT License)

Copyright (c) Ryan Davis, seattle.rb

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Files

- Manifest.txt
- README.txt

## Classes/Modules

- RubyParserStuff
- RubyParserStuff::Environment
- RubyParserStuff::Keyword
- RubyParserStuff::Keyword::KWtable
- RubyParserStuff::Ruby18Parser
- RubyParserStuff::Ruby19Parser
- RubyParserStuff::Ruby20Parser
- RubyParserStuff::RubyParser
- RubyParserStuff::RubyParser::SyntaxError
- RubyParserStuff::Sexp
- RubyParserStuff::StackState
- RubyParserStuff::String
- RPStringScanner
- Ruby18Parser
- Ruby19Parser
- Ruby20Parser
- RubyLexer
- RubyParserGauntlet

## Methods

- ::for_current_ruby — RubyParserStuff::RubyParser
- ::keyword18 — RubyParserStuff::Keyword
- ::keyword19 — RubyParserStuff::Keyword
- ::new — RubyParserGauntlet
- ::new — RubyParserStuff::Keyword::KWtable
- ::new — RubyLexer
- ::new — RubyParserStuff::Environment
- ::new — RubyParserStuff::StackState
- ::new — RubyParserStuff
- ::new — RubyParserStuff::RubyParser
- #[] — RubyParserStuff::Environment
- #[]= — RubyParserStuff::Environment
- #add — RubyParserStuff::Sexp
- #add_all — RubyParserStuff::Sexp
- #advance — RubyLexer
- #all — RubyParserStuff::Environment
- #arg_add — RubyParserStuff
- #arg_ambiguous — RubyLexer
- #arg_blk_pass — RubyParserStuff
- #arg_concat — RubyParserStuff
- #argl — RubyParserStuff
- #args — RubyParserStuff
- #array_to_hash — RubyParserStuff
- #aryset — RubyParserStuff
- #assignable — RubyParserStuff
- #backref_assign_error — RubyParserStuff
- #block_append — RubyParserStuff
- #block_dup_check — RubyParserStuff
- #block_pass? — RubyParserStuff::Sexp
- #block_var — RubyParserStuff
- #block_var18 — RubyParserStuff
- #broke — RubyParserGauntlet
- #call_args — RubyParserStuff
- #charpos — RPStringScanner
- #clean_mlhs — RubyParserStuff
- #comments — RubyLexer
- #cond — RubyParserStuff
- #current — RubyParserStuff::Environment
- #current_line — RPStringScanner
- #d — RPStringScanner
- #debug20 — RubyParserStuff
- #diff_pp — RubyParserGauntlet
- #do_parse — RubyParserStuff
- #dynamic — RubyParserStuff::Environment
- #dynamic? — RubyParserStuff::Environment
- #expr_beg_push — RubyLexer
- #extend — RubyParserStuff::Environment
- #extra_lines_added — RPStringScanner
- #extra_lines_added= — RPStringScanner
- #fix_arg_lex_state — RubyLexer
- #get_match_node — RubyParserStuff
- #getch — RPStringScanner
- #gettable — RubyParserStuff
- #grep — RubyParserStuff::String
- #hack_encoding — RubyParserStuff
- #handle_encoding — RubyParserStuff
- #heredoc — RubyLexer
- #heredoc_identifier — RubyLexer
- #in_lex_state? — RubyLexer
- #inspect — RubyParserStuff::StackState
- #int_with_base — RubyLexer
- #is_arg? — RubyLexer
- #is_beg? — RubyLexer
- #is_end? — RubyLexer
- #is_in_state — RubyParserStuff::StackState
- #is_label_possible? — RubyLexer
- #is_space_arg? — RubyLexer
- #lex_state= — RubyLexer
- #lexpop — RubyParserStuff::StackState
- #lineno — RubyLexer
- #lineno — RPStringScanner
- #list_append — RubyParserStuff
- #list_prepend — RubyParserStuff
- #literal_concat — RubyParserStuff
- #logop — RubyParserStuff
- #new_aref — RubyParserStuff
- #new_body — RubyParserStuff
- #new_call — RubyParserStuff
- #new_case — RubyParserStuff
- #new_class — RubyParserStuff
- #new_compstmt — RubyParserStuff
- #new_defn — RubyParserStuff
- #new_defs — RubyParserStuff
- #new_for — RubyParserStuff
- #new_if — RubyParserStuff
- #new_iter — RubyParserStuff
- #new_masgn — RubyParserStuff
- #new_module — RubyParserStuff
- #new_op_asgn — RubyParserStuff
- #new_regexp — RubyParserStuff
- #new_resbody — RubyParserStuff
- #new_sclass — RubyParserStuff
- #new_super — RubyParserStuff
- #new_undef — RubyParserStuff
- #new_until — RubyParserStuff
- #new_until_or_while — RubyParserStuff
- #new_when — RubyParserStuff
- #new_while — RubyParserStuff
- #new_xstring — RubyParserStuff
- #new_yield — RubyParserStuff
- #next_token — RubyParserStuff
- #node_assign — RubyParserStuff
- #old_getch — RPStringScanner
- #old_scan — RPStringScanner
- #on_error — RubyParserStuff
- #paren — RubyParserStuff::Sexp
- #parse — RubyParserStuff::RubyParser
- #parse_number — RubyLexer
- #parse_quote — RubyLexer
- #parse_string — RubyLexer
- #pop — RubyParserStuff::StackState
- #process — RubyParserStuff
- #process — RubyParserStuff::RubyParser
- #process — RubyParserGauntlet
- #process_token — RubyLexer
- #push — RubyParserStuff::StackState
- #rb_compile_error — RubyLexer
- #read_escape — RubyLexer
- #regx_options — RubyLexer
- #remove_begin — RubyParserStuff
- #reset — RubyParserStuff::Environment
- #reset — RubyParserStuff::RubyParser
- #reset — RubyLexer
- #reset — RubyParserStuff
- #ret_args — RubyParserStuff
- #ruby18 — RubyLexer
- #ruby19 — RubyLexer
- #run — RubyParserGauntlet
- #s — RubyParserStuff
- #scan — RPStringScanner
- #should_skip? — RubyParserGauntlet
- #src= — RubyLexer
- #string_to_pos — RPStringScanner
- #syntax_error — RubyParserStuff
- #to_sym — RubyParserStuff::Sexp
- #tokadd_escape — RubyLexer
- #tokadd_string — RubyLexer
- #unescape — RubyLexer
- #unextend — RubyParserStuff::Environment
- #unread_many — RPStringScanner
- #use — RubyParserStuff::Environment
- #used? — RubyParserStuff::Environment
- #value — RubyParserStuff::Sexp
- #value_expr — RubyParserStuff
- #void_stmts — RubyParserStuff
- #warning — RubyParserStuff
- #warning — RubyLexer
- #yylex — RubyLexer
- #yylex_paren18 — RubyLexer
- #yylex_paren19 — RubyLexer
- #yylex_string — RubyLexer

[Validate]

Generated with the Darkfish Rdoc Generator 2.