Brace expansion: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(→{{header|TXR}}: More notes.) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 4,989:
templates collateSequence
data part <[]|''> local
@: [''];
$... -> #
$@!
when <´part´ '.*'> do
def part: $;
@: [$@... -> '$;$part;'];
Line 5,039 ⟶ 5,040:
{}} some }{,{\\ edge \,}{ cases, {here} \\\\\}
</pre>
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
Line 5,160 ⟶ 5,162:
This notation is processed by the <code>bexp-expand</code> function to produce the list of strings which it denotes. The <code>bexp-parse</code> function parses a string containing brace expansion into the above notation.
The backslashes and edge cases are handled between the tokenizing and parsing. Backslashed characters are represented as tokens which include the backslash. Thus the <code>\{</code> token compares unequal to <code>{</code> and isn't mistaken for it. These backslashed tokens just look like any other text that has no special meaning
The empty <code>{}</code> is handled as a token, but other cases of braces containing no commas are handled in the parser.
When the parser has scanned
In the main case of a balanced brace with commas, the parsed out elements are split on the commas, which are removed, and that forms the arguments of <code>/</code> node.
<syntaxhighlight lang="txrlisp">;; API
Line 5,197 ⟶ 5,199:
(casequal next
("{" (add (bexp-parse-brace ctx)))
("}" (return :ok))
(t (add next))))
(:ok
(cond
((
(flow (get)
(split* @1 (op where (op
(cons '/)))
(t
Line 5,215 ⟶ 5,213:
(nil
(add* "{")
;; expander
Line 5,237 ⟶ 5,235:
(tprint (brace-expand "It{{em,alic}iz,erat}e{d,}, please."))
(tprint (brace-expand "{,{,gotta have{ ,\\, again\\, }}more }cowbell!"))
(tprint (brace-expand "{}} some }{,{\\\\{ edge, edge} \\,}{ cases, {here} \\\\\\\\\\}"))</syntaxhighlight>
{{out}}
Line 5,365 ⟶ 5,362:
=={{header|Wren}}==
{{trans|Python}}
<syntaxhighlight lang="
var getItem = Fn.new { |s, depth|
Line 5,460 ⟶ 5,457:
{}} some }{,{\\ edge \,}{ cases, {here} \\\\\}
</pre>
=={{header|zkl}}==
This is a two pass algorithm (2*length(string)), one pass to find valid {} pairs, the next pass to expand them.
|