Class: MessagePack::IDL::Parser

Inherits:
Object
  • Object
show all
Includes:
ProcessorModule
Defined in:
lib/msgpack/idl/parser.rb

Instance Attribute Summary collapse

Attributes included from ProcessorModule

#log

Instance Method Summary collapse

Methods included from ProcessorModule

#log_error, #log_trace, #log_warn

Constructor Details

#initialize(search_paths = []) ⇒ Parser

Returns a new instance of Parser.



27
28
29
30
31
32
# File 'lib/msgpack/idl/parser.rb', line 27

def initialize(search_paths = [])
	@search_paths = search_paths
	@parslet = ParsletParser.new
	@transform = ParsletTransform.new
	@ast = []
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



34
35
36
# File 'lib/msgpack/idl/parser.rb', line 34

def ast
  @ast
end

Instance Method Details

#parse(src, fname, dir) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/msgpack/idl/parser.rb', line 36

def parse(src, fname, dir)
	begin
		tree = @parslet.parse(src)
		ast = @transform.apply(tree)
	rescue Parslet::ParseFailed => error
		msg = @parslet.print_error(error, fname, StringIO.new).string
		raise SyntaxError, msg
	end
	ast.each {|e|
		if e.class == AST::Include
			parse_include(e.path, dir, fname)
		else
			@ast << e
		end
	}
	self
end

#parse_file(path) ⇒ Object



54
55
56
# File 'lib/msgpack/idl/parser.rb', line 54

def parse_file(path)
	parse(File.read(path), File.basename(path), File.dirname(path))
end