Class: Rouge::Lexers::YAML
- Inherits:
-
RegexLexer
- Object
- Rouge::Lexer
- RegexLexer
- Rouge::Lexers::YAML
- Defined in:
- lib/rouge/lexers/yaml.rb
Direct Known Subclasses
Constant Summary
Constants inherited from RegexLexer
Constants included from Token::Tokens
Token::Tokens::Num, Token::Tokens::Str
Instance Attribute Summary
Attributes inherited from Rouge::Lexer
Class Method Summary collapse
-
.detect?(text) ⇒ Boolean
Documentation: https://yaml.org/spec/1.2/spec.html.
Instance Method Summary collapse
- #continue_indent(match) ⇒ Object
- #dedent?(level) ⇒ Boolean
- #indent ⇒ Object
- #indent?(level) ⇒ Boolean
-
#reset_indent ⇒ Object
reset the indentation levels.
-
#save_indent(match) ⇒ Object
Save a possible indentation level.
- #set_indent(match, opts = {}) ⇒ Object
Methods inherited from RegexLexer
append, #delegate, #goto, #group, #groups, #in_state?, #pop!, prepend, #push, #recurse, replace_state, #reset!, #reset_stack, #stack, start, start_procs, state, #state, #state?, state_definitions, states, #step, #stream_tokens, #token
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, detectable?, disable_debug!, enable_debug!, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #hash_option, #initialize, lex, #lex, #lexer_option, #list_option, lookup_fancy, mimetypes, option, option_docs, #reset!, #stream_tokens, #string_option, #tag, tag, title, #token_option, #with
Methods included from Token::Tokens
Constructor Details
This class inherits a constructor from Rouge::Lexer
Class Method Details
.detect?(text) ⇒ Boolean
Documentation: https://yaml.org/spec/1.2/spec.html
16 17 18 19 |
# File 'lib/rouge/lexers/yaml.rb', line 16 def self.detect?(text) # look for the %YAML directive return true if text =~ /\A\s*%YAML/m end |
Instance Method Details
#continue_indent(match) ⇒ Object
62 63 64 65 |
# File 'lib/rouge/lexers/yaml.rb', line 62 def continue_indent(match) puts " yaml: continue_indent" if @debug @next_indent += match.size end |
#dedent?(level) ⇒ Boolean
37 38 39 |
# File 'lib/rouge/lexers/yaml.rb', line 37 def dedent?(level) level < self.indent end |
#indent ⇒ Object
32 33 34 35 |
# File 'lib/rouge/lexers/yaml.rb', line 32 def indent raise 'empty indent stack!' if @indent_stack.empty? @indent_stack.last end |
#indent?(level) ⇒ Boolean
41 42 43 |
# File 'lib/rouge/lexers/yaml.rb', line 41 def indent?(level) level > self.indent end |
#reset_indent ⇒ Object
reset the indentation levels
25 26 27 28 29 30 |
# File 'lib/rouge/lexers/yaml.rb', line 25 def reset_indent puts " yaml: reset_indent" if @debug @indent_stack = [0] @next_indent = 0 @block_scalar_indent = nil end |
#save_indent(match) ⇒ Object
Save a possible indentation level
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rouge/lexers/yaml.rb', line 46 def save_indent(match) @next_indent = match.size puts " yaml: indent: #{self.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: #{self.indent}/#@next_indent" if @debug # dedenting to a state not previously indented to is an error [match[0...self.indent], match[self.indent..-1]] else [match, ''] end end |
#set_indent(match, opts = {}) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/rouge/lexers/yaml.rb', line 67 def set_indent(match, opts={}) if indent < @next_indent puts " yaml: indenting #{indent}/#{@next_indent}" if @debug @indent_stack << @next_indent end @next_indent += match.size unless opts[:implicit] end |