highlightjs_example.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!--
  2. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  3. Exceptions. See /LICENSE for license information.
  4. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. -->
  6. <!-- Grab a released highlight.js from one of its CDNs. -->
  7. <link
  8. rel="stylesheet"
  9. href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/ir-black.min.css"
  10. />
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
  12. <script type="module">
  13. import Carbon from './highlightjs_carbon_lang.js';
  14. hljs.registerLanguage('Carbon', Carbon);
  15. hljs.highlightAll();
  16. </script>
  17. <pre><code class="language-carbon">
  18. package Sorting api;
  19. import Carbon library "Printing";
  20. fn Partition[T:! Comparable & Movable](s: Slice(T))
  21. -> i64 {
  22. var i: i64 = -1;
  23. let (x: i64, var y: i64) = (1, 2);
  24. for (e: T in s) {
  25. if (e <= s.Last()) {
  26. ++i;
  27. Swap(&s[i], &e);
  28. }
  29. }
  30. return i;
  31. }
  32. fn QuickSort[T:! Comparable & Movable](s: Slice(T)) {
  33. if (s.Size() <= 1) {
  34. return;
  35. }
  36. let p: i64 = Partition(s);
  37. QuickSort(s[:p - 1]));
  38. QuickSort(s[p + 1:]));
  39. }
  40. interface WidgetI {
  41. }
  42. constraint WidgetC {
  43. }
  44. base class Widget {
  45. fn Print[addr me: Self*](var i: i64, x: f32 = 4.2, _: bool);
  46. }
  47. fn Widget.Print[addr me: Self*](var i: i64, x: f32, _: bool, 47) {
  48. Carbon.Print("test" + "t\u{FFFF}his");
  49. Carbon.Print(
  50. """
  51. testing more
  52. with weird stuff \
  53. that does stuff
  54. """);
  55. Carbon.Print(
  56. """c++
  57. template &lt;typename T&gt; class C {};
  58. """);
  59. }
  60. class FancyWidget(T:! Type) extends Widget {
  61. fn Print[me: Self]();
  62. impl as Add(T) {
  63. fn Op[me: Self]();
  64. }
  65. }
  66. fn FancyWidget(T:! Type).Print[me: Self]() {
  67. Carbon.Print("more test");
  68. }
  69. impl forall [T:! Type] FancyWidget(T) as Printable {
  70. alias Print = FancyWidget(T).Print;
  71. }
  72. </code></pre>