Files
carbon-lang/utils/textmate/Samples/functions_variables.carbon
T
Chandler CarruthandDana Jansens 37949a2066 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>
2026-09-15 20:29:22 +00:00

53 lines
1008 B
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
fn F;
fn F1();
fn Func(a: i32, b: A);
fn Generic[T: type, U: I](a: T, b: U) -> U;
fn Lambda(a: i32) -> i32 => return a + 5;
fn
MultiLine[
A: type,
B: C1,
C: C2
](a: A(B, C),
b: B,
c: i32);
fn Invalid#+?Name();
x.(I.F)();
a: A;
a: A = (b as A);
a: i32;
a: array(A, 5);
generic a: type;
generic a: T = b;
a: A in some_list;
var a: T;
let b: T;
binding: T;
generic binding: T;
var
multiline: T;
fn F(ref a: A, const ref b: B);
fn F() -> T;
fn F() -> T.U { return val; }
fn F() -> i32 => return val;
// --- lambdas and positional parameters
var explicit: auto = fn (x: i32) -> i32 { return x + 1; };
var expression: auto = fn (x: i32) => x + 1;
var positional: auto = fn { Print($0, $1, $42); };
// --- raw identifiers
r#class
r#if
r#i32
var r#var: i32 = r#class;