Files
carbon-lang/utils/textmate/Samples/main.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

47 lines
854 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
// More single line comments
package Carbon;
interface HasValueParam(T: type, V: T) {
fn Go(self) -> T;
}
impl () as HasValueParam(i32, 5) {
fn Go(self) -> i32 { return 42; }
}
class Point {
fn Origin() -> Self {
return {.x = 0, .y = 0};
}
var x: i32;
var y: i32;
}
fn Procedure() -> i32 {
returned var zoop: i32 = 0;
while (DoSomeJob()) {
zoop += 1;
}
return var;
}
fn Main() -> i32 {
let str = "Hello world";
let hex = 0xABCDEF1234567890;
let bin = 0b0000111001010010;
let dec = 123456789012345678;
let big: Core.Int(1024) = 1234;
let aaa: auto = "Carbon";
let view: str = "Carbon";
return Procedure();
}