mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 13:35:00 +01:00
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>
30 lines
830 B
Plaintext
30 lines
830 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
|
|
//
|
|
// Inline C++ is scoped `meta.embedded.block.cpp`, so an editor that has a C++
|
|
// grammar highlights them as C++; these renderings come from the Carbon grammar
|
|
// alone, so that content shows plain.
|
|
|
|
package Sample library "interop";
|
|
|
|
import Cpp library "<cstdio>";
|
|
import Cpp library "<string_view>";
|
|
|
|
import Cpp inline '''c++
|
|
int FromImport() { return 1; }
|
|
''';
|
|
|
|
import Cpp inline "int OneLiner() { return 2; }";
|
|
|
|
inline Cpp '''
|
|
int FromBlock() { return 3; }
|
|
''';
|
|
|
|
fn Uses() {
|
|
var value: Cpp.int = 1 as Cpp.int;
|
|
var widened: Cpp.size_t = value as Cpp.size_t;
|
|
var back: i32 = value unsafe as i32;
|
|
Cpp.printf("%d\n", value);
|
|
}
|