Class: Trenni::Parser
- Inherits:
-
StringScanner
- Object
- StringScanner
- StringScanner
- Trenni::Parser
- 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
Instance Attribute Summary
Attributes inherited from StringScanner
Instance Method Summary collapse
-
#initialize(buffer, delegate) ⇒ Parser
constructor
A new instance of Parser.
- #parse! ⇒ Object
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 |