Methods

Files

Class Index [+]

Quicksearch

CodeRay::Scanners::Diff

Public Instance Methods

scan_tokens(tokens, options) click to toggle source
     # File lib/coderay/scanners/diff.rb, line 9
  9:     def scan_tokens tokens, options
 10:       
 11:       line_kind = nil
 12:       state = :initial
 13:       
 14:       until eos?
 15:         kind = match = nil
 16:         
 17:         if match = scan(/\n/)
 18:           if line_kind
 19:             tokens << [:end_line, line_kind]
 20:             line_kind = nil
 21:           end
 22:           tokens << [match, :space]
 23:           next
 24:         end
 25:         
 26:         case state
 27:         
 28:         when :initial
 29:           if match = scan(/--- |\+\+\+ |=+|_+/)
 30:             tokens << [:begin_line, line_kind = :head]
 31:             tokens << [match, :head]
 32:             next unless match = scan(/.+/)
 33:             kind = :plain
 34:           elsif match = scan(/Index: |Property changes on: /)
 35:             tokens << [:begin_line, line_kind = :head]
 36:             tokens << [match, :head]
 37:             next unless match = scan(/.+/)
 38:             kind = :plain
 39:           elsif match = scan(/Added: /)
 40:             tokens << [:begin_line, line_kind = :head]
 41:             tokens << [match, :head]
 42:             next unless match = scan(/.+/)
 43:             kind = :plain
 44:             state = :added
 45:           elsif match = scan(/\\ /)
 46:             tokens << [:begin_line, line_kind = :change]
 47:             tokens << [match, :change]
 48:             next unless match = scan(/.+/)
 49:             kind = :plain
 50:           elsif scan(/(@@)((?>[^@\n]*))(@@)/)
 51:             tokens << [:begin_line, line_kind = :change]
 52:             tokens << [self[1], :change]
 53:             tokens << [self[2], :plain]
 54:             tokens << [self[3], :change]
 55:             next unless match = scan(/.+/)
 56:             kind = :plain
 57:           elsif match = scan(/\+/)
 58:             tokens << [:begin_line, line_kind = :insert]
 59:             tokens << [match, :insert]
 60:             next unless match = scan(/.+/)
 61:             kind = :plain
 62:           elsif match = scan(/-/)
 63:             tokens << [:begin_line, line_kind = :delete]
 64:             tokens << [match, :delete]
 65:             next unless match = scan(/.+/)
 66:             kind = :plain
 67:           elsif scan(/ .*/)
 68:             kind = :comment
 69:           elsif scan(/.+/)
 70:             tokens << [:begin_line, line_kind = :head]
 71:             kind = :plain
 72:           else
 73:             raise_inspect 'else case rached'
 74:           end
 75:         
 76:         when :added
 77:           if match = scan(/   \+/)
 78:             tokens << [:begin_line, line_kind = :insert]
 79:             tokens << [match, :insert]
 80:             next unless match = scan(/.+/)
 81:             kind = :plain
 82:           else
 83:             state = :initial
 84:             next
 85:           end
 86:         end
 87:         
 88:         match ||= matched
 89:         if $CODERAY_DEBUG and not kind
 90:           raise_inspect 'Error token %p in line %d' %
 91:             [[match, kind], line], tokens
 92:         end
 93:         raise_inspect 'Empty token', tokens unless match
 94:         
 95:         tokens << [match, kind]
 96:       end
 97:       
 98:       tokens << [:end_line, line_kind] if line_kind
 99:       tokens
100:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.