Class: FaultInjection::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/fault_injection/parser.rb

Class Method Summary collapse

Class Method Details

.compile(src) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fault_injection/parser.rb', line 7

def self.compile src
  method_pat = '([A-Z][A-Za-z0-9_]*)(?:#|::)([a-z_][a-zA-Z0-9_]*)'
  src.gsub!(/\s/,'')
  
  if src =~ /([A-Za-z0-9_.~-]+):(\d+)/
	return FaultConditionLine.new($1,$2.to_i)

  else
	methods = src.split(">")
	methods.map! do |e|
	  unless e =~ Regexp.new(method_pat)
		raise ArgumentError,"Invalid method name:'#{e}'"
	  end

	  [$1.to_sym,$2.to_sym]
	end

	c = FaultConditionCall.new
	c.stack_pattern = methods.reverse # callee first
	
	return c
  end
end