- Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathhighlightjs_example.html
89 lines (75 loc) · 1.95 KB
/
highlightjs_example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!--
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"
/>
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<scripttype="module">
importCarbonfrom'./highlightjs_carbon_lang.js';
hljs.registerLanguage('Carbon',Carbon);
hljs.highlightAll();
</script>
<pre><codeclass="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[self: Self]();
}
base class Widget {
virtual fn Print[addr self: Self*](var i: i64, x: f32 = 4.2, _: bool);
}
fn Widget.Print[addr self: 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 <typename T> class C {};
""");
}
class FancyWidget(T:! type) extends Widget {
impl fn Print[self: Self]();
impl as Add(T) {
fn Op[self: Self]();
}
}
fn FancyWidget(T:! type).Print[self: Self]() {
Carbon.Print("more test");
}
impl forall [T:! type] FancyWidget(T) as Printable {
alias Print = FancyWidget(T).Print;
}
</code></pre>