Class: RPrec::RegexpLexer

Inherits:
Object
  • Object
show all
Defined in:
lib/rprec/regexp_lexer.rb

Overview

RegexpLexer is a lexer using regexp patterns.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(skip:, pattern:, &block) ⇒ RegexpLexer

Returns a new instance of RegexpLexer.

Parameters:

  • skip (Regexp)
  • pattern (Regexp)
  • block (Proc)


11
12
13
14
15
# File 'lib/rprec/regexp_lexer.rb', line 11

def initialize(skip:, pattern:, &block)
  @skip = /\G#{skip}/
  @pattern = /\G#{pattern}/
  @block = block
end

Instance Attribute Details

#blockProc (readonly)

Returns:

  • (Proc)


24
25
26
# File 'lib/rprec/regexp_lexer.rb', line 24

def block
  @block
end

#patternRegexp (readonly)

Returns:

  • (Regexp)


22
23
24
# File 'lib/rprec/regexp_lexer.rb', line 22

def pattern
  @pattern
end

#skipRegexp (readonly)

Returns:

  • (Regexp)


20
21
22
# File 'lib/rprec/regexp_lexer.rb', line 20

def skip
  @skip
end

Instance Method Details

#lex(source) ⇒ RPrec::RegexpStream

Parameters:

  • source (String)

Returns:



28
29
30
# File 'lib/rprec/regexp_lexer.rb', line 28

def lex(source)
  RegexpStream.new(self, source)
end