Class: Ripper::TokenPattern

Inherits:
Object show all
Defined in:
lib/ripper/lexer.rb

Overview

:nodoc:

Defined Under Namespace

Classes: CompileError, Error, MatchData, MatchError

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ TokenPattern

Returns a new instance of TokenPattern.



137
138
139
140
# File 'lib/ripper/lexer.rb', line 137

def initialize(pattern)
  @source = pattern
  @re = compile(pattern)
end

Instance Method Details

#match(str) ⇒ Object



142
143
144
# File 'lib/ripper/lexer.rb', line 142

def match(str)
  match_list(::Ripper.lex(str))
end

#match_list(tokens) ⇒ Object



146
147
148
149
150
151
# File 'lib/ripper/lexer.rb', line 146

def match_list(tokens)
  if m = @re.match(map_tokens(tokens))
  then MatchData.new(tokens, m)
  else nil
  end
end