mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-25 06:12:35 +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
60 lines
15 KiB
XML
60 lines
15 KiB
XML
<svg xmlns="http://www.w3.org/2000/svg" width="721" height="1069" viewBox="0 0 721 1069">
|
|
<rect width="100%" height="100%" fill="#1e1e2e"/>
|
|
<g xml:space="preserve" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="14">
|
|
<text style="white-space:pre" x="12" y="26"><tspan fill="#6c7086"> 1 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> Part of the Carbon Language project, under the Apache License v2.0 with LLVM</tspan></text>
|
|
<text style="white-space:pre" x="12" y="45"><tspan fill="#6c7086"> 2 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> Exceptions. See /LICENSE for license information.</tspan></text>
|
|
<text style="white-space:pre" x="12" y="64"><tspan fill="#6c7086"> 3 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception</tspan></text>
|
|
<text style="white-space:pre" x="12" y="83"><tspan fill="#6c7086"> 4 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="102"><tspan fill="#6c7086"> 5 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- operators</tspan></text>
|
|
<text style="white-space:pre" x="12" y="121"><tspan fill="#6c7086"> 6 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="140"><tspan fill="#6c7086"> 7 </tspan><tspan fill="#94e2d5">>>=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5"><=></tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5"><<=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">->?</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">&=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">^=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">:=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">:?</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">==</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">=></tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">!=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">>=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">>></tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5"><=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5"><></tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5"><<</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5"><-</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">-=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">-></tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">--</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">%=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">|=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">+=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">++</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">/=</tspan></text>
|
|
<text style="white-space:pre" x="12" y="159"><tspan fill="#6c7086"> 8 </tspan><tspan fill="#94e2d5">*=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">~=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">&</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">@</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">^</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">:</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">=</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">!</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">></tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5"><</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">-</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">%</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#74c7ec">.</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">|</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">+</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">?</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">/</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">*</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">~</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">\</tspan></text>
|
|
<text style="white-space:pre" x="12" y="178"><tspan fill="#6c7086"> 9 </tspan><tspan fill="#f38ba8">and</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">as</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">impls</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">in</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">like</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">not</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">or</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">typeof</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5" font-style="italic">where</tspan></text>
|
|
<text style="white-space:pre" x="12" y="197"><tspan fill="#6c7086">10 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="216"><tspan fill="#6c7086">11 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- special-keywords</tspan></text>
|
|
<text style="white-space:pre" x="12" y="235"><tspan fill="#6c7086">12 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="254"><tspan fill="#6c7086">13 </tspan><tspan fill="#f38ba8">break</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">case</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">continue</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">else</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">if</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">for</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">match</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">return</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">returned</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">then</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">while</tspan></text>
|
|
<text style="white-space:pre" x="12" y="273"><tspan fill="#6c7086">14 </tspan><tspan fill="#f38ba8">default</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5">=></tspan></text>
|
|
<text style="white-space:pre" x="12" y="292"><tspan fill="#6c7086">15 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="311"><tspan fill="#6c7086">16 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- introducer-keywords</tspan></text>
|
|
<text style="white-space:pre" x="12" y="330"><tspan fill="#6c7086">17 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="349"><tspan fill="#6c7086">18 </tspan><tspan fill="#cba6f7">adapt</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">alias</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">choice</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">class</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">constraint</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">fn</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">import</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">inline</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">interface</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">let</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">library</tspan></text>
|
|
<text style="white-space:pre" x="12" y="368"><tspan fill="#6c7086">19 </tspan><tspan fill="#cba6f7">match_first</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">namespace</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f5e0dc">observe</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">require</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">var</tspan></text>
|
|
<text style="white-space:pre" x="12" y="387"><tspan fill="#6c7086">20 </tspan><tspan fill="#cba6f7">base</tspan></text>
|
|
<text style="white-space:pre" x="12" y="406"><tspan fill="#6c7086">21 </tspan><tspan fill="#cba6f7">export</tspan></text>
|
|
<text style="white-space:pre" x="12" y="425"><tspan fill="#6c7086">22 </tspan><tspan fill="#cba6f7">impl</tspan></text>
|
|
<text style="white-space:pre" x="12" y="444"><tspan fill="#6c7086">23 </tspan><tspan fill="#cba6f7">package</tspan></text>
|
|
<text style="white-space:pre" x="12" y="463"><tspan fill="#6c7086">24 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="482"><tspan fill="#6c7086">25 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- modifier-keywords</tspan></text>
|
|
<text style="white-space:pre" x="12" y="501"><tspan fill="#6c7086">26 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="520"><tspan fill="#6c7086">27 </tspan><tspan fill="#cba6f7" font-style="italic">abstract</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">const</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">eval</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">extend</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">extern</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">final</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">generic</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">musteval</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">override</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">partial</tspan></text>
|
|
<text style="white-space:pre" x="12" y="539"><tspan fill="#6c7086">28 </tspan><tspan fill="#cba6f7" font-style="italic">private</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">protected</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">ref</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">runtime</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">static</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">template</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">unsafe</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">unused</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">val</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7" font-style="italic">virtual</tspan></text>
|
|
<text style="white-space:pre" x="12" y="558"><tspan fill="#6c7086">29 </tspan><tspan fill="#cba6f7" font-style="italic">base</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">class</tspan></text>
|
|
<text style="white-space:pre" x="12" y="577"><tspan fill="#6c7086">30 </tspan><tspan fill="#cba6f7" font-style="italic">default</tspan></text>
|
|
<text style="white-space:pre" x="12" y="596"><tspan fill="#6c7086">31 </tspan><tspan fill="#cba6f7" font-style="italic">export</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f38ba8">import</tspan></text>
|
|
<text style="white-space:pre" x="12" y="615"><tspan fill="#6c7086">32 </tspan><tspan fill="#cba6f7" font-style="italic">impl</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">fn</tspan></text>
|
|
<text style="white-space:pre" x="12" y="634"><tspan fill="#6c7086">33 </tspan><tspan fill="#cba6f7" font-style="italic">impl</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">library</tspan></text>
|
|
<text style="white-space:pre" x="12" y="653"><tspan fill="#6c7086">34 </tspan><tspan fill="#cba6f7" font-style="italic">impl</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cba6f7">package</tspan></text>
|
|
<text style="white-space:pre" x="12" y="672"><tspan fill="#6c7086">35 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="691"><tspan fill="#6c7086">36 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- misc-keywords</tspan></text>
|
|
<text style="white-space:pre" x="12" y="710"><tspan fill="#6c7086">37 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="729"><tspan fill="#6c7086">38 </tspan><tspan fill="#94e2d5" font-style="italic">destroy</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5" font-style="italic">each</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5" font-style="italic">expand</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5" font-style="italic">forall</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5" font-style="italic">form</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5" font-style="italic">friend</tspan></text>
|
|
<text style="white-space:pre" x="12" y="748"><tspan fill="#6c7086">39 </tspan><tspan fill="#cba6f7">fn</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#94e2d5" font-style="italic">destroy</tspan></text>
|
|
<text style="white-space:pre" x="12" y="767"><tspan fill="#6c7086">40 </tspan><tspan fill="#74c7ec">...</tspan><tspan fill="#94e2d5" font-style="italic">expand</tspan></text>
|
|
<text style="white-space:pre" x="12" y="786"><tspan fill="#6c7086">41 </tspan><tspan fill="#74c7ec">.</tspan><tspan fill="#94e2d5" font-style="italic">base</tspan></text>
|
|
<text style="white-space:pre" x="12" y="805"><tspan fill="#6c7086">42 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="824"><tspan fill="#6c7086">43 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- self-keywords</tspan></text>
|
|
<text style="white-space:pre" x="12" y="843"><tspan fill="#6c7086">44 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="862"><tspan fill="#6c7086">45 </tspan><tspan fill="#cdd6f4" font-weight="bold">self</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#cdd6f4" font-weight="bold">Self</tspan></text>
|
|
<text style="white-space:pre" x="12" y="881"><tspan fill="#6c7086">46 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="900"><tspan fill="#6c7086">47 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- package-roots</tspan></text>
|
|
<text style="white-space:pre" x="12" y="919"><tspan fill="#6c7086">48 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="938"><tspan fill="#6c7086">49 </tspan><tspan fill="#f9e2af" font-weight="bold">Core</tspan><tspan fill="#a6adc8"> </tspan><tspan fill="#f9e2af" font-weight="bold">Cpp</tspan></text>
|
|
<text style="white-space:pre" x="12" y="957"><tspan fill="#6c7086">50 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="976"><tspan fill="#6c7086">51 </tspan><tspan fill="#7f849c">//</tspan><tspan fill="#7f849c" font-style="italic"> --- underscore</tspan></text>
|
|
<text style="white-space:pre" x="12" y="995"><tspan fill="#6c7086">52 </tspan></text>
|
|
<text style="white-space:pre" x="12" y="1014"><tspan fill="#6c7086">53 </tspan><tspan fill="#74c7ec" font-weight="bold">;</tspan></text>
|
|
<text style="white-space:pre" x="12" y="1033"><tspan fill="#6c7086">54 </tspan><tspan fill="#cdd6f4" font-weight="bold">_</tspan></text>
|
|
<text style="white-space:pre" x="12" y="1052"><tspan fill="#6c7086">55 </tspan><tspan fill="#cdd6f4">_some_var</tspan></text>
|
|
</g></svg>
|