mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 18:58:13 +00:00
This is a re-do of #7888 Outside a call, the grammar scoped a name as a type or a variable by its capitalization. A theme could not distinguish a type from a value with the same spelling, or a parameter, a member, or an implemented interface from any other name. Pointer member access `->` was scoped as a result arrow, which scoped `Lookup` in `regions->Lookup(x)` as a type. `entity.name.type` now applies only in a type position (after `:`, `->`, `as`, `adapt`, or `require`, or in an `impl`) and to the name a nominal declaration declares. A qualifier, in a declared name like `fn N.Base(T: type).F()` or in a type, is `entity.name.scope-resolution` nested in `entity.name.type`. As in the parser, a name is a qualifier when its parameter lists are followed by `.`. Parameters, `let` bindings, choice alternatives, members, implemented interfaces, primitive types, `import`, and the strings naming a builtin or a library have their own scopes, and brackets use the C++ grammar's scopes. A `->` written directly after its operand is member access; no result arrow in the repository is written that way. The sample palette renders each scope that depends on context differently, and `tmlanguage.py` now supports nested captures. In 17 of the 19 themes measured, the VS Code built-ins plus One Dark Pro, Night Owl, Tokyo Night, and Nord, 13% to 27% of the characters in hand-written Carbon change color or style. A theme loses a color where `.` is now punctuation, where word operators like `as` are no longer control-flow keywords, or where a name outside a type position is no longer a type. Assisted-by: Claude Code
76 lines
1.0 KiB
Plaintext
76 lines
1.0 KiB
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.
|
|
'''
|
|
'''sql // A trailing comment on the introducer line.
|
|
SELECT 1;
|
|
'''
|
|
''' // A comment with no file type indicator.
|
|
Text.
|
|
'''
|
|
|
|
#"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'
|
|
"\x4F is an escape, \x4f is not"
|
|
''
|
|
'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
|