Generate the TextMate sample renderings (#7762)

The images beside the samples were screenshots taken by hand, so they
drifted: they still showed `package Carbon api;`, syntax the language
dropped in 2024.

`render_sample.py` renders a sample the way the grammar in this
repository actually highlights it, using `tmlanguage.py`, a small
TextMate tokenizer. VS Code runs grammars under Oniguruma, which we
cannot depend on here, but this grammar uses no Oniguruma-only syntax,
so `re` runs its regexes unchanged and the two agree on every character
of every Carbon file in the repository. The output is SVG, so
regenerating needs nothing but Python, and a later grammar change gets a
same-path image diff showing what it did to real code.

The samples change where a construct left the language (`api`, `Carbon`
as the package name, `StringView`, `destructor`), refresh the
`keywords.carbon` inventory against `token_kind.def`, and add sections
for octal, raw and block literals, character literals, lambdas, and raw
identifiers. `interop.carbon` is new, covering inline C++. These are
highlighting fixtures rather than programs, so the deliberately invalid
lines stay.

Assisted-by: Claude Code

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
This commit is contained in:
Chandler Carruth
2026-09-15 20:29:22 +00:00
committed by GitHub
co-authored by Dana Jansens
parent e962b12e53
commit 37949a2066
27 changed files with 1051 additions and 11 deletions
+20
View File
@@ -0,0 +1,20 @@
<svg xmlns="http://www.w3.org/2000/svg" width="721" height="328" viewBox="0 0 721 328">
<rect width="100%" height="100%" fill="#1f1f1f"/>
<g xml:space="preserve" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="14">
<text style="white-space:pre" x="12" y="26"><tspan fill="#6e7681"> 1 </tspan><tspan fill="#6a9955">// Part of the Carbon Language project, under the Apache License v2.0 with LLVM</tspan></text>
<text style="white-space:pre" x="12" y="45"><tspan fill="#6e7681"> 2 </tspan><tspan fill="#6a9955">// Exceptions. See /LICENSE for license information.</tspan></text>
<text style="white-space:pre" x="12" y="64"><tspan fill="#6e7681"> 3 </tspan><tspan fill="#6a9955">// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception</tspan></text>
<text style="white-space:pre" x="12" y="83"><tspan fill="#6e7681"> 4 </tspan></text>
<text style="white-space:pre" x="12" y="102"><tspan fill="#6e7681"> 5 </tspan><tspan fill="#6a9955">// This is a comment.</tspan></text>
<text style="white-space:pre" x="12" y="121"><tspan fill="#6e7681"> 6 </tspan><tspan fill="#6a9955"> // Comment with whitespace.</tspan></text>
<text style="white-space:pre" x="12" y="140"><tspan fill="#6e7681"> 7 </tspan><tspan fill="#6a9955">// class C; fn F[T: A](a: T) -&gt; i32 { return 86; }</tspan></text>
<text style="white-space:pre" x="12" y="159"><tspan fill="#6e7681"> 8 </tspan><tspan fill="#6a9955">//@dump-sem-ir-begin</tspan></text>
<text style="white-space:pre" x="12" y="178"><tspan fill="#6e7681"> 9 </tspan><tspan fill="#6a9955">//@dump-sem-ir-end</tspan></text>
<text style="white-space:pre" x="12" y="197"><tspan fill="#6e7681">10 </tspan><tspan fill="#6a9955">//@include-in-dumps</tspan></text>
<text style="white-space:pre" x="12" y="216"><tspan fill="#6e7681">11 </tspan><tspan fill="#d4d4d4">//@</tspan><tspan fill="#9cdcfe">dump</tspan><tspan fill="#d4d4d4">-</tspan><tspan fill="#9cdcfe">sem</tspan><tspan fill="#d4d4d4">-</tspan><tspan fill="#9cdcfe">ir</tspan><tspan fill="#d4d4d4">-</tspan></text>
<text style="white-space:pre" x="12" y="235"><tspan fill="#6e7681">12 </tspan><tspan fill="#d4d4d4">//</tspan><tspan fill="#9cdcfe">no</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">whitespace</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">after</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">double</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">slash</tspan></text>
<text style="white-space:pre" x="12" y="254"><tspan fill="#6e7681">13 </tspan><tspan fill="#d4d4d4">/* </tspan><tspan fill="#9cdcfe">invalid</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">comment</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">pattern</tspan><tspan fill="#d4d4d4">. */</tspan></text>
<text style="white-space:pre" x="12" y="273"><tspan fill="#6e7681">14 </tspan><tspan fill="#d4d4d4">/// </tspan><tspan fill="#9cdcfe">invalid</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">comment</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">pattern</tspan><tspan fill="#d4d4d4">.</tspan></text>
<text style="white-space:pre" x="12" y="292"><tspan fill="#6e7681">15 </tspan><tspan fill="#569cd6">class</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#4ec9b0">C</tspan><tspan fill="#d4d4d4">; // </tspan><tspan fill="#9cdcfe">Comment</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">after</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">a</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">statement</tspan><tspan fill="#d4d4d4">/</tspan><tspan fill="#9cdcfe">expression</tspan><tspan fill="#d4d4d4">/</tspan><tspan fill="#9cdcfe">declaration</tspan><tspan fill="#d4d4d4">.</tspan></text>
<text style="white-space:pre" x="12" y="311"><tspan fill="#6e7681">16 </tspan><tspan fill="#569cd6">var</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">x</tspan><tspan fill="#d4d4d4">: </tspan><tspan fill="#569cd6">i32</tspan><tspan fill="#d4d4d4"> = </tspan><tspan fill="#b5cea8">1</tspan><tspan fill="#d4d4d4">;// </tspan><tspan fill="#9cdcfe">Trailing</tspan><tspan fill="#d4d4d4">, </tspan><tspan fill="#9cdcfe">with</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">no</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">space</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">before</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">the</tspan><tspan fill="#d4d4d4"> </tspan><tspan fill="#9cdcfe">introducer</tspan><tspan fill="#d4d4d4">.</tspan></text>
</g></svg>

After

Width:  |  Height:  |  Size: 4.5 KiB