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, lookup_fancy, mimetypes, option, option_docs, #reset!, #string_option, tag, #tag, title, #token_option, #with

Methods included from Token::Tokens

token

Constructor Details

#initializeEscape

Returns a new instance of Escape.



20
21
22
23
24
25
# File 'lib/rouge/lexers/escape.rb', line 20

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.



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

def end
  @end
end

#langObject (readonly)

Returns the value of attribute lang.



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

def lang
  @lang
end

#startObject (readonly)

Returns the value of attribute start.



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

def start
  @start
end

Instance Method Details

#stream_tokens(str, &b) ⇒ Object



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

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



31
32
33
# File 'lib/rouge/lexers/escape.rb', line 31

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

#to_start_regexObject



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

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