UNPKG

meld

Version:

Meld: A template language for LLM prompts

148 lines (142 loc) 5.89 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>@text Directive - meld</title> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Tektur:wght@800&family=Cousine:wght@400;700&display=swap" rel="stylesheet"> <link rel="stylesheet" href="/css/style.css"> <script src="/js/theme.js" defer></script> <script src="/js/terminal.js" defer></script> </head> <body> <header> <div class="container"> <a href="/" class="logo">meld</a> <nav> <ul> <li><a href="/" aria-current=&quot;page&quot;>Home</a></li> <li><a href="/docs/introduction/" >Docs</a></li> <li><a href="https://github.com/meldorg/meld">GitHub</a></li> </ul> </nav> </div> </header> <main> <div class="container"> <div class="docs-layout"> <aside class="docs-sidebar"> <nav> <h3>Documentation</h3> <ul class="nav-list"> <li><a href="/docs/introduction/" >Introduction</a></li> <li><a href="/docs/cli-usage/" >CLI Usage</a></li> <li><a href="/docs/sdk-usage/" >SDK Usage</a></li> <li><a href="/docs/variables/" >Variables</a></li> <li><a href="/docs/error-handling/" >Error Handling</a></li> <li><a href="/docs/grammar-reference/" >Grammar Reference</a></li> </ul> <h3>Directives</h3> <ul class="nav-list"> <li><a href="/docs/directives/" aria-current=&quot;page&quot;>Overview</a></li> <li><a href="/docs/directives/data/" >@data</a></li> <li><a href="/docs/directives/define/" >@define</a></li> <li><a href="/docs/directives/embed/" >@embed</a></li> <li><a href="/docs/directives/import/" >@import</a></li> <li><a href="/docs/directives/path/" >@path</a></li> <li><a href="/docs/directives/run/" >@run</a></li> <li><a href="/docs/directives/text/" aria-current=&quot;page&quot;>@text</a></li> </ul> </nav> </aside> <div class="docs-content"> <h1 id="%40text-directive" tabindex="-1">@text Directive</h1> <p>The <code>@text</code> directive defines a text variable that can store string values.</p> <h2 id="syntax" tabindex="-1">Syntax</h2> <pre><code class="language-meld">@text identifier = &quot;value&quot; @text identifier = @embed [content] @text identifier = @run [command] </code></pre> <p>Where:</p> <ul> <li><code>identifier</code> is the variable name (must be a valid identifier)</li> <li><code>value</code> can be a quoted string, the result of an <code>@embed</code> directive, or the result of an <code>@run</code> directive</li> </ul> <h2 id="identifier-requirements" tabindex="-1">Identifier Requirements</h2> <ul> <li>Must start with a letter or underscore</li> <li>Can contain letters, numbers, and underscores</li> <li>Case-sensitive</li> <li>Cannot be empty</li> </ul> <h2 id="string-values" tabindex="-1">String Values</h2> <p>Text values can be defined using different quote styles:</p> <pre><code class="language-meld">@text simple = &quot;Plain string&quot; # Double quotes @text also_simple = 'Single quotes' # Single quotes @text template = `Hello {{name}}` # Template literal with variable </code></pre> <p>For multi-line strings, use template literals with the <code>[[</code> and <code>]]</code> delimiters:</p> <pre><code class="language-meld">@text multiline = [[` This is a multi-line string with {{variables}} `]] </code></pre> <h2 id="referencing-text-variables" tabindex="-1">Referencing Text Variables</h2> <p>Text variables are referenced using the <code>{{identifier}}</code> syntax:</p> <pre><code class="language-meld">@text name = &quot;World&quot; @text greeting = `Hello, {{name}}!` </code></pre> <h2 id="variable-interpolation" tabindex="-1">Variable Interpolation</h2> <p>Template literals (using backticks) support variable interpolation:</p> <ul> <li>Text variables: <code>Hello, {{name}}!</code></li> <li>Nested variables: <code>Hello, {{user.{{userType}}}}</code></li> </ul> <h2 id="string-concatenation" tabindex="-1">String Concatenation</h2> <pre><code class="language-meld">@text first = &quot;Hello&quot; @text second = &quot;World&quot; @text message = {{first}} ++ &quot; &quot; ++ {{second}} </code></pre> <ul> <li>Requires spaces on both sides of the <code>++</code> operator</li> <li>Joins string parts without adding spaces between them</li> <li>Cannot concatenate across multiple lines</li> </ul> <h2 id="examples" tabindex="-1">Examples</h2> <p>Basic text variable:</p> <pre><code class="language-meld">@text title = &quot;My Document&quot; @text author = &quot;Jane Smith&quot; </code></pre> <p>Using the result of a command:</p> <pre><code class="language-meld">@text date = @run [date +&quot;%Y-%m-%d&quot;] </code></pre> <p>Embedding file content:</p> <pre><code class="language-meld">@text header = @embed [header.md] </code></pre> <h2 id="error-handling" tabindex="-1">Error Handling</h2> <ul> <li>Empty values are not allowed</li> <li>Quotes must match (no mixing of quote types)</li> <li>Circular references in variables will be detected and prevented</li> <li>Variable resolution has a maximum depth (10 levels) to prevent infinite recursion</li> </ul> <h2 id="notes" tabindex="-1">Notes</h2> <ul> <li>Text variables cannot have field access (use data variables for structured data)</li> <li>Text variables can be used in template strings, commands, and data structures</li> <li>Only backtick strings support variable interpolation</li> </ul> </div> </div> </div> </main> <footer> <div class="container"> <p>&copy; 2025 meld - <a href="https://github.com/meldorg/meld">GitHub</a></p> </div> </footer> </body> </html>