648 lines
17 KiB
HTML
648 lines
17 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>
|
|
Class: Hyde::PatternMatching::Glob
|
|
|
|
— Documentation by YARD 0.9.34
|
|
|
|
</title>
|
|
|
|
<link rel="stylesheet" href="../../css/style.css" type="text/css" />
|
|
|
|
<link rel="stylesheet" href="../../css/common.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
pathId = "Hyde::PatternMatching::Glob";
|
|
relpath = '../../';
|
|
</script>
|
|
|
|
|
|
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
|
|
|
|
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
|
|
|
|
|
|
</head>
|
|
<body>
|
|
<div class="nav_wrap">
|
|
<iframe id="nav" src="../../class_list.html?1"></iframe>
|
|
<div id="resizer"></div>
|
|
</div>
|
|
|
|
<div id="main" tabindex="-1">
|
|
<div id="header">
|
|
<div id="menu">
|
|
|
|
<a href="../../_index.html">Index (G)</a> »
|
|
<span class='title'><span class='object_link'><a href="../../Hyde.html" title="Hyde (module)">Hyde</a></span></span> » <span class='title'><span class='object_link'><a href="../PatternMatching.html" title="Hyde::PatternMatching (module)">PatternMatching</a></span></span>
|
|
»
|
|
<span class="title">Glob</span>
|
|
|
|
</div>
|
|
|
|
<div id="search">
|
|
|
|
<a class="full_list_link" id="class_list_link"
|
|
href="../../class_list.html">
|
|
|
|
<svg width="24" height="24">
|
|
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
</svg>
|
|
</a>
|
|
|
|
</div>
|
|
<div class="clear"></div>
|
|
</div>
|
|
|
|
<div id="content"><h1>Class: Hyde::PatternMatching::Glob
|
|
|
|
|
|
|
|
</h1>
|
|
<div class="box_info">
|
|
|
|
<dl>
|
|
<dt>Inherits:</dt>
|
|
<dd>
|
|
<span class="inheritName">Object</span>
|
|
|
|
<ul class="fullTree">
|
|
<li>Object</li>
|
|
|
|
<li class="next">Hyde::PatternMatching::Glob</li>
|
|
|
|
</ul>
|
|
<a href="#" class="inheritanceTree">show all</a>
|
|
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dl>
|
|
<dt>Defined in:</dt>
|
|
<dd>lib/hyde/pattern_matching/glob.rb</dd>
|
|
</dl>
|
|
|
|
</div>
|
|
|
|
<h2>Overview</h2><div class="docstring">
|
|
<div class="discussion">
|
|
<p>Implements glob-like pattern matching.
|
|
Exact specifications for globbing rules:</p>
|
|
|
|
<p>"/"</p>
|
|
|
|
<ul>
|
|
<li>act as directory separators</li>
|
|
<li>multiple slashes (i.e. "///") are the same as one slash ("/")</li>
|
|
<li>slashes are stripped at start and end of an expression or path</li>
|
|
<li>slashes are not matched by anything but the globstar ("**")</li>
|
|
</ul>
|
|
|
|
<p>"<em>" ( regexp: /([^/]</em>)/ )</p>
|
|
|
|
<ul>
|
|
<li>matches from 0 to any number of characters</li>
|
|
<li>does not match nothing if placed between two slashes (i.e "/*/")</li>
|
|
<li>result is captured in an array</li>
|
|
<li>stops at slashes</li>
|
|
<li>greedy (matches as much as possible)</li>
|
|
</ul>
|
|
|
|
<p>"*<em>" ( regexp: /(.</em>)/ )</p>
|
|
|
|
<ul>
|
|
<li>matches any number of characters</li>
|
|
<li>matches slashes ("/")</li>
|
|
<li>result is captured in an array</li>
|
|
<li>does not stop at slashes</li>
|
|
<li>greedy (matches as much as possible)</li>
|
|
</ul>
|
|
|
|
<p>"[...]+" ( regexp: itself, ! and ^ at the start are interchangeable )</p>
|
|
|
|
<ul>
|
|
<li>acts like a regexp range</li>
|
|
<li>matches any characters, including slashes if specified</li>
|
|
<li>matches any number of characters</li>
|
|
<li>valid ways to specify a range: [A-z], [a-z], <a href="ascii%20order">9-z</a></li>
|
|
<li>! or ^ at the start invert meaning (any character not in range)</li>
|
|
<li>result is captured in an array</li>
|
|
</ul>
|
|
|
|
<p>":name" ( regexp: acts like a named group for /[^/]*/ )</p>
|
|
|
|
<ul>
|
|
<li>acts like * as defined above</li>
|
|
<li>result is captured in a hash with "name" as key</li>
|
|
<li>name allows alphanumeric characters and underscores</li>
|
|
<li>ignored unless placed between two slashes</li>
|
|
</ul>
|
|
|
|
<p>"(name|name2|...)" ( regexp: itself )</p>
|
|
|
|
<ul>
|
|
<li>matches any of (full keywords) name, name2, ...</li>
|
|
<li>result is captured in an array</li>
|
|
<li>each name may include only these groups of characters:
|
|
|
|
<ul>
|
|
<li>alphanumeric</li>
|
|
<li>slashes</li>
|
|
<li>underscores</li>
|
|
<li>dashes</li>
|
|
</ul></li>
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2>
|
|
Class Method Summary
|
|
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
</h2>
|
|
|
|
<ul class="summary">
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#can_convert%3F-class_method" title="can_convert? (class method)">.<strong>can_convert?</strong>(input) ⇒ Boolean </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'><p>Test if input is convertible to a Glob and if it should be converted.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<h2>
|
|
Instance Method Summary
|
|
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
</h2>
|
|
|
|
<ul class="summary">
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(pattern) ⇒ Glob </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span class="note title constructor">constructor</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'><p>A new instance of Glob.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#match-instance_method" title="#match (instance method)">#<strong>match</strong>(input) ⇒ Array(String,Array,Hash), FalseClass </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'><p>Match the string and assign matches to parameters.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#match%3F-instance_method" title="#match? (instance method)">#<strong>match?</strong>(input) ⇒ Boolean </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'><p>Test if a string can be matched.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
<div id="constructor_details" class="method_details_list">
|
|
<h2>Constructor Details</h2>
|
|
|
|
<div class="method_details first">
|
|
<h3 class="signature first" id="initialize-instance_method">
|
|
|
|
#<strong>initialize</strong>(pattern) ⇒ <tt><span class='object_link'><a href="" title="Hyde::PatternMatching::Glob (class)">Glob</a></span></tt>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
<p>Returns a new instance of Glob.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
<p class="tag_title">Parameters:</p>
|
|
<ul class="param">
|
|
|
|
<li>
|
|
|
|
<span class='name'>input</span>
|
|
|
|
|
|
<span class='type'>(<tt>String</tt>)</span>
|
|
|
|
|
|
|
|
—
|
|
<div class='inline'><p>Glob pattern</p>
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
56
|
|
57
|
|
58
|
|
59
|
|
60
|
|
61
|
|
62
|
|
63</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/hyde/pattern_matching/glob.rb', line 56</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_pattern'>pattern</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_pattern'>pattern</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../../Hyde.html" title="Hyde (module)">Hyde</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../PatternMatching.html" title="Hyde::PatternMatching (module)">PatternMatching</a></span></span><span class='period'>.</span><span class='id identifier rubyid_canonicalize'><span class='object_link'><a href="../PatternMatching.html#canonicalize-class_method" title="Hyde::PatternMatching.canonicalize (method)">canonicalize</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_pattern'>pattern</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_pieces'>pieces</span> <span class='op'>=</span> <span class='id identifier rubyid_pattern'>pattern</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='const'>TOKENS</span><span class='rparen'>)</span>
|
|
<span class='comment'># @type [Array<String,Integer>]
|
|
</span> <span class='ivar'>@index</span> <span class='op'>=</span> <span class='id identifier rubyid_build_index'>build_index</span><span class='lparen'>(</span><span class='id identifier rubyid_pieces'>pieces</span><span class='rparen'>)</span>
|
|
<span class='comment'># @type [Regexp]
|
|
</span> <span class='ivar'>@glob</span> <span class='op'>=</span> <span class='id identifier rubyid_build_regexp'>build_regexp</span><span class='lparen'>(</span><span class='id identifier rubyid_pieces'>pieces</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<div id="class_method_details" class="method_details_list">
|
|
<h2>Class Method Details</h2>
|
|
|
|
|
|
<div class="method_details first">
|
|
<h3 class="signature first" id="can_convert?-class_method">
|
|
|
|
.<strong>can_convert?</strong>(input) ⇒ <tt>Boolean</tt>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
<p>Test if input is convertible to a Glob and if it should be converted</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
<p class="tag_title">Parameters:</p>
|
|
<ul class="param">
|
|
|
|
<li>
|
|
|
|
<span class='name'>input</span>
|
|
|
|
|
|
<span class='type'></span>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p class="tag_title">Returns:</p>
|
|
<ul class="return">
|
|
|
|
<li>
|
|
|
|
|
|
<span class='type'>(<tt>Boolean</tt>)</span>
|
|
|
|
|
|
|
|
—
|
|
<div class='inline'><p>Input can be safely converted to Glob</p>
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
96
|
|
97
|
|
98
|
|
99</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/hyde/pattern_matching/glob.rb', line 96</span>
|
|
|
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_can_convert?'>can_convert?</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>String</span> <span class='kw'>and</span>
|
|
<span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_match?'>match?</span><span class='lparen'>(</span><span class='const'>TOKENS</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="instance_method_details" class="method_details_list">
|
|
<h2>Instance Method Details</h2>
|
|
|
|
|
|
<div class="method_details first">
|
|
<h3 class="signature first" id="match-instance_method">
|
|
|
|
#<strong>match</strong>(input) ⇒ <tt>Array(String,Array,Hash)</tt>, <tt>FalseClass</tt>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
<p>Match the string and assign matches to parameters.
|
|
Returns:</p>
|
|
|
|
<ul>
|
|
<li>Unmatched part of a string</li>
|
|
<li>Unnamed parameters</li>
|
|
<li>Named parameters</li>
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
<p class="tag_title">Parameters:</p>
|
|
<ul class="param">
|
|
|
|
<li>
|
|
|
|
<span class='name'>input</span>
|
|
|
|
|
|
<span class='type'>(<tt>String</tt>)</span>
|
|
|
|
|
|
|
|
—
|
|
<div class='inline'><p>String to match</p>
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p class="tag_title">Returns:</p>
|
|
<ul class="return">
|
|
|
|
<li>
|
|
|
|
|
|
<span class='type'>(<tt>Array(String,Array,Hash)</tt>)</span>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
|
|
<span class='type'>(<tt>FalseClass</tt>)</span>
|
|
|
|
|
|
|
|
—
|
|
<div class='inline'><p>if input doesn't match glob</p>
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
|
79
|
|
80
|
|
81
|
|
82</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/hyde/pattern_matching/glob.rb', line 74</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../../Hyde.html" title="Hyde (module)">Hyde</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../PatternMatching.html" title="Hyde::PatternMatching (module)">PatternMatching</a></span></span><span class='period'>.</span><span class='id identifier rubyid_canonicalize'><span class='object_link'><a href="../PatternMatching.html#canonicalize-class_method" title="Hyde::PatternMatching.canonicalize (method)">canonicalize</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='ivar'>@glob</span><span class='rparen'>)</span>
|
|
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='id identifier rubyid_result'>result</span>
|
|
|
|
<span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_post_match'>post_match</span>
|
|
<span class='id identifier rubyid_named_params'>named_params</span><span class='comma'>,</span> <span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_assign_by_index'>assign_by_index</span><span class='lparen'>(</span><span class='ivar'>@index</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_captures'>captures</span><span class='rparen'>)</span>
|
|
<span class='lbracket'>[</span><span class='id identifier rubyid_input'>input</span><span class='comma'>,</span> <span class='id identifier rubyid_params'>params</span><span class='comma'>,</span> <span class='id identifier rubyid_named_params'>named_params</span><span class='rbracket'>]</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="match?-instance_method">
|
|
|
|
#<strong>match?</strong>(input) ⇒ <tt>Boolean</tt>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
<p>Test if a string can be matched.
|
|
Lighter version of match that doesn't assign any variables.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
<p class="tag_title">Parameters:</p>
|
|
<ul class="param">
|
|
|
|
<li>
|
|
|
|
<span class='name'>input</span>
|
|
|
|
|
|
<span class='type'>(<tt>String</tt>)</span>
|
|
|
|
|
|
|
|
—
|
|
<div class='inline'><p>String to match</p>
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p class="tag_title">Returns:</p>
|
|
<ul class="return">
|
|
|
|
<li>
|
|
|
|
|
|
<span class='type'>(<tt>Boolean</tt>)</span>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
88
|
|
89
|
|
90
|
|
91</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/hyde/pattern_matching/glob.rb', line 88</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_match?'>match?</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../../Hyde.html" title="Hyde (module)">Hyde</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../PatternMatching.html" title="Hyde::PatternMatching (module)">PatternMatching</a></span></span><span class='period'>.</span><span class='id identifier rubyid_canonicalize'><span class='object_link'><a href="../PatternMatching.html#canonicalize-class_method" title="Hyde::PatternMatching.canonicalize (method)">canonicalize</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_match?'>match?</span> <span class='ivar'>@glob</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="footer">
|
|
Generated on Sun Sep 17 00:23:46 2023 by
|
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
0.9.34 (ruby-3.0.6).
|
|
</div>
|
|
|
|
</div>
|
|
</body>
|
|
</html> |