Class: Rouge::Lexers::Escape

Inherits:
Rouge::Lexer show all
Defined in:
lib/rouge/lexers/escape.rb

Constant Summary

Constants included from Token::Tokens

Token::Tokens::Num, Token::Tokens::Str

Instance Attribute Summary collapse

Attributes inherited from Rouge::Lexer

#options

Instance Method Summary collapse

Methods inherited from Rouge::Lexer

aliases, all, #as_bool, #as_lexer, #as_list, #as_string, #as_token, #bool_option, #continue_lex, continue_lex, debug_enabled?, demo, demo_file, desc, detect?, detectable?, disable_debug!, enable_debug!, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #hash_option, #lex, lex, #lexer_option, #list_option, mimetypes, option, option_docs, #reset!, #string_option, #tag, tag, title, #token_option

Methods included from Token::Tokens

token

Constructor Details

#initializeEscape

Returns a new instance of Escape


17
18
19
20
21
22
# File 'lib/rouge/lexers/escape.rb', line 17

def initialize(*)
  super
  @start = string_option(:start) { '<!' }
  @end = string_option(:end) { '!>' }
  @lang = lexer_option(:lang) { PlainText.new }
end

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end


14
15
16
# File 'lib/rouge/lexers/escape.rb', line 14

def end
  @end
end

#langObject (readonly)

Returns the value of attribute lang


15
16
17
# File 'lib/rouge/lexers/escape.rb', line 15

def lang
  @lang
end

#startObject (readonly)

Returns the value of attribute start


13
14
15
# File 'lib/rouge/lexers/escape.rb', line 13

def start
  @start
end

Instance Method Details

#stream_tokens(str, &b) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rouge/lexers/escape.rb', line 32

def stream_tokens(str, &b)
  stream = StringScanner.new(str)

  loop do
    if stream.scan(to_start_regex)
      puts "pre-escape: #{stream[1].inspect}" if @debug
      @lang.continue_lex(stream[1], &b)
    else
      # no more start delimiters, scan til the end
      @lang.continue_lex(stream.rest, &b)
      return
    end

    if stream.scan(to_end_regex)
      yield Token::Tokens::Escape, stream[1]
    else
      yield Token::Tokens::Escape, stream.rest
      return
    end
  end
end

#to_end_regexObject


28
29
30
# File 'lib/rouge/lexers/escape.rb', line 28

def to_end_regex
  @to_end_regex ||= /(.*?)(#{Regexp.escape(@end)})/m
end

#to_start_regexObject


24
25
26
# File 'lib/rouge/lexers/escape.rb', line 24

def to_start_regex
  @to_start_regex ||= /(.*?)(#{Regexp.escape(@start)})/m
end