Class: Ripper::TokenPattern

Inherits:
Object
  • 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.



225
226
227
228
# File 'lib/ripper/lexer.rb', line 225

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

Instance Method Details

#match(str) ⇒ Object



230
231
232
# File 'lib/ripper/lexer.rb', line 230

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

#match_list(tokens) ⇒ Object



234
235
236
237
238
239
# File 'lib/ripper/lexer.rb', line 234

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