Class: Rouge::Lexers::YAML
Constant Summary
Constants inherited
from RegexLexer
RegexLexer::MAX_NULL_SCANS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from RegexLexer
#delegate, get_state, #get_state, #group, #in_state?, #pop!, #push, #reset!, #reset_stack, #run_callback, #run_rule, #stack, start, start_procs, #state, state, #state?, states, #step, #stream_tokens, #token
aliases, all, assert_utf8!, #debug, default_options, demo, demo_file, desc, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #initialize, lex, #lex, mimetypes, #option, #options, #reset!, #stream_tokens, tag, #tag
Constructor Details
This class inherits a constructor from Rouge::Lexer
Class Method Details
.analyze_text(text) ⇒ Object
9
10
11
12
|
# File 'lib/rouge/lexers/yaml.rb', line 9
def self.analyze_text(text)
return 1 if text =~ /\A\s*%YAML/m
end
|
Instance Method Details
#continue_indent ⇒ Object
58
59
60
61
|
# File 'lib/rouge/lexers/yaml.rb', line 58
def continue_indent
debug { " yaml: continue_indent" }
@next_indent += @last_match[0].size
end
|
#dedent?(level) ⇒ Boolean
31
32
33
|
# File 'lib/rouge/lexers/yaml.rb', line 31
def dedent?(level)
level < self.indent
end
|
#indent ⇒ Object
26
27
28
29
|
# File 'lib/rouge/lexers/yaml.rb', line 26
def indent
raise 'empty indent stack!' if @indent_stack.empty?
@indent_stack.last
end
|
#indent?(level) ⇒ Boolean
35
36
37
|
# File 'lib/rouge/lexers/yaml.rb', line 35
def indent?(level)
level > self.indent
end
|
#reset_indent ⇒ Object
reset the indentation levels
19
20
21
22
23
24
|
# File 'lib/rouge/lexers/yaml.rb', line 19
def reset_indent
debug { " yaml: reset_indent" }
@indent_stack = [0]
@next_indent = 0
@block_scalar_indent = nil
end
|
#save_indent(opts = {}) ⇒ Object
Save a possible indentation level
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rouge/lexers/yaml.rb', line 40
def save_indent(opts={})
debug { " yaml: save_indent" }
match = @last_match[0]
@next_indent = match.size
debug { " yaml: indent: #{self.indent}/#@next_indent" }
debug { " yaml: popping indent stack - before: #@indent_stack" }
if dedent?(@next_indent)
@indent_stack.pop while dedent?(@next_indent)
debug { " yaml: popping indent stack - after: #@indent_stack" }
debug { " yaml: indent: #{self.indent}/#@next_indent" }
[match[0...self.indent], match[self.indent..-1]]
else
[match, '']
end
end
|
#set_indent(opts = {}) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/rouge/lexers/yaml.rb', line 63
def set_indent(opts={})
if indent < @next_indent
@indent_stack << @next_indent
end
@next_indent += @last_match[0].size unless opts[:implicit]
end
|