class Rugments::Lexers::YAML
Public Class Methods
analyze_text(text)
click to toggle source
# File lib/rugments/lexers/yaml.rb, line 10 def self.analyze_text(text) # look for the %YAML directive return 1 if text =~ /\A\s*%YAML/m end
Public Instance Methods
continue_indent(match)
click to toggle source
# File lib/rugments/lexers/yaml.rb, line 57 def continue_indent(match) puts ' yaml: continue_indent' if @debug @next_indent += match.size end
dedent?(level)
click to toggle source
# File lib/rugments/lexers/yaml.rb, line 32 def dedent?(level) level < indent end
indent()
click to toggle source
# File lib/rugments/lexers/yaml.rb, line 27 def indent fail 'empty indent stack!' if @indent_stack.empty? @indent_stack.last end
indent?(level)
click to toggle source
# File lib/rugments/lexers/yaml.rb, line 36 def indent?(level) level > indent end
reset_indent()
click to toggle source
reset the indentation levels
# File lib/rugments/lexers/yaml.rb, line 20 def reset_indent puts ' yaml: reset_indent' if @debug @indent_stack = [0] @next_indent = 0 @block_scalar_indent = nil end
save_indent(match)
click to toggle source
Save a possible indentation level
# File lib/rugments/lexers/yaml.rb, line 41 def save_indent(match) @next_indent = match.size puts " yaml: indent: #{indent}/#{@next_indent}" if @debug puts " yaml: popping indent stack - before: #{@indent_stack}" if @debug if dedent?(@next_indent) @indent_stack.pop while dedent?(@next_indent) puts " yaml: popping indent stack - after: #{@indent_stack}" if @debug puts " yaml: indent: #{indent}/#{@next_indent}" if @debug # dedenting to a state not previously indented to is an error [match[0...indent], match[indent..-1]] else [match, ''] end end
set_indent(match, opts = {})
click to toggle source
# File lib/rugments/lexers/yaml.rb, line 62 def set_indent(match, opts = {}) if indent < @next_indent @indent_stack << @next_indent end @next_indent += match.size unless opts[:implicit] end