/usr/lib/ruby/vendor_ruby/rugments/util.rb is in ruby-rugments 1.0.0~beta8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | module Rugments
class InheritableHash < Hash
def initialize(parent = nil)
@parent = parent
end
def [](k)
_sup = super
return _sup if own_keys.include?(k)
_sup || parent[k]
end
def parent
@parent ||= {}
end
def include?(k)
super || parent.include?(k)
end
def each(&b)
keys.each do |k|
b.call(k, self[k])
end
end
alias_method :own_keys, :keys
def keys
keys = own_keys.concat(parent.keys)
keys.uniq!
keys
end
end
class InheritableList
include Enumerable
def initialize(parent = nil)
@parent = parent
end
def parent
@parent ||= []
end
def each(&b)
return enum_for(:each) unless block_given?
parent.each(&b)
own_entries.each(&b)
end
def own_entries
@own_entries ||= []
end
def push(o)
own_entries << o
end
alias_method :<<, :push
end
# shared methods for some indentation-sensitive lexers
module Indentation
def reset!
super
@block_state = @block_indentation = nil
end
# push a state for the next indented block
def starts_block(block_state)
@block_state = block_state
@block_indentation = @last_indentation || ''
puts " starts_block #{block_state.inspect}" if @debug
puts " block_indentation: #{@block_indentation.inspect}" if @debug
end
# handle a single indented line
def indentation(indent_str)
puts " indentation #{indent_str.inspect}" if @debug
puts " block_indentation: #{@block_indentation.inspect}" if @debug
@last_indentation = indent_str
# if it's an indent and we know where to go next,
# push that state. otherwise, push content and
# clear the block state.
if @block_state &&
indent_str.start_with?(@block_indentation) &&
indent_str != @block_indentation
push @block_state
else
@block_state = @block_indentation = nil
push :content
end
end
end
end
|