Files
carbon-lang/utils/highlightjs/highlightjs_example.html
T
Mats Larsen 5d1ef8bb44 move highlightjs code into utils directory (#1472)
Following a short discussion on Discord about where to locate developer tools, I suggest we collect developer utils inside a `/utils` directory at the repository root.

The idea behind this directory is taken from LLVM's utils directories in the various LLVM subprojects which host tooling such as Vim and VSCode extensions, utility scripts, and other useful bits for developers developing or using LLVM.

This patch moves the highlightjs code into said utils directory.

Let me know if there's anything else that's missing 😄

cc @jonmeow
2022-07-20 15:15:23 -04:00

90 lines
1.9 KiB
HTML

<!--
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
-->
<!-- Grab a released highlight.js from one of its CDNs. -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/ir-black.min.css"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script type="module">
import Carbon from './highlightjs_carbon_lang.js';
hljs.registerLanguage('Carbon', Carbon);
hljs.highlightAll();
</script>
<pre><code class="language-carbon">
package Sorting api;
import Carbon library "Printing";
fn Partition[T:! Comparable & Movable](s: Slice(T))
-> i64 {
var i: i64 = -1;
let (x: i64, var y: auto) = (1, {.x = {.a = (1, {.k = 42}), .b = 13}, .y = "..."});
for (e: T in s) {
if (e <= s.Last()) {
++i;
Swap(&s[i], &e);
}
}
return i;
}
fn QuickSort[T:! Comparable & Movable](s: Slice(T)) {
if (s.Size() <= 1) {
return;
}
let p: i64 = Partition(s);
QuickSort(s[:p - 1]));
QuickSort(s[p + 1:]));
}
interface WidgetI {
}
constraint WidgetC {
}
abstract class Abstract {
abstract fn DoSomething[me: Self]();
}
base class Widget {
virtual fn Print[addr me: Self*](var i: i64, x: f32 = 4.2, _: bool);
}
fn Widget.Print[addr me: Self*](var i: i64, x: f32, _: bool, 47) {
Carbon.Print("test" + "t\u{FFFF}his");
Carbon.Print(
"""
testing more
with weird stuff \
that does stuff
""");
Carbon.Print(
"""c++
template &lt;typename T&gt; class C {};
""");
}
class FancyWidget(T:! Type) extends Widget {
impl fn Print[me: Self]();
impl as Add(T) {
fn Op[me: Self]();
}
}
fn FancyWidget(T:! Type).Print[me: Self]() {
Carbon.Print("more test");
}
impl forall [T:! Type] FancyWidget(T) as Printable {
alias Print = FancyWidget(T).Print;
}
</code></pre>