Class: Galena::BalanceStack
- Inherits:
-
Object
- Object
- Galena::BalanceStack
- Defined in:
- lib/galena.rb
Overview
balances #= and #=end blocks
Instance Method Summary collapse
-
#dedent(p = 0) ⇒ Object
return the current dedent.
-
#dedent=(dd) ⇒ Object
dedent a line.
-
#do_line(line) ⇒ Object
process a new line.
-
#indent ⇒ Object
indent a line.
-
#initialize ⇒ BalanceStack
constructor
A new instance of BalanceStack.
Constructor Details
#initialize ⇒ BalanceStack
Returns a new instance of BalanceStack.
189 190 191 192 193 |
# File 'lib/galena.rb', line 189 def initialize @stack = [] @seeking = false @block = false end |
Instance Method Details
#dedent(p = 0) ⇒ Object
return the current dedent
234 235 236 237 238 239 240 |
# File 'lib/galena.rb', line 234 def dedent(p=0) if @stack.empty? 0 else @stack.last[-1-p] end end |
#dedent=(dd) ⇒ Object
dedent a line
229 230 231 |
# File 'lib/galena.rb', line 229 def dedent=(dd) @stack.last[1]=dd end |
#do_line(line) ⇒ Object
process a new line
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/galena.rb', line 196 def do_line line s_len = line.match(/^\s*/)[0].length case line when /^\s*\^</ @block = false push(s_len) @seeking = true when /^\s*\^>/ pop else if @seeking if @block == true self.dedent = 0 else self.dedent = dedent + s_len - indent end end @seeking = false end # puts "#{dedent}, #{@stack.length}, #{line}" if @stack.empty? line else line = Galena.ladj(line, s_len - dedent) end end |
#indent ⇒ Object
indent a line
224 225 226 |
# File 'lib/galena.rb', line 224 def indent @stack.last[0] end |