mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 14:01:06 +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>
69 lines
904 B
Plaintext
69 lines
904 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
|
|
|
|
// --- string
|
|
|
|
'C'
|
|
"Hello\nWorld\n"
|
|
"\"\'\t\r\n"
|
|
'''Single line string'''
|
|
''' Multi line
|
|
string
|
|
'''
|
|
'''py
|
|
Block literal with a file type indicator.
|
|
'''
|
|
|
|
#"a raw \n literal, where \#n is the escape"#
|
|
##"nested "# stays inside, and \##n is the escape"##
|
|
#'''
|
|
A raw block literal.
|
|
'''#
|
|
|
|
"unterminated
|
|
|
|
// --- characters
|
|
|
|
'a' '\n' '\0' '\u{1F600}'
|
|
'\x70'
|
|
''
|
|
'abcde'
|
|
|
|
// --- true-false
|
|
|
|
true false
|
|
|
|
// --- type-literals
|
|
|
|
array auto bool char str type
|
|
i8 i16 i32 i64 i128 i10
|
|
u8 u16 u32 u64 u128 u11
|
|
f8 f16 f32 f64 f128 f12
|
|
|
|
// --- numbers
|
|
|
|
12345 6789 00012345
|
|
|
|
1234.56789
|
|
0.875
|
|
0.3e5
|
|
1e5
|
|
.123
|
|
.1e3
|
|
|
|
0o755
|
|
0o_17
|
|
0o8
|
|
|
|
0b1011_0010
|
|
0b_010
|
|
0b2345
|
|
0B011
|
|
|
|
0x2AE5
|
|
0x_F109
|
|
0xD8_E2.5F_7Bp8
|
|
0xabcdef.abcdef
|
|
0XA85CE
|