<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>class Parslet::Atoms::Named - parslet-1.5.0 Documentation</title>

<link type="text/css" media="screen" href="../../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
</script>

<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../../index.html">Home</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  

  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/parslet/atoms/named.rb
    <li>lib/parslet/atoms/visitor.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link"><a href="Base.html">Parslet::Atoms::Base</a>
  
</nav>

    
    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li class="calls-super" ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-accept">#accept</a>
    
    <li ><a href="#method-i-apply">#apply</a>
    
    <li ><a href="#method-i-produce_return_value">#produce_return_value</a>
    
    <li ><a href="#method-i-to_s_inner">#to_s_inner</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../../README.html">README</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../../Parslet.html">Parslet</a>
  
    <li><a href="../../Parslet/Atoms.html">Parslet::Atoms</a>
  
    <li><a href="../../Parslet/Atoms/Alternative.html">Parslet::Atoms::Alternative</a>
  
    <li><a href="../../Parslet/Atoms/Base.html">Parslet::Atoms::Base</a>
  
    <li><a href="../../Parslet/Atoms/CanFlatten.html">Parslet::Atoms::CanFlatten</a>
  
    <li><a href="../../Parslet/Atoms/Capture.html">Parslet::Atoms::Capture</a>
  
    <li><a href="../../Parslet/Atoms/Context.html">Parslet::Atoms::Context</a>
  
    <li><a href="../../Parslet/Atoms/DSL.html">Parslet::Atoms::DSL</a>
  
    <li><a href="../../Parslet/Atoms/Dynamic.html">Parslet::Atoms::Dynamic</a>
  
    <li><a href="../../Parslet/Atoms/Entity.html">Parslet::Atoms::Entity</a>
  
    <li><a href="../../Parslet/Atoms/Lookahead.html">Parslet::Atoms::Lookahead</a>
  
    <li><a href="../../Parslet/Atoms/Named.html">Parslet::Atoms::Named</a>
  
    <li><a href="../../Parslet/Atoms/Precedence.html">Parslet::Atoms::Precedence</a>
  
    <li><a href="../../Parslet/Atoms/Re.html">Parslet::Atoms::Re</a>
  
    <li><a href="../../Parslet/Atoms/Repetition.html">Parslet::Atoms::Repetition</a>
  
    <li><a href="../../Parslet/Atoms/Scope.html">Parslet::Atoms::Scope</a>
  
    <li><a href="../../Parslet/Atoms/Sequence.html">Parslet::Atoms::Sequence</a>
  
    <li><a href="../../Parslet/Atoms/Str.html">Parslet::Atoms::Str</a>
  
    <li><a href="../../Parslet/Cause.html">Parslet::Cause</a>
  
    <li><a href="../../Parslet/ClassMethods.html">Parslet::ClassMethods</a>
  
    <li><a href="../../Parslet/DelayedMatchConstructor.html">Parslet::DelayedMatchConstructor</a>
  
    <li><a href="../../Parslet/ErrorReporter.html">Parslet::ErrorReporter</a>
  
    <li><a href="../../Parslet/ErrorReporter/Deepest.html">Parslet::ErrorReporter::Deepest</a>
  
    <li><a href="../../Parslet/ErrorReporter/Tree.html">Parslet::ErrorReporter::Tree</a>
  
    <li><a href="../../Parslet/Expression.html">Parslet::Expression</a>
  
    <li><a href="../../Parslet/Expression/Treetop.html">Parslet::Expression::Treetop</a>
  
    <li><a href="../../Parslet/Expression/Treetop/Parser.html">Parslet::Expression::Treetop::Parser</a>
  
    <li><a href="../../Parslet/Expression/Treetop/Transform.html">Parslet::Expression::Treetop::Transform</a>
  
    <li><a href="../../Parslet/ParseFailed.html">Parslet::ParseFailed</a>
  
    <li><a href="../../Parslet/Parser.html">Parslet::Parser</a>
  
    <li><a href="../../Parslet/Parser/PrettyPrinter.html">Parslet::Parser::PrettyPrinter</a>
  
    <li><a href="../../Parslet/Parser/Visitors.html">Parslet::Parser::Visitors</a>
  
    <li><a href="../../Parslet/Parser/Visitors/Citrus.html">Parslet::Parser::Visitors::Citrus</a>
  
    <li><a href="../../Parslet/Parser/Visitors/Treetop.html">Parslet::Parser::Visitors::Treetop</a>
  
    <li><a href="../../Parslet/Pattern.html">Parslet::Pattern</a>
  
    <li><a href="../../Parslet/Pattern/SequenceBind.html">Parslet::Pattern::SequenceBind</a>
  
    <li><a href="../../Parslet/Pattern/SimpleBind.html">Parslet::Pattern::SimpleBind</a>
  
    <li><a href="../../Parslet/Pattern/SubtreeBind.html">Parslet::Pattern::SubtreeBind</a>
  
    <li><a href="../../Parslet/Scope.html">Parslet::Scope</a>
  
    <li><a href="../../Parslet/Scope/Binding.html">Parslet::Scope::Binding</a>
  
    <li><a href="../../Parslet/Scope/NotFound.html">Parslet::Scope::NotFound</a>
  
    <li><a href="../../Parslet/Slice.html">Parslet::Slice</a>
  
    <li><a href="../../Parslet/Source.html">Parslet::Source</a>
  
    <li><a href="../../Parslet/Source/LineCache.html">Parslet::Source::LineCache</a>
  
    <li><a href="../../Parslet/Source/RangeSearch.html">Parslet::Source::RangeSearch</a>
  
    <li><a href="../../Parslet/Transform.html">Parslet::Transform</a>
  
    <li><a href="../../Parslet/Transform/Context.html">Parslet::Transform::Context</a>
  
    <li><a href="../../RSpec.html">RSpec</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class Parslet::Atoms::Named</h1>

  <div id="description" class="description">
    
<p>Names a match to influence tree construction.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">str</span>(<span class="ruby-string">&#39;foo&#39;</span>)            <span class="ruby-comment"># will return &#39;foo&#39;, </span>
<span class="ruby-identifier">str</span>(<span class="ruby-string">&#39;foo&#39;</span>).<span class="ruby-identifier">as</span>(:<span class="ruby-identifier">foo</span>)   <span class="ruby-comment"># will return :foo =&gt; &#39;foo&#39;</span>
</pre>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    
    <!-- Attributes -->
    <section id="attribute-method-details" class="method-section section">
      <h3 class="section-header">Attributes</h3>

      
      <div id="attribute-i-name" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">name</span><span
            class="attribute-access-type">[R]</span>
        </div>

        <div class="method-description">
        
        
        
        </div>
      </div>
      
      <div id="attribute-i-parslet" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">parslet</span><span
            class="attribute-access-type">[R]</span>
        </div>

        <div class="method-description">
        
        
        
        </div>
      </div>
      
    </section><!-- attribute-method-details -->
    

    <!-- Methods -->
    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Class Methods</h3>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(parslet, name)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          
          
          
            <div class="method-calls-super">
              Calls superclass method
              
            </div>
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/parslet/atoms/named.rb, line 10</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">parslet</span>, <span class="ruby-identifier">name</span>)
  <span class="ruby-keyword">super</span>()

  <span class="ruby-ivar">@parslet</span>, <span class="ruby-ivar">@name</span> = <span class="ruby-identifier">parslet</span>, <span class="ruby-identifier">name</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- new-source -->
          
        </div>

        

        
      </div><!-- new-method -->

    
    </section><!-- public-class-method-details -->
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-accept" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">accept</span><span
            class="method-args">(visitor)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Call back visitors visit_named method. See parslet/export for an example.</p>
          
          

          
          <div class="method-source-code" id="accept-source">
            <pre><span class="ruby-comment"># File lib/parslet/atoms/visitor.rb, line 33</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">accept</span>(<span class="ruby-identifier">visitor</span>)
  <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">visit_named</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">parslet</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- accept-source -->
          
        </div>

        

        
      </div><!-- accept-method -->

    
      <div id="method-i-apply" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">apply</span><span
            class="method-args">(source, context, consume_all)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          
          
          

          
          <div class="method-source-code" id="apply-source">
            <pre><span class="ruby-comment"># File lib/parslet/atoms/named.rb, line 16</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">apply</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">context</span>, <span class="ruby-identifier">consume_all</span>)
  <span class="ruby-identifier">success</span>, <span class="ruby-identifier">value</span> = <span class="ruby-identifier">result</span> = <span class="ruby-identifier">parslet</span>.<span class="ruby-identifier">apply</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">context</span>, <span class="ruby-identifier">consume_all</span>)

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">result</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">success</span>
  <span class="ruby-identifier">succ</span>(
    <span class="ruby-identifier">produce_return_value</span>(
      <span class="ruby-identifier">value</span>))
<span class="ruby-keyword">end</span></pre>
          </div><!-- apply-source -->
          
        </div>

        

        
      </div><!-- apply-method -->

    
      <div id="method-i-to_s_inner" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">to_s_inner</span><span
            class="method-args">(prec)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          
          
          

          
          <div class="method-source-code" id="to_s_inner-source">
            <pre><span class="ruby-comment"># File lib/parslet/atoms/named.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_s_inner</span>(<span class="ruby-identifier">prec</span>)
  <span class="ruby-node">&quot;#{name}:#{parslet.to_s(prec)}&quot;</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- to_s_inner-source -->
          
        </div>

        

        
      </div><!-- to_s_inner-method -->

    
    </section><!-- public-instance-method-details -->
  
     <section id="private-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Private Instance Methods</h3>

    
      <div id="method-i-produce_return_value" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">produce_return_value</span><span
            class="method-args">(val)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          
          
          

          
          <div class="method-source-code" id="produce_return_value-source">
            <pre><span class="ruby-comment"># File lib/parslet/atoms/named.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">produce_return_value</span>(<span class="ruby-identifier">val</span>)
  { <span class="ruby-identifier">name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">flatten</span>(<span class="ruby-identifier">val</span>, <span class="ruby-keyword">true</span>) }
<span class="ruby-keyword">end</span></pre>
          </div><!-- produce_return_value-source -->
          
        </div>

        

        
      </div><!-- produce_return_value-method -->

    
    </section><!-- private-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

