Module RubyParserStuff
In: lib/ruby_parser_extras.rb

Methods

Classes and Modules

Class RubyParserStuff::Environment
Class RubyParserStuff::Keyword
Class RubyParserStuff::Ruby18Parser
Class RubyParserStuff::Ruby19Parser
Class RubyParserStuff::RubyParser
Class RubyParserStuff::Sexp
Class RubyParserStuff::StackState
Class RubyParserStuff::String

Constants

VERSION = '3.0.1' unless constants.include? "VERSION"

Attributes

canonicalize_conditions  [RW]  Canonicalize conditionals. Eg:
  not x ? a : b

becomes:

  x ? b : a
comments  [R] 
env  [R] 
file  [RW] 
in_def  [RW] 
in_single  [RW] 
lexer  [RW] 

Public Class methods

Public Instance methods

for pure ruby systems only

Returns a UTF-8 encoded string after processing BOMs and magic encoding comments.

Holy crap… ok. Here goes:

Ruby‘s file handling and encoding support is insane. We need to be able to lex a file. The lexer file is explicitly UTF-8 to make things cleaner. This allows us to deal with extended chars in class and method names. In order to do this, we need to encode all input source files as UTF-8. First, we look for a UTF-8 BOM by looking at the first line while forcing its encoding to ASCII-8BIT. If we find a BOM, we strip it and set the expected encoding to UTF-8. Then, we search for a magic encoding comment. If found, it overrides the BOM. Finally, we force the encoding of the input string to whatever was found, and then encode that to UTF-8 for compatibility with the lexer.

parse(str, file = "(string)", time = 10)

Alias for process

Parse str at path file and return a sexp. Raises Timeout::Error if it runs for more than time seconds.

[Validate]