Class: Ripper::TokenPattern

Inherits:
Object show all
Defined in:
ext/ripper/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.



294
295
296
297
# File 'ext/ripper/lib/ripper/lexer.rb', line 294

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

Instance Method Details

#match(str) ⇒ Object



299
300
301
# File 'ext/ripper/lib/ripper/lexer.rb', line 299

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

#match_list(tokens) ⇒ Object



303
304
305
306
307
308
# File 'ext/ripper/lib/ripper/lexer.rb', line 303

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