Brace expansion: Difference between revisions
→{{header|TXR}}: Remove a pointless optimization from the parser, and the substitution of the : symbol. The substitution would be necessary if we de-escaped escaped commas.
(→{{header|TXR}}: More notes.) |
(→{{header|TXR}}: Remove a pointless optimization from the parser, and the substitution of the : symbol. The substitution would be necessary if we de-escaped escaped commas.) |
||
Line 5,160:
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:
(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,211:
(nil
(add* "{")
;; expander
Line 5,237 ⟶ 5,233:
(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}}
|