Class: Trenni::Parser

Inherits:
StringScanner show all
Defined in:
lib/trenni/parser.rb

Overview

This parser processes general markup into a sequence of events which are passed to a delegate.

Constant Summary collapse

OPENED_TAG =
:opened
CLOSED_TAG =
:closed

Constants inherited from StringScanner

StringScanner::STUCK_MESSAGE

Instance Attribute Summary

Attributes inherited from StringScanner

#buffer

Instance Method Summary collapse

Methods inherited from StringScanner

#parse_error!, #path, #raise_if_stuck, #stuck?

Constructor Details

#initialize(buffer, delegate) ⇒ Parser

Returns a new instance of Parser.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/trenni/parser.rb', line 29

def initialize(buffer, delegate)
	super(buffer)
	
	@delegate = delegate
	
	# The delegate must respond to:
	# .begin_parse(self)
	# .text(escaped_data)
	# .cdata(unescaped_data)
	# .attribute(name, value_or_true)
	# .begin_tag(name, :opened or :closed)
	# .end_tag(begin_tag_type, :opened or :closed)
	# .doctype(doctype_attributes)
	# .comment(comment_text)
	# .instruction(instruction_text)
end

Instance Method Details

#parse!Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/trenni/parser.rb', line 46

def parse!
	@delegate.begin_parse(self)

	until eos?
		start_pos = self.pos

		scan_text
		scan_tag

		raise_if_stuck(start_pos)
	end
end