Parent

Included Modules

Class Index

Quicksearch

Arrow::Template::Parser::State

Parse state object class. Instance of this class represent a parser‘s progress through a given template body.

Attributes

current_branch[R]
The current branch of the parse state. Branches are added and removed for re-entrances into the parse loop.
current_branch_node[R]
The pointer into the syntax tree for the node which is the base of the current branch.
current_node[R]
The pointer into the syntax tree for the current node
data[R]
A miscellaneous data hash to allow directives to keep their own state for a parse.
scanner[R]
The StringScanner object which is scanning the text being parsed.
tag_close[RW]
The pattern that will match the current tag-closing characters during the parse of a directive.
tag_middle[RW]
The pattern that will match the middle of the current tag during the parse of a directive.
tag_open[R]
The string that contains the opening string of the current tag, if any.

Public Class Methods

new( text, template, initialData={} ) click to toggle source

Create and return a new parse state for the specified text. The initialData is used to propagate directive bookkeeping state through recursive parses.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 125
125:         def initialize( text, template, initialData={} )
126:             @scanner = StringScanner.new( text )
127:             @template = template
128:             @tag_open = nil
129:             @tag_middle = nil
130:             @tag_close = nil
131:             @current_branch = []
132:             @current_branch_node = nil
133:             @current_node = nil
134:             @data = initialData
135: 
136:             #self.log.debug "From %s: Created a parse state for %p (%p). Data is: %p" %
137:             #    [ caller(1).first, text, template, initialData ]
138:         end

Public Instance Methods

<<( *nodes ) click to toggle source

Alias for #add_nodes

add_nodes( *nodes ) click to toggle source

Add the given nodes to the state‘s syntax tree.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 199
199:         def add_nodes( *nodes )
200:             @current_branch.push( *nodes )
201:             @current_node = @current_branch.last
202:             return self
203:         end
Also aliased as: <<
branch( node ) {|self| ...} click to toggle source

Add a branch belonging to the specified node to the parse state for the duration of the supplied block, removing and returning it when the block returns.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 210
210:         def branch( node )
211:             raise LocalJumpError, "no block given" unless
212:                 block_given?
213: 
214:             # Save and set the current branch node
215:             entryNode = @current_branch_node
216:             @current_branch_node = node
217: 
218:             # Push a new branch and make the current branch point to it
219:             # while saving the one we entered with so it can be restored
220:             # later.
221:             entryBranch = @current_branch
222:             entryBranch.push( @current_branch = [] )
223: 
224:             yield( self )
225: 
226:             # Restore the current branch and branch node to what they were
227:             # before
228:             @current_branch = entryBranch
229:             @current_branch_node = entryNode
230: 
231:             return @current_branch.pop
232:         end
line() click to toggle source

Return the line number of the line on which the parse‘s pointer current rests.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 184
184:         def line
185:             return @scanner.string[ 0, @scanner.pos ].count( $/ ) + 1
186:         end
set_tag_patterns( opening ) click to toggle source

Set the middle and closing tag patterns from the given matched opening string.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 191
191:         def set_tag_patterns( opening )
192:             @tag_open = opening
193:             @tag_close = TAGCLOSE[ opening ]
194:             @tag_middle = TAGMIDDLE[ @tag_close ]
195:         end

secsequence

--- SEC00162

seccomment

--- ""

attributes

--- 
- name: current_branch
  rw: R
  a_desc: |+
    
    The current <a href="State.html#M000167">branch</a> of the parse state.
    Branches are added and removed for re-entrances into the parse loop.
    
- name: current_branch_node
  rw: R
  a_desc: |+
    
    The pointer into the syntax tree for the node which is the base of the
    current <a href="State.html#M000167">branch</a>.
    
- name: current_node
  rw: R
  a_desc: |+
    
    The pointer into the syntax tree for the current node
    
- name: data
  rw: R
  a_desc: |+
    
    A miscellaneous data hash to allow directives to keep their own state for a
    parse.
    
- name: scanner
  rw: R
  a_desc: |+
    
    The StringScanner object which is scanning the text being parsed.
    
- name: tag_close
  rw: RW
  a_desc: |+
    
    The pattern that will match the current tag-closing characters during the
    parse of a directive.
    
- name: tag_middle
  rw: RW
  a_desc: |+
    
    The pattern that will match the middle of the current tag during the parse
    of a directive.
    
- name: tag_open
  rw: R
  a_desc: |+
    
    The string that contains the opening string of the current tag, if any.
    

method_list

--- 
- methods: 
  - visibility: public
    aref: M000162
    name: new
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 125</span>\n\
      125:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">text</span>, <span class=\"ruby-identifier\">template</span>, <span class=\"ruby-identifier\">initialData</span>={} )\n\
      126:             <span class=\"ruby-ivar\">@scanner</span> = <span class=\"ruby-constant\">StringScanner</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-identifier\">text</span> )\n\
      127:             <span class=\"ruby-ivar\">@template</span> = <span class=\"ruby-identifier\">template</span>\n\
      128:             <span class=\"ruby-ivar\">@tag_open</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      129:             <span class=\"ruby-ivar\">@tag_middle</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      130:             <span class=\"ruby-ivar\">@tag_close</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      131:             <span class=\"ruby-ivar\">@current_branch</span> = []\n\
      132:             <span class=\"ruby-ivar\">@current_branch_node</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      133:             <span class=\"ruby-ivar\">@current_node</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      134:             <span class=\"ruby-ivar\">@data</span> = <span class=\"ruby-identifier\">initialData</span>\n\
      135: \n\
      136:             <span class=\"ruby-comment cmt\">#self.log.debug &quot;From %s: Created a parse state for %p (%p). Data is: %p&quot; %</span>\n\
      137:             <span class=\"ruby-comment cmt\">#    [ caller(1).first, text, template, initialData ]</span>\n\
      138:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Create and return a <a href="State.html#M000162">new</a> parse state for
      the specified <tt>text</tt>. The <tt>initialData</tt> is used to propagate
      directive bookkeeping state through recursive parses.
      </p>
    params: ( text, template, initialData={} )
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000166
    name: "&lt;&lt;"
    m_desc: |-
      <p>
      Alias for <a href="State.html#M000165">#add_nodes</a>
      </p>
    params: ( *nodes )
  - visibility: public
    aref: M000165
    name: add_nodes
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 199</span>\n\
      199:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">add_nodes</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">nodes</span> )\n\
      200:             <span class=\"ruby-ivar\">@current_branch</span>.<span class=\"ruby-identifier\">push</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">nodes</span> )\n\
      201:             <span class=\"ruby-ivar\">@current_node</span> = <span class=\"ruby-ivar\">@current_branch</span>.<span class=\"ruby-identifier\">last</span>\n\
      202:             <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">self</span>\n\
      203:         <span class=\"ruby-keyword kw\">end</span>"
    aka: 
    - aref: State.html#M000166
      name: "<<"
    m_desc: |-
      <p>
      Add the given <tt>nodes</tt> to the state&#8216;s syntax tree.
      </p>
    params: ( *nodes )
  - visibility: public
    aref: M000167
    name: branch
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 210</span>\n\
      210:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">branch</span>( <span class=\"ruby-identifier\">node</span> )\n\
      211:             <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">LocalJumpError</span>, <span class=\"ruby-value str\">&quot;no block given&quot;</span> <span class=\"ruby-keyword kw\">unless</span>\n\
      212:                 <span class=\"ruby-identifier\">block_given?</span>\n\
      213: \n\
      214:             <span class=\"ruby-comment cmt\"># Save and set the current branch node</span>\n\
      215:             <span class=\"ruby-identifier\">entryNode</span> = <span class=\"ruby-ivar\">@current_branch_node</span>\n\
      216:             <span class=\"ruby-ivar\">@current_branch_node</span> = <span class=\"ruby-identifier\">node</span>\n\
      217: \n\
      218:             <span class=\"ruby-comment cmt\"># Push a new branch and make the current branch point to it</span>\n\
      219:             <span class=\"ruby-comment cmt\"># while saving the one we entered with so it can be restored</span>\n\
      220:             <span class=\"ruby-comment cmt\"># later.</span>\n\
      221:             <span class=\"ruby-identifier\">entryBranch</span> = <span class=\"ruby-ivar\">@current_branch</span>\n\
      222:             <span class=\"ruby-identifier\">entryBranch</span>.<span class=\"ruby-identifier\">push</span>( <span class=\"ruby-ivar\">@current_branch</span> = [] )\n\
      223: \n\
      224:             <span class=\"ruby-keyword kw\">yield</span>( <span class=\"ruby-keyword kw\">self</span> )\n\
      225: \n\
      226:             <span class=\"ruby-comment cmt\"># Restore the current branch and branch node to what they were</span>\n\
      227:             <span class=\"ruby-comment cmt\"># before</span>\n\
      228:             <span class=\"ruby-ivar\">@current_branch</span> = <span class=\"ruby-identifier\">entryBranch</span>\n\
      229:             <span class=\"ruby-ivar\">@current_branch_node</span> = <span class=\"ruby-identifier\">entryNode</span>\n\
      230: \n\
      231:             <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@current_branch</span>.<span class=\"ruby-identifier\">pop</span>\n\
      232:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Add a <a href="State.html#M000167">branch</a> belonging to the specified
      <tt>node</tt> to the parse state for the duration of the supplied block,
      removing and returning it when the block returns.
      </p>
    params: ( node ) {|self| ...}
  - visibility: public
    aref: M000163
    name: line
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 184</span>\n\
      184:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">line</span>\n\
      185:             <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@scanner</span>.<span class=\"ruby-identifier\">string</span>[ <span class=\"ruby-value\">0</span>, <span class=\"ruby-ivar\">@scanner</span>.<span class=\"ruby-identifier\">pos</span> ].<span class=\"ruby-identifier\">count</span>( <span class=\"ruby-identifier\">$/</span> ) <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">1</span>\n\
      186:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Return the <a href="State.html#M000163">line</a> number of the <a
      href="State.html#M000163">line</a> on which the parse&#8216;s pointer
      current rests.
      </p>
    params: ()
  - visibility: public
    aref: M000164
    name: set_tag_patterns
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/parser.rb, line 191</span>\n\
      191:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">set_tag_patterns</span>( <span class=\"ruby-identifier\">opening</span> )\n\
      192:             <span class=\"ruby-ivar\">@tag_open</span> = <span class=\"ruby-identifier\">opening</span>\n\
      193:             <span class=\"ruby-ivar\">@tag_close</span> = <span class=\"ruby-constant\">TAGCLOSE</span>[ <span class=\"ruby-identifier\">opening</span> ]\n\
      194:             <span class=\"ruby-ivar\">@tag_middle</span> = <span class=\"ruby-constant\">TAGMIDDLE</span>[ <span class=\"ruby-ivar\">@tag_close</span> ]\n\
      195:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Set the middle and closing tag patterns from the given matched opening
      string.
      </p>
    params: ( opening )
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.