Class: RegexpToken

Inherits:
RegexpTree show all
Defined in:
app/models/regexp_parse.rb

Overview

assert(global_name?(:RexexpTree))

Defined Under Namespace

Modules: Constants

Constant Summary

Constants inherited from RegexpTree

RegexpTree::Ascii_characters, RegexpTree::Binary_bytes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RegexpTree

#&, #+, #<=>, canonical_regexp, canonical_regexp_tree, #compare_repetitions?, #initialize, #probability_space_regexp, #probability_space_size, promote, #to_a, #to_regexp, #to_s

Methods included from RegexpTree::ClassMethods

#promote

Methods inherited from NestedArray

#[], #initialize, #map_branches, #map_recursive, #merge_single_element_arrays?, #promote, #reverse, #to_s

Methods included from NestedArray::Assertions::ClassMethods

#assert_post_conditions

Methods included from NestedArray::Assertions

#assert_post_conditions, #assert_pre_conditions

Constructor Details

This class inherits a constructor from RegexpTree

Class Method Details

.[](character) ⇒ Object


25
26
27
28
29
30
31
# File 'app/models/regexp_parse.rb', line 25

def self.[](character)
	if character.instance_of?(Symbol) then
		RegexpToken.new([Constants::To_s[character]]) # get character from symbol lookup
	else
		RegexpToken.new([character])	
	end #if
end

.tos_initializeObject

square_brackets_RegexpToken


32
33
34
35
36
37
38
39
# File 'app/models/regexp_parse.rb', line 32

def self.tos_initialize
	ret={}
	Array.new(256){|i| i.chr}.each do |character|
		symbol=RegexpToken[character].to_sym
		ret[symbol]=character
	end #each
	return ret
end

Instance Method Details

#inspectObject

tos_initialize


40
41
42
# File 'app/models/regexp_parse.rb', line 40

def inspect
	':'+to_sym.to_s
end

#to_symObject

inspect


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
# File 'app/models/regexp_parse.rb', line 43

def to_sym
	case self[0]
	when '(' then :begin_capture
	when ')' then :end_capture
	when '{' then :begin_repetition
	when '}' then :end_repetition
	when '[' then :begin_class
	when ']' then :end_class
	when '.' then :any_char
	when '?' then :optional
	when '+' then :many
	when '*' then :any
	when ' ' then :space
	when "\t" then :tab
	when "\n" then :newline
	else 
		if self[0]==Regexp.escape(self[0]) then
			self[0].to_sym
#		elsif self[0]!=self[0].inspect[1..-2] then # strip double quotes
		else
			self[0].inspect[1..-2].to_sym
#		else
#			raise "#{self[0].inspect} is not escaped"
		end #if
	end #case
end