Jump to content

Brace expansion: Difference between revisions

(→‎{{header|TXR}}: Some explanatory notes.)
(→‎{{header|TXR}}: More notes.)
Line 5,159:
 
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. Adding code to the parser to recognize these tokens and strip the backslash would be very easy. Right after the <code>("," (add :))</code> case, adding a case which looks like <code>(`\\@x` (add x))</code> should do the trick.
 
The empty <code>{}</code> is handled as a token, but other cases of braces containing no commas are handled in the parser.
 
The parser for the brace notation replaces <code>,</code> (comma) tokens with the <code>:</code> (colon) keyword symbol. That is then used for splitting the items to form the arguments of <code>/</code>.
 
When the parser has scanned a complete, valid brace that contains no comma, instead of generating a <code>(/ ...)</code> tree node from the content, it generates <code>("{" ... "}")</code>, rendering the braces as literal strings. The <code>...</code> content may contain <code>/</code> operators, as required.
 
When the parser has scanned an incomplete brace, which may contain commas that have been replaced by <code>:</code>, it reverts those symbols back to commas and then puts out <code>("{" ...)</code>: the dangling brace is represented literally, followed by the items that have been parsed out.
 
<syntaxhighlight lang="txrlisp">;; API
543

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.