Class: QDA::Backend::NPNode

Inherits:
Object
  • Object
show all
Defined in:
lib/weft/backend/n6.rb

Overview

A container for strings that reside between matching parenthesis. Each instance of this class contains a list of values that are either strings or other NPNode objects representing nesting.

Constant Summary collapse

@@NORMAL_MODE =
0
@@QUOTE_MODE =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ NPNode

Initialize a new instance that has the specified parent. The parent can be nil, in which case it is assumed that this is the top level node. If the parent is not nil, then this object is added as a child to the parent.



276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/weft/backend/n6.rb', line 276

def initialize (parent)

		@parent = parent
		
		if ( @parent != nil ) then
 @parent.push(self)
		end

		@state = @@NORMAL_MODE
		@level = ( parent == nil ) ? 0 : @parent.level + 1

		@values = Array.new
		@curval = Array.new
end

Instance Attribute Details

#levelObject (readonly)

The level of this group. This is set by the constructor and is based upon the level of the parent.



259
260
261
# File 'lib/weft/backend/n6.rb', line 259

def level
  @level
end

#parentObject (readonly)

The parent of this group.



255
256
257
# File 'lib/weft/backend/n6.rb', line 255

def parent
  @parent
end

#stateObject (readonly)

The state of this group. This will either be NORMAL or QUOTE. In QUOTE, whitespace is absorbed.



263
264
265
# File 'lib/weft/backend/n6.rb', line 263

def state
  @state
end

#valuesObject (readonly)

The members of this group.



252
253
254
# File 'lib/weft/backend/n6.rb', line 252

def values
  @values
end

Instance Method Details

#closeObject



265
266
267
268
269
270
# File 'lib/weft/backend/n6.rb', line 265

def close
		if ( @curval.size > 0 ) then
 @values.push( @curval.to_s )
 @curval.clear
		end
end

#push(ch) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/weft/backend/n6.rb', line 291

def push(ch)
		if ( ch.kind_of? NPNode ) then
 # If this is an NPNode instance, just add it to the end of the
 # values array.
 @values.push(ch)

		else
 if ( ch == "'" || ch == "\"" ) then
# If this is a double quote, then we have to start a new
# value, toggle the mode.
@state = ( @state + 1 ) % 2
close

 elsif ( (@state != @@QUOTE_MODE) && ch =~ /[ \t\n\r]/ ) then
# If this is a whitespace character and the length is
# greater than zero, push the current value on the values
# array and clear the current values string.
close

 else
# Otherwise go ahead and push the character onto the end of
# the current value.
@curval.push( ch )
 end
		end
end

#to_sObject



318
319
320
321
# File 'lib/weft/backend/n6.rb', line 318

def to_s 
		str = Array.new()
		return "(#{@values.join(' ')})"
end