aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/SYNTAX.md16
-rw-r--r--docs/TYPES.md6
-rw-r--r--docs/book/SYNTAX.html16
-rw-r--r--docs/book/TYPES.html6
-rw-r--r--docs/book/highlight.js2506
-rw-r--r--docs/book/tomorrow-night.css15
6 files changed, 1574 insertions, 991 deletions
diff --git a/docs/SYNTAX.md b/docs/SYNTAX.md
index c6e96f6..249d6e3 100644
--- a/docs/SYNTAX.md
+++ b/docs/SYNTAX.md
@@ -4,7 +4,7 @@
There is little difference between a function, macro, and operator call. There are only a few forms such calls can take, too, though notably more than most other languages (due to, among other things, uniform function call syntax): hence this section.
-```
+```puck
# The standard, unambiguous call.
routine(1, 2, 3, 4)
# The method call syntax equivalent.
@@ -22,7 +22,7 @@ routine 1, 2, 3, 4
Binary operators have some special rules.
-```
+```puck
# Valid call syntaxes for binary operators. What can constitute a binary
# operator is constrained for parsing's sake. Whitespace is optional.
1 + 2
@@ -33,7 +33,7 @@ Binary operators have some special rules.
As do unary operators.
-```
+```puck
# The standard call for unary operators. Postfix.
1?
?(1)
@@ -41,7 +41,7 @@ As do unary operators.
Method call syntax has a number of advantages: notably that it can be *chained*: acting as a natural pipe operator. Redundant parenthesis can also be omitted.
-```
+```puck
# The following statements are equivalent:
foo.bar.baz
foo().bar().baz()
@@ -110,7 +110,7 @@ of that then ...
A line beginning with a scope token is treated as attached to the previous expression.
-```
+```puck
# Technically allowed. Please don't do this.
let foo
= ...
@@ -132,7 +132,7 @@ of that then ...
This *can* lead to some ugly possibilities for formatting that are best avoided.
-```
+```puck
# Much preferred.
let foo =
@@ -166,7 +166,7 @@ There are some syntactic constructs unambiguously recognizable as statements: al
Expressions can go almost anywhere. Our indentation rules above allow for it.
-```
+```puck
# Some different formulations of valid expressions.
if cond then
@@ -190,7 +190,7 @@ let foo =
that
```
-```
+```puck
# Some different formulations of *invalid* expressions.
# These primarily break the rule that everything following a scope token
# (ex. `=`, `do`, `then`) not at the end of the line must be self-contained.
diff --git a/docs/TYPES.md b/docs/TYPES.md
index 5ea320a..5d97db5 100644
--- a/docs/TYPES.md
+++ b/docs/TYPES.md
@@ -259,15 +259,15 @@ func eval(context: mut HashTable[Ident, Value], expr: Expr): Result[Value]
of Variable(ident) then
context.get(ident).err("Variable not in context")
of Application(body, arg) then
- if body of Abstraction(param, body as inner_body):
+ if body of Abstraction(param, body as inner_body) then
context.set(param, context.eval(arg)?) # from std.tables
context.eval(inner_body)
else
Error("Expected Abstraction, found {}".fmt(body))
- of Conditional(condition, then_case, else_case):
+ of Conditional(condition, then_case, else_case) then
if context.eval(condition)? == "true" then
context.eval(then_case)
- else:
+ else
context.eval(else_case)
of expr then
Error("Invalid expression {}".fmt(expr))
diff --git a/docs/book/SYNTAX.html b/docs/book/SYNTAX.html
index 4860718..6783b5e 100644
--- a/docs/book/SYNTAX.html
+++ b/docs/book/SYNTAX.html
@@ -176,7 +176,7 @@
<h1 id="syntax-a-casual-and-formal-look"><a class="header" href="#syntax-a-casual-and-formal-look">Syntax: A Casual and Formal Look</a></h1>
<h2 id="call-syntax"><a class="header" href="#call-syntax">Call Syntax</a></h2>
<p>There is little difference between a function, macro, and operator call. There are only a few forms such calls can take, too, though notably more than most other languages (due to, among other things, uniform function call syntax): hence this section.</p>
-<pre><code># The standard, unambiguous call.
+<pre><code class="language-puck"># The standard, unambiguous call.
routine(1, 2, 3, 4)
# The method call syntax equivalent.
1.routine(2, 3, 4)
@@ -191,7 +191,7 @@ routine
routine 1, 2, 3, 4
</code></pre>
<p>Binary operators have some special rules.</p>
-<pre><code># Valid call syntaxes for binary operators. What can constitute a binary
+<pre><code class="language-puck"># Valid call syntaxes for binary operators. What can constitute a binary
# operator is constrained for parsing's sake. Whitespace is optional.
1 + 2
1+2
@@ -199,12 +199,12 @@ routine 1, 2, 3, 4
+(1, 2)
</code></pre>
<p>As do unary operators.</p>
-<pre><code># The standard call for unary operators. Postfix.
+<pre><code class="language-puck"># The standard call for unary operators. Postfix.
1?
?(1)
</code></pre>
<p>Method call syntax has a number of advantages: notably that it can be <em>chained</em>: acting as a natural pipe operator. Redundant parenthesis can also be omitted.</p>
-<pre><code># The following statements are equivalent:
+<pre><code class="language-puck"># The following statements are equivalent:
foo.bar.baz
foo().bar().baz()
baz(bar(foo))
@@ -252,7 +252,7 @@ of this then ...
of that then ...
</code></pre>
<p>A line beginning with a scope token is treated as attached to the previous expression.</p>
-<pre><code># Technically allowed. Please don't do this.
+<pre><code class="language-puck"># Technically allowed. Please don't do this.
let foo
= ...
@@ -271,7 +271,7 @@ then ...
of that then ...
</code></pre>
<p>This <em>can</em> lead to some ugly possibilities for formatting that are best avoided.</p>
-<pre><code># Much preferred.
+<pre><code class="language-puck"># Much preferred.
let foo =
...
@@ -298,7 +298,7 @@ of that then ...
<p>First, a word on the distinction between <em>expressions</em> and <em>statements</em>. Expressions return a value. Statements do not. That is all.</p>
<p>There are some syntactic constructs unambiguously recognizable as statements: all declarations, modules, and <code>use</code> statements. There are no syntactic constructs unambiguously recognizable as expressions. As calls returning <code>void</code> are treated as statements, and expressions that return a type could possibly return <code>void</code>, there is no explicit distinction between expressions and statements made in the parser: or anywhere before type-checking.</p>
<p>Expressions can go almost anywhere. Our indentation rules above allow for it.</p>
-<pre><code># Some different formulations of valid expressions.
+<pre><code class="language-puck"># Some different formulations of valid expressions.
if cond then
this
@@ -320,7 +320,7 @@ let foo =
else
that
</code></pre>
-<pre><code># Some different formulations of *invalid* expressions.
+<pre><code class="language-puck"># Some different formulations of *invalid* expressions.
# These primarily break the rule that everything following a scope token
# (ex. `=`, `do`, `then`) not at the end of the line must be self-contained.
diff --git a/docs/book/TYPES.html b/docs/book/TYPES.html
index 5abe998..1054e03 100644
--- a/docs/book/TYPES.html
+++ b/docs/book/TYPES.html
@@ -395,15 +395,15 @@ func eval(context: mut HashTable[Ident, Value], expr: Expr): Result[Value]
of Variable(ident) then
context.get(ident).err("Variable not in context")
of Application(body, arg) then
- if body of Abstraction(param, body as inner_body):
+ if body of Abstraction(param, body as inner_body) then
context.set(param, context.eval(arg)?) # from std.tables
context.eval(inner_body)
else
Error("Expected Abstraction, found {}".fmt(body))
- of Conditional(condition, then_case, else_case):
+ of Conditional(condition, then_case, else_case) then
if context.eval(condition)? == "true" then
context.eval(then_case)
- else:
+ else
context.eval(else_case)
of expr then
Error("Invalid expression {}".fmt(expr))
diff --git a/docs/book/highlight.js b/docs/book/highlight.js
index 2661c0e..2352580 100644
--- a/docs/book/highlight.js
+++ b/docs/book/highlight.js
@@ -1,6 +1,6 @@
/*!
- Highlight.js v11.9.0 (git: 215b7639e5)
- (c) 2006-2023 undefined and other contributors
+ Highlight.js v11.9.0 (git: ea6ad285eb)
+ (c) 2006-2024 Josh Goebel <hello@joshgoebel.com> and other contributors
License: BSD-3-Clause
*/
var hljs = (function () {
@@ -2604,634 +2604,6 @@ var hljs = (function () {
var HighlightJS = highlight;
/*
- Language: Puck
- Description: Puck is a whitespace-sensitive, memory-safe, interface-oriented, imperative language with functional underpinnings.
- Website: https://puck-lang.org
- Category: system
- */
-
- function puck(hljs) {
- const TYPES = [
- "struct",
- "tuple",
- "union",
- "enum",
- "class",
- "ref",
- "refc",
- "ptr",
- "array",
- "list",
- "slice",
- "int",
- "uint",
- "float",
- "dec",
- "i8",
- "i16",
- "i32",
- "i64",
- "i128",
- "u8",
- "u16",
- "u32",
- "u64",
- "u128",
- "f32",
- "f64",
- "f128",
- "dec64",
- "dec128",
- "void",
- "empty",
- "never",
- "bool",
- "byte",
- "chr",
- "str"
- ];
- const KEYWORDS = [
- "pub",
- "let",
- "var",
- "const",
- "func",
- "macro",
- "type",
- "mod",
- "use",
- "as",
- "for",
- "in",
- "do",
- "while",
- "loop",
- "block",
- "if",
- "then",
- "elif",
- "else",
- "when",
- "match",
- "of",
- "where",
- "try",
- "catch",
- "finally",
- "lent",
- "mut",
- "break",
- "continue",
- "return",
- "is"
- ];
- const BUILT_INS = [
- "stdin",
- "stdout",
- "stderr",
- "result"
- ];
- const LITERALS = [
- "true",
- "unit",
- "false",
- // "some",
- // "none",
- ];
- return {
- name: 'Puck',
- aliases: [ 'pk' ],
- keywords: {
- keyword: KEYWORDS,
- literal: LITERALS,
- type: TYPES,
- built_in: BUILT_INS
- },
- contains: [
- {
- className: 'string',
- begin: /[a-zA-Z]\w*"/,
- end: /"/,
- contains: [ { begin: /""/ } ]
- },
- {
- className: 'string',
- begin: /([a-zA-Z]\w*)?"""/,
- end: /"""/
- },
- hljs.QUOTE_STRING_MODE,
- {
- className: 'type',
- begin: /\b[A-Z]\w+\b/,
- relevance: 0
- },
- {
- className: 'number',
- relevance: 0,
- variants: [
- { begin: /\b(0[xX][0-9a-fA-F][_0-9a-fA-F]*)('?[iIuU](8|16|32|64))?/ },
- { begin: /\b(0o[0-7][_0-7]*)('?[iIuUfF](8|16|32|64))?/ },
- { begin: /\b(0(b|B)[01][_01]*)('?[iIuUfF](8|16|32|64))?/ },
- { begin: /\b(\d[_\d]*)('?[iIuUfF](8|16|32|64))?/ }
- ]
- },
- hljs.HASH_COMMENT_MODE
- ]
- };
- }
-
- /*
- Language: Nim
- Description: Nim is a statically typed compiled systems programming language.
- Website: https://nim-lang.org
- Category: system
- */
-
- function nim(hljs) {
- const TYPES = [
- "int",
- "int8",
- "int16",
- "int32",
- "int64",
- "uint",
- "uint8",
- "uint16",
- "uint32",
- "uint64",
- "float",
- "float32",
- "float64",
- "bool",
- "char",
- "string",
- "cstring",
- "pointer",
- "expr",
- "stmt",
- "void",
- "auto",
- "any",
- "range",
- "array",
- "openarray",
- "varargs",
- "seq",
- "set",
- "clong",
- "culong",
- "cchar",
- "cschar",
- "cshort",
- "cint",
- "csize",
- "clonglong",
- "cfloat",
- "cdouble",
- "clongdouble",
- "cuchar",
- "cushort",
- "cuint",
- "culonglong",
- "cstringarray",
- "semistatic"
- ];
- const KEYWORDS = [
- "addr",
- "and",
- "as",
- "asm",
- "bind",
- "block",
- "break",
- "case",
- "cast",
- "const",
- "continue",
- "converter",
- "discard",
- "distinct",
- "div",
- "do",
- "elif",
- "else",
- "end",
- "enum",
- "except",
- "export",
- "finally",
- "for",
- "from",
- "func",
- "generic",
- "guarded",
- "if",
- "import",
- "in",
- "include",
- "interface",
- "is",
- "isnot",
- "iterator",
- "let",
- "macro",
- "method",
- "mixin",
- "mod",
- "nil",
- "not",
- "notin",
- "object",
- "of",
- "or",
- "out",
- "proc",
- "ptr",
- "raise",
- "ref",
- "return",
- "shared",
- "shl",
- "shr",
- "static",
- "template",
- "try",
- "tuple",
- "type",
- "using",
- "var",
- "when",
- "while",
- "with",
- "without",
- "xor",
- "yield"
- ];
- const BUILT_INS = [
- "stdin",
- "stdout",
- "stderr",
- "result"
- ];
- const LITERALS = [
- "true",
- "false"
- ];
- return {
- name: 'Nim',
- keywords: {
- keyword: KEYWORDS,
- literal: LITERALS,
- type: TYPES,
- built_in: BUILT_INS
- },
- contains: [
- {
- className: 'meta', // Actually pragma
- begin: /\{\./,
- end: /\.\}/,
- relevance: 10
- },
- {
- className: 'string',
- begin: /[a-zA-Z]\w*"/,
- end: /"/,
- contains: [ { begin: /""/ } ]
- },
- {
- className: 'string',
- begin: /([a-zA-Z]\w*)?"""/,
- end: /"""/
- },
- hljs.QUOTE_STRING_MODE,
- {
- className: 'type',
- begin: /\b[A-Z]\w+\b/,
- relevance: 0
- },
- {
- className: 'number',
- relevance: 0,
- variants: [
- { begin: /\b(0[xX][0-9a-fA-F][_0-9a-fA-F]*)('?[iIuU](8|16|32|64))?/ },
- { begin: /\b(0o[0-7][_0-7]*)('?[iIuUfF](8|16|32|64))?/ },
- { begin: /\b(0(b|B)[01][_01]*)('?[iIuUfF](8|16|32|64))?/ },
- { begin: /\b(\d[_\d]*)('?[iIuUfF](8|16|32|64))?/ }
- ]
- },
- hljs.HASH_COMMENT_MODE
- ]
- };
- }
-
- /*
- Language: Rust
- Author: Andrey Vlasovskikh <andrey.vlasovskikh@gmail.com>
- Contributors: Roman Shmatov <romanshmatov@gmail.com>, Kasper Andersen <kma_untrusted@protonmail.com>
- Website: https://www.rust-lang.org
- Category: common, system
- */
-
- /** @type LanguageFn */
- function rust(hljs) {
- const regex = hljs.regex;
- const FUNCTION_INVOKE = {
- className: "title.function.invoke",
- relevance: 0,
- begin: regex.concat(
- /\b/,
- /(?!let|for|while|if|else|match\b)/,
- hljs.IDENT_RE,
- regex.lookahead(/\s*\(/))
- };
- const NUMBER_SUFFIX = '([ui](8|16|32|64|128|size)|f(32|64))\?';
- const KEYWORDS = [
- "abstract",
- "as",
- "async",
- "await",
- "become",
- "box",
- "break",
- "const",
- "continue",
- "crate",
- "do",
- "dyn",
- "else",
- "enum",
- "extern",
- "false",
- "final",
- "fn",
- "for",
- "if",
- "impl",
- "in",
- "let",
- "loop",
- "macro",
- "match",
- "mod",
- "move",
- "mut",
- "override",
- "priv",
- "pub",
- "ref",
- "return",
- "self",
- "Self",
- "static",
- "struct",
- "super",
- "trait",
- "true",
- "try",
- "type",
- "typeof",
- "unsafe",
- "unsized",
- "use",
- "virtual",
- "where",
- "while",
- "yield"
- ];
- const LITERALS = [
- "true",
- "false",
- "Some",
- "None",
- "Ok",
- "Err"
- ];
- const BUILTINS = [
- // functions
- 'drop ',
- // traits
- "Copy",
- "Send",
- "Sized",
- "Sync",
- "Drop",
- "Fn",
- "FnMut",
- "FnOnce",
- "ToOwned",
- "Clone",
- "Debug",
- "PartialEq",
- "PartialOrd",
- "Eq",
- "Ord",
- "AsRef",
- "AsMut",
- "Into",
- "From",
- "Default",
- "Iterator",
- "Extend",
- "IntoIterator",
- "DoubleEndedIterator",
- "ExactSizeIterator",
- "SliceConcatExt",
- "ToString",
- // macros
- "assert!",
- "assert_eq!",
- "bitflags!",
- "bytes!",
- "cfg!",
- "col!",
- "concat!",
- "concat_idents!",
- "debug_assert!",
- "debug_assert_eq!",
- "env!",
- "eprintln!",
- "panic!",
- "file!",
- "format!",
- "format_args!",
- "include_bytes!",
- "include_str!",
- "line!",
- "local_data_key!",
- "module_path!",
- "option_env!",
- "print!",
- "println!",
- "select!",
- "stringify!",
- "try!",
- "unimplemented!",
- "unreachable!",
- "vec!",
- "write!",
- "writeln!",
- "macro_rules!",
- "assert_ne!",
- "debug_assert_ne!"
- ];
- const TYPES = [
- "i8",
- "i16",
- "i32",
- "i64",
- "i128",
- "isize",
- "u8",
- "u16",
- "u32",
- "u64",
- "u128",
- "usize",
- "f32",
- "f64",
- "str",
- "char",
- "bool",
- "Box",
- "Option",
- "Result",
- "String",
- "Vec"
- ];
- return {
- name: 'Rust',
- aliases: [ 'rs' ],
- keywords: {
- $pattern: hljs.IDENT_RE + '!?',
- type: TYPES,
- keyword: KEYWORDS,
- literal: LITERALS,
- built_in: BUILTINS
- },
- illegal: '</',
- contains: [
- hljs.C_LINE_COMMENT_MODE,
- hljs.COMMENT('/\\*', '\\*/', { contains: [ 'self' ] }),
- hljs.inherit(hljs.QUOTE_STRING_MODE, {
- begin: /b?"/,
- illegal: null
- }),
- {
- className: 'string',
- variants: [
- { begin: /b?r(#*)"(.|\n)*?"\1(?!#)/ },
- { begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ }
- ]
- },
- {
- className: 'symbol',
- begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
- },
- {
- className: 'number',
- variants: [
- { begin: '\\b0b([01_]+)' + NUMBER_SUFFIX },
- { begin: '\\b0o([0-7_]+)' + NUMBER_SUFFIX },
- { begin: '\\b0x([A-Fa-f0-9_]+)' + NUMBER_SUFFIX },
- { begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)'
- + NUMBER_SUFFIX }
- ],
- relevance: 0
- },
- {
- begin: [
- /fn/,
- /\s+/,
- hljs.UNDERSCORE_IDENT_RE
- ],
- className: {
- 1: "keyword",
- 3: "title.function"
- }
- },
- {
- className: 'meta',
- begin: '#!?\\[',
- end: '\\]',
- contains: [
- {
- className: 'string',
- begin: /"/,
- end: /"/,
- contains: [
- hljs.BACKSLASH_ESCAPE
- ]
- }
- ]
- },
- {
- begin: [
- /let/,
- /\s+/,
- /(?:mut\s+)?/,
- hljs.UNDERSCORE_IDENT_RE
- ],
- className: {
- 1: "keyword",
- 3: "keyword",
- 4: "variable"
- }
- },
- // must come before impl/for rule later
- {
- begin: [
- /for/,
- /\s+/,
- hljs.UNDERSCORE_IDENT_RE,
- /\s+/,
- /in/
- ],
- className: {
- 1: "keyword",
- 3: "variable",
- 5: "keyword"
- }
- },
- {
- begin: [
- /type/,
- /\s+/,
- hljs.UNDERSCORE_IDENT_RE
- ],
- className: {
- 1: "keyword",
- 3: "title.class"
- }
- },
- {
- begin: [
- /(?:trait|enum|struct|union|impl|for)/,
- /\s+/,
- hljs.UNDERSCORE_IDENT_RE
- ],
- className: {
- 1: "keyword",
- 3: "title.class"
- }
- },
- {
- begin: hljs.IDENT_RE + '::',
- keywords: {
- keyword: "Self",
- built_in: BUILTINS,
- type: TYPES
- }
- },
- {
- className: "punctuation",
- begin: '->'
- },
- FUNCTION_INVOKE
- ]
- };
- }
-
- /*
Language: Bash
Author: vah <vahtenberg@gmail.com>
Contributrors: Benjamin Pannell <contact@sierrasoftworks.com>
@@ -3416,6 +2788,7 @@ var hljs = (function () {
"read",
"readarray",
"source",
+ "sudo",
"type",
"typeset",
"ulimit",
@@ -3601,7 +2974,10 @@ var hljs = (function () {
return {
name: 'Bash',
- aliases: [ 'sh' ],
+ aliases: [
+ 'sh',
+ 'zsh'
+ ],
keywords: {
$pattern: /\b[a-z][a-z0-9._-]+\b/,
keyword: KEYWORDS,
@@ -3633,6 +3009,1085 @@ var hljs = (function () {
};
}
+ /*
+ Language: C
+ Category: common, system
+ Website: https://en.wikipedia.org/wiki/C_(programming_language)
+ */
+
+ /** @type LanguageFn */
+ function c(hljs) {
+ const regex = hljs.regex;
+ // added for historic reasons because `hljs.C_LINE_COMMENT_MODE` does
+ // not include such support nor can we be sure all the grammars depending
+ // on it would desire this behavior
+ const C_LINE_COMMENT_MODE = hljs.COMMENT('//', '$', { contains: [ { begin: /\\\n/ } ] });
+ const DECLTYPE_AUTO_RE = 'decltype\\(auto\\)';
+ const NAMESPACE_RE = '[a-zA-Z_]\\w*::';
+ const TEMPLATE_ARGUMENT_RE = '<[^<>]+>';
+ const FUNCTION_TYPE_RE = '('
+ + DECLTYPE_AUTO_RE + '|'
+ + regex.optional(NAMESPACE_RE)
+ + '[a-zA-Z_]\\w*' + regex.optional(TEMPLATE_ARGUMENT_RE)
+ + ')';
+
+
+ const TYPES = {
+ className: 'type',
+ variants: [
+ { begin: '\\b[a-z\\d_]*_t\\b' },
+ { match: /\batomic_[a-z]{3,6}\b/ }
+ ]
+
+ };
+
+ // https://en.cppreference.com/w/cpp/language/escape
+ // \\ \x \xFF \u2837 \u00323747 \374
+ const CHARACTER_ESCAPES = '\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)';
+ const STRINGS = {
+ className: 'string',
+ variants: [
+ {
+ begin: '(u8?|U|L)?"',
+ end: '"',
+ illegal: '\\n',
+ contains: [ hljs.BACKSLASH_ESCAPE ]
+ },
+ {
+ begin: '(u8?|U|L)?\'(' + CHARACTER_ESCAPES + "|.)",
+ end: '\'',
+ illegal: '.'
+ },
+ hljs.END_SAME_AS_BEGIN({
+ begin: /(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,
+ end: /\)([^()\\ ]{0,16})"/
+ })
+ ]
+ };
+
+ const NUMBERS = {
+ className: 'number',
+ variants: [
+ { begin: '\\b(0b[01\']+)' },
+ { begin: '(-?)\\b([\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)' },
+ { begin: '(-?)(\\b0[xX][a-fA-F0-9\']+|(\\b[\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)([eE][-+]?[\\d\']+)?)' }
+ ],
+ relevance: 0
+ };
+
+ const PREPROCESSOR = {
+ className: 'meta',
+ begin: /#\s*[a-z]+\b/,
+ end: /$/,
+ keywords: { keyword:
+ 'if else elif endif define undef warning error line '
+ + 'pragma _Pragma ifdef ifndef elifdef elifndef include' },
+ contains: [
+ {
+ begin: /\\\n/,
+ relevance: 0
+ },
+ hljs.inherit(STRINGS, { className: 'string' }),
+ {
+ className: 'string',
+ begin: /<.*?>/
+ },
+ C_LINE_COMMENT_MODE,
+ hljs.C_BLOCK_COMMENT_MODE
+ ]
+ };
+
+ const TITLE_MODE = {
+ className: 'title',
+ begin: regex.optional(NAMESPACE_RE) + hljs.IDENT_RE,
+ relevance: 0
+ };
+
+ const FUNCTION_TITLE = regex.optional(NAMESPACE_RE) + hljs.IDENT_RE + '\\s*\\(';
+
+ const C_KEYWORDS = [
+ "asm",
+ "auto",
+ "break",
+ "case",
+ "continue",
+ "default",
+ "do",
+ "else",
+ "enum",
+ "extern",
+ "for",
+ "fortran",
+ "goto",
+ "if",
+ "inline",
+ "register",
+ "restrict",
+ "return",
+ "sizeof",
+ "struct",
+ "switch",
+ "typedef",
+ "union",
+ "volatile",
+ "while",
+ "_Alignas",
+ "_Alignof",
+ "_Atomic",
+ "_Generic",
+ "_Noreturn",
+ "_Static_assert",
+ "_Thread_local",
+ // aliases
+ "alignas",
+ "alignof",
+ "noreturn",
+ "static_assert",
+ "thread_local",
+ // not a C keyword but is, for all intents and purposes, treated exactly like one.
+ "_Pragma"
+ ];
+
+ const C_TYPES = [
+ "float",
+ "double",
+ "signed",
+ "unsigned",
+ "int",
+ "short",
+ "long",
+ "char",
+ "void",
+ "_Bool",
+ "_BitInt",
+ "_Complex",
+ "_Imaginary",
+ "_Decimal32",
+ "_Decimal64",
+ "_Decimal96",
+ "_Decimal128",
+ "_Decimal64x",
+ "_Decimal128x",
+ "_Float16",
+ "_Float32",
+ "_Float64",
+ "_Float128",
+ "_Float32x",
+ "_Float64x",
+ "_Float128x",
+ // modifiers
+ "const",
+ "static",
+ "constexpr",
+ // aliases
+ "complex",
+ "bool",
+ "imaginary"
+ ];
+
+ const KEYWORDS = {
+ keyword: C_KEYWORDS,
+ type: C_TYPES,
+ literal: 'true false NULL',
+ // TODO: apply hinting work similar to what was done in cpp.js
+ built_in: 'std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream '
+ + 'auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set '
+ + 'unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos '
+ + 'asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp '
+ + 'fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper '
+ + 'isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow '
+ + 'printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp '
+ + 'strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan '
+ + 'vfprintf vprintf vsprintf endl initializer_list unique_ptr',
+ };
+
+ const EXPRESSION_CONTAINS = [
+ PREPROCESSOR,
+ TYPES,
+ C_LINE_COMMENT_MODE,
+ hljs.C_BLOCK_COMMENT_MODE,
+ NUMBERS,
+ STRINGS
+ ];
+
+ const EXPRESSION_CONTEXT = {
+ // This mode covers expression context where we can't expect a function
+ // definition and shouldn't highlight anything that looks like one:
+ // `return some()`, `else if()`, `(x*sum(1, 2))`
+ variants: [
+ {
+ begin: /=/,
+ end: /;/
+ },
+ {
+ begin: /\(/,
+ end: /\)/
+ },
+ {
+ beginKeywords: 'new throw return else',
+ end: /;/
+ }
+ ],
+ keywords: KEYWORDS,
+ contains: EXPRESSION_CONTAINS.concat([
+ {
+ begin: /\(/,
+ end: /\)/,
+ keywords: KEYWORDS,
+ contains: EXPRESSION_CONTAINS.concat([ 'self' ]),
+ relevance: 0
+ }
+ ]),
+ relevance: 0
+ };
+
+ const FUNCTION_DECLARATION = {
+ begin: '(' + FUNCTION_TYPE_RE + '[\\*&\\s]+)+' + FUNCTION_TITLE,
+ returnBegin: true,
+ end: /[{;=]/,
+ excludeEnd: true,
+ keywords: KEYWORDS,
+ illegal: /[^\w\s\*&:<>.]/,
+ contains: [
+ { // to prevent it from being confused as the function title
+ begin: DECLTYPE_AUTO_RE,
+ keywords: KEYWORDS,
+ relevance: 0
+ },
+ {
+ begin: FUNCTION_TITLE,
+ returnBegin: true,
+ contains: [ hljs.inherit(TITLE_MODE, { className: "title.function" }) ],
+ relevance: 0
+ },
+ // allow for multiple declarations, e.g.:
+ // extern void f(int), g(char);
+ {
+ relevance: 0,
+ match: /,/
+ },
+ {
+ className: 'params',
+ begin: /\(/,
+ end: /\)/,
+ keywords: KEYWORDS,
+ relevance: 0,
+ contains: [
+ C_LINE_COMMENT_MODE,
+ hljs.C_BLOCK_COMMENT_MODE,
+ STRINGS,
+ NUMBERS,
+ TYPES,
+ // Count matching parentheses.
+ {
+ begin: /\(/,
+ end: /\)/,
+ keywords: KEYWORDS,
+ relevance: 0,
+ contains: [
+ 'self',
+ C_LINE_COMMENT_MODE,
+ hljs.C_BLOCK_COMMENT_MODE,
+ STRINGS,
+ NUMBERS,
+ TYPES
+ ]
+ }
+ ]
+ },
+ TYPES,
+ C_LINE_COMMENT_MODE,
+ hljs.C_BLOCK_COMMENT_MODE,
+ PREPROCESSOR
+ ]
+ };
+
+ return {
+ name: "C",
+ aliases: [ 'h' ],
+ keywords: KEYWORDS,
+ // Until differentiations are added between `c` and `cpp`, `c` will
+ // not be auto-detected to avoid auto-detect conflicts between C and C++
+ disableAutodetect: true,
+ illegal: '</',
+ contains: [].concat(
+ EXPRESSION_CONTEXT,
+ FUNCTION_DECLARATION,
+ EXPRESSION_CONTAINS,
+ [
+ PREPROCESSOR,
+ {
+ begin: hljs.IDENT_RE + '::',
+ keywords: KEYWORDS
+ },
+ {
+ className: 'class',
+ beginKeywords: 'enum class struct union',
+ end: /[{;:<>=]/,
+ contains: [
+ { beginKeywords: "final class struct" },
+ hljs.TITLE_MODE
+ ]
+ }
+ ]),
+ exports: {
+ preprocessor: PREPROCESSOR,
+ strings: STRINGS,
+ keywords: KEYWORDS
+ }
+ };
+ }
+
+ /*
+ Language: Python
+ Description: Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.
+ Website: https://www.python.org
+ Category: common
+ */
+
+ function python(hljs) {
+ const regex = hljs.regex;
+ const IDENT_RE = /[\p{XID_Start}_]\p{XID_Continue}*/u;
+ const RESERVED_WORDS = [
+ 'and',
+ 'as',
+ 'assert',
+ 'async',
+ 'await',
+ 'break',
+ 'case',
+ 'class',
+ 'continue',
+ 'def',
+ 'del',
+ 'elif',
+ 'else',
+ 'except',
+ 'finally',
+ 'for',
+ 'from',
+ 'global',
+ 'if',
+ 'import',
+ 'in',
+ 'is',
+ 'lambda',
+ 'match',
+ 'nonlocal|10',
+ 'not',
+ 'or',
+ 'pass',
+ 'raise',
+ 'return',
+ 'try',
+ 'while',
+ 'with',
+ 'yield'
+ ];
+
+ const BUILT_INS = [
+ '__import__',
+ 'abs',
+ 'all',
+ 'any',
+ 'ascii',
+ 'bin',
+ 'bool',
+ 'breakpoint',
+ 'bytearray',
+ 'bytes',
+ 'callable',
+ 'chr',
+ 'classmethod',
+ 'compile',
+ 'complex',
+ 'delattr',
+ 'dict',
+ 'dir',
+ 'divmod',
+ 'enumerate',
+ 'eval',
+ 'exec',
+ 'filter',
+ 'float',
+ 'format',
+ 'frozenset',
+ 'getattr',
+ 'globals',
+ 'hasattr',
+ 'hash',
+ 'help',
+ 'hex',
+ 'id',
+ 'input',
+ 'int',
+ 'isinstance',
+ 'issubclass',
+ 'iter',
+ 'len',
+ 'list',
+ 'locals',
+ 'map',
+ 'max',
+ 'memoryview',
+ 'min',
+ 'next',
+ 'object',
+ 'oct',
+ 'open',
+ 'ord',
+ 'pow',
+ 'print',
+ 'property',
+ 'range',
+ 'repr',
+ 'reversed',
+ 'round',
+ 'set',
+ 'setattr',
+ 'slice',
+ 'sorted',
+ 'staticmethod',
+ 'str',
+ 'sum',
+ 'super',
+ 'tuple',
+ 'type',
+ 'vars',
+ 'zip'
+ ];
+
+ const LITERALS = [
+ '__debug__',
+ 'Ellipsis',
+ 'False',
+ 'None',
+ 'NotImplemented',
+ 'True'
+ ];
+
+ // https://docs.python.org/3/library/typing.html
+ // TODO: Could these be supplemented by a CamelCase matcher in certain
+ // contexts, leaving these remaining only for relevance hinting?
+ const TYPES = [
+ "Any",
+ "Callable",
+ "Coroutine",
+ "Dict",
+ "List",
+ "Literal",
+ "Generic",
+ "Optional",
+ "Sequence",
+ "Set",
+ "Tuple",
+ "Type",
+ "Union"
+ ];
+
+ const KEYWORDS = {
+ $pattern: /[A-Za-z]\w+|__\w+__/,
+ keyword: RESERVED_WORDS,
+ built_in: BUILT_INS,
+ literal: LITERALS,
+ type: TYPES
+ };
+
+ const PROMPT = {
+ className: 'meta',
+ begin: /^(>>>|\.\.\.) /
+ };
+
+ const SUBST = {
+ className: 'subst',
+ begin: /\{/,
+ end: /\}/,
+ keywords: KEYWORDS,
+ illegal: /#/
+ };
+
+ const LITERAL_BRACKET = {
+ begin: /\{\{/,
+ relevance: 0
+ };
+
+ const STRING = {
+ className: 'string',
+ contains: [ hljs.BACKSLASH_ESCAPE ],
+ variants: [
+ {
+ begin: /([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/,
+ end: /'''/,
+ contains: [
+ hljs.BACKSLASH_ESCAPE,
+ PROMPT
+ ],
+ relevance: 10
+ },
+ {
+ begin: /([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?"""/,
+ end: /"""/,
+ contains: [
+ hljs.BACKSLASH_ESCAPE,
+ PROMPT
+ ],
+ relevance: 10
+ },
+ {
+ begin: /([fF][rR]|[rR][fF]|[fF])'''/,
+ end: /'''/,
+ contains: [
+ hljs.BACKSLASH_ESCAPE,
+ PROMPT,
+ LITERAL_BRACKET,
+ SUBST
+ ]
+ },
+ {
+ begin: /([fF][rR]|[rR][fF]|[fF])"""/,
+ end: /"""/,
+ contains: [
+ hljs.BACKSLASH_ESCAPE,
+ PROMPT,
+ LITERAL_BRACKET,
+ SUBST
+ ]
+ },
+ {
+ begin: /([uU]|[rR])'/,
+ end: /'/,
+ relevance: 10
+ },
+ {
+ begin: /([uU]|[rR])"/,
+ end: /"/,
+ relevance: 10
+ },
+ {
+ begin: /([bB]|[bB][rR]|[rR][bB])'/,
+ end: /'/
+ },
+ {
+ begin: /([bB]|[bB][rR]|[rR][bB])"/,
+ end: /"/
+ },
+ {
+ begin: /([fF][rR]|[rR][fF]|[fF])'/,
+ end: /'/,
+ contains: [
+ hljs.BACKSLASH_ESCAPE,
+ LITERAL_BRACKET,
+ SUBST
+ ]
+ },
+ {
+ begin: /([fF][rR]|[rR][fF]|[fF])"/,
+ end: /"/,
+ contains: [
+ hljs.BACKSLASH_ESCAPE,
+ LITERAL_BRACKET,
+ SUBST
+ ]
+ },
+ hljs.APOS_STRING_MODE,
+ hljs.QUOTE_STRING_MODE
+ ]
+ };
+
+ // https://docs.python.org/3.9/reference/lexical_analysis.html#numeric-literals
+ const digitpart = '[0-9](_?[0-9])*';
+ const pointfloat = `(\\b(${digitpart}))?\\.(${digitpart})|\\b(${digitpart})\\.`;
+ // Whitespace after a number (or any lexical token) is needed only if its absence
+ // would change the tokenization
+ // https://docs.python.org/3.9/reference/lexical_analysis.html#whitespace-between-tokens
+ // We deviate slightly, requiring a word boundary or a keyword
+ // to avoid accidentally recognizing *prefixes* (e.g., `0` in `0x41` or `08` or `0__1`)
+ const lookahead = `\\b|${RESERVED_WORDS.join('|')}`;
+ const NUMBER = {
+ className: 'number',
+ relevance: 0,
+ variants: [
+ // exponentfloat, pointfloat
+ // https://docs.python.org/3.9/reference/lexical_analysis.html#floating-point-literals
+ // optionally imaginary
+ // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals
+ // Note: no leading \b because floats can start with a decimal point
+ // and we don't want to mishandle e.g. `fn(.5)`,
+ // no trailing \b for pointfloat because it can end with a decimal point
+ // and we don't want to mishandle e.g. `0..hex()`; this should be safe
+ // because both MUST contain a decimal point and so cannot be confused with
+ // the interior part of an identifier
+ {
+ begin: `(\\b(${digitpart})|(${pointfloat}))[eE][+-]?(${digitpart})[jJ]?(?=${lookahead})`
+ },
+ {
+ begin: `(${pointfloat})[jJ]?`
+ },
+
+ // decinteger, bininteger, octinteger, hexinteger
+ // https://docs.python.org/3.9/reference/lexical_analysis.html#integer-literals
+ // optionally "long" in Python 2
+ // https://docs.python.org/2.7/reference/lexical_analysis.html#integer-and-long-integer-literals
+ // decinteger is optionally imaginary
+ // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals
+ {
+ begin: `\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?(?=${lookahead})`
+ },
+ {
+ begin: `\\b0[bB](_?[01])+[lL]?(?=${lookahead})`
+ },
+ {
+ begin: `\\b0[oO](_?[0-7])+[lL]?(?=${lookahead})`
+ },
+ {
+ begin: `\\b0[xX](_?[0-9a-fA-F])+[lL]?(?=${lookahead})`
+ },
+
+ // imagnumber (digitpart-based)
+ // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals
+ {
+ begin: `\\b(${digitpart})[jJ](?=${lookahead})`
+ }
+ ]
+ };
+ const COMMENT_TYPE = {
+ className: "comment",
+ begin: regex.lookahead(/# type:/),
+ end: /$/,
+ keywords: KEYWORDS,
+ contains: [
+ { // prevent keywords from coloring `type`
+ begin: /# type:/
+ },
+ // comment within a datatype comment includes no keywords
+ {
+ begin: /#/,
+ end: /\b\B/,
+ endsWithParent: true
+ }
+ ]
+ };
+ const PARAMS = {
+ className: 'params',
+ variants: [
+ // Exclude params in functions without params
+ {
+ className: "",
+ begin: /\(\s*\)/,
+ skip: true
+ },
+ {
+ begin: /\(/,
+ end: /\)/,
+ excludeBegin: true,
+ excludeEnd: true,
+ keywords: KEYWORDS,
+ contains: [
+ 'self',
+ PROMPT,
+ NUMBER,
+ STRING,
+ hljs.HASH_COMMENT_MODE
+ ]
+ }
+ ]
+ };
+ SUBST.contains = [
+ STRING,
+ NUMBER,
+ PROMPT
+ ];
+
+ return {
+ name: 'Python',
+ aliases: [
+ 'py',
+ 'gyp',
+ 'ipython'
+ ],
+ unicodeRegex: true,
+ keywords: KEYWORDS,
+ illegal: /(<\/|\?)|=>/,
+ contains: [
+ PROMPT,
+ NUMBER,
+ {
+ // very common convention
+ scope: 'variable.language',
+ match: /\bself\b/
+ },
+ {
+ // eat "if" prior to string so that it won't accidentally be
+ // labeled as an f-string
+ beginKeywords: "if",
+ relevance: 0
+ },
+ { match: /\bor\b/, scope: "keyword" },
+ STRING,
+ COMMENT_TYPE,
+ hljs.HASH_COMMENT_MODE,
+ {
+ match: [
+ /\bdef/, /\s+/,
+ IDENT_RE,
+ ],
+ scope: {
+ 1: "keyword",
+ 3: "title.function"
+ },
+ contains: [ PARAMS ]
+ },
+ {
+ variants: [
+ {
+ match: [
+ /\bclass/, /\s+/,
+ IDENT_RE, /\s*/,
+ /\(\s*/, IDENT_RE,/\s*\)/
+ ],
+ },
+ {
+ match: [
+ /\bclass/, /\s+/,
+ IDENT_RE
+ ],
+ }
+ ],
+ scope: {
+ 1: "keyword",
+ 3: "title.class",
+ 6: "title.class.inherited",
+ }
+ },
+ {
+ className: 'meta',
+ begin: /^[\t ]*@/,
+ end: /(?=#)|$/,
+ contains: [
+ NUMBER,
+ PARAMS,
+ STRING
+ ]
+ }
+ ]
+ };
+ }
+
+ /*
+ Language: Rust
+ Author: Andrey Vlasovskikh <andrey.vlasovskikh@gmail.com>
+ Contributors: Roman Shmatov <romanshmatov@gmail.com>, Kasper Andersen <kma_untrusted@protonmail.com>
+ Website: https://www.rust-lang.org
+ Category: common, system
+ */
+
+ /** @type LanguageFn */
+
+ function rust(hljs) {
+ const regex = hljs.regex;
+ // ============================================
+ // Added to support the r# keyword, which is a raw identifier in Rust.
+ const RAW_IDENTIFIER = /(r#)?/;
+ const UNDERSCORE_IDENT_RE = regex.concat(RAW_IDENTIFIER, hljs.UNDERSCORE_IDENT_RE);
+ const IDENT_RE = regex.concat(RAW_IDENTIFIER, hljs.IDENT_RE);
+ // ============================================
+ const FUNCTION_INVOKE = {
+ className: "title.function.invoke",
+ relevance: 0,
+ begin: regex.concat(
+ /\b/,
+ /(?!let|for|while|if|else|match\b)/,
+ IDENT_RE,
+ regex.lookahead(/\s*\(/))
+ };
+ const NUMBER_SUFFIX = '([ui](8|16|32|64|128|size)|f(32|64))\?';
+ const KEYWORDS = [
+ "abstract",
+ "as",
+ "async",
+ "await",
+ "become",
+ "box",
+ "break",
+ "const",
+ "continue",
+ "crate",
+ "do",
+ "dyn",
+ "else",
+ "enum",
+ "extern",
+ "false",
+ "final",
+ "fn",
+ "for",
+ "if",
+ "impl",
+ "in",
+ "let",
+ "loop",
+ "macro",
+ "match",
+ "mod",
+ "move",
+ "mut",
+ "override",
+ "priv",
+ "pub",
+ "ref",
+ "return",
+ "self",
+ "Self",
+ "static",
+ "struct",
+ "super",
+ "trait",
+ "true",
+ "try",
+ "type",
+ "typeof",
+ "union",
+ "unsafe",
+ "unsized",
+ "use",
+ "virtual",
+ "where",
+ "while",
+ "yield"
+ ];
+ const LITERALS = [
+ "true",
+ "false",
+ "Some",
+ "None",
+ "Ok",
+ "Err"
+ ];
+ const BUILTINS = [
+ // functions
+ 'drop ',
+ // traits
+ "Copy",
+ "Send",
+ "Sized",
+ "Sync",
+ "Drop",
+ "Fn",
+ "FnMut",
+ "FnOnce",
+ "ToOwned",
+ "Clone",
+ "Debug",
+ "PartialEq",
+ "PartialOrd",
+ "Eq",
+ "Ord",
+ "AsRef",
+ "AsMut",
+ "Into",
+ "From",
+ "Default",
+ "Iterator",
+ "Extend",
+ "IntoIterator",
+ "DoubleEndedIterator",
+ "ExactSizeIterator",
+ "SliceConcatExt",
+ "ToString",
+ // macros
+ "assert!",
+ "assert_eq!",
+ "bitflags!",
+ "bytes!",
+ "cfg!",
+ "col!",
+ "concat!",
+ "concat_idents!",
+ "debug_assert!",
+ "debug_assert_eq!",
+ "env!",
+ "eprintln!",
+ "panic!",
+ "file!",
+ "format!",
+ "format_args!",
+ "include_bytes!",
+ "include_str!",
+ "line!",
+ "local_data_key!",
+ "module_path!",
+ "option_env!",
+ "print!",
+ "println!",
+ "select!",
+ "stringify!",
+ "try!",
+ "unimplemented!",
+ "unreachable!",
+ "vec!",
+ "write!",
+ "writeln!",
+ "macro_rules!",
+ "assert_ne!",
+ "debug_assert_ne!"
+ ];
+ const TYPES = [
+ "i8",
+ "i16",
+ "i32",
+ "i64",
+ "i128",
+ "isize",
+ "u8",
+ "u16",
+ "u32",
+ "u64",
+ "u128",
+ "usize",
+ "f32",
+ "f64",
+ "str",
+ "char",
+ "bool",
+ "Box",
+ "Option",
+ "Result",
+ "String",
+ "Vec"
+ ];
+ return {
+ name: 'Rust',
+ aliases: [ 'rs' ],
+ keywords: {
+ $pattern: hljs.IDENT_RE + '!?',
+ type: TYPES,
+ keyword: KEYWORDS,
+ literal: LITERALS,
+ built_in: BUILTINS
+ },
+ illegal: '</',
+ contains: [
+ hljs.C_LINE_COMMENT_MODE,
+ hljs.COMMENT('/\\*', '\\*/', { contains: [ 'self' ] }),
+ hljs.inherit(hljs.QUOTE_STRING_MODE, {
+ begin: /b?"/,
+ illegal: null
+ }),
+ {
+ className: 'string',
+ variants: [
+ { begin: /b?r(#*)"(.|\n)*?"\1(?!#)/ },
+ { begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ }
+ ]
+ },
+ {
+ className: 'symbol',
+ begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
+ },
+ {
+ className: 'number',
+ variants: [
+ { begin: '\\b0b([01_]+)' + NUMBER_SUFFIX },
+ { begin: '\\b0o([0-7_]+)' + NUMBER_SUFFIX },
+ { begin: '\\b0x([A-Fa-f0-9_]+)' + NUMBER_SUFFIX },
+ { begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)'
+ + NUMBER_SUFFIX }
+ ],
+ relevance: 0
+ },
+ {
+ begin: [
+ /fn/,
+ /\s+/,
+ UNDERSCORE_IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "title.function"
+ }
+ },
+ {
+ className: 'meta',
+ begin: '#!?\\[',
+ end: '\\]',
+ contains: [
+ {
+ className: 'string',
+ begin: /"/,
+ end: /"/,
+ contains: [
+ hljs.BACKSLASH_ESCAPE
+ ]
+ }
+ ]
+ },
+ {
+ begin: [
+ /let/,
+ /\s+/,
+ /(?:mut\s+)?/,
+ UNDERSCORE_IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "keyword",
+ 4: "variable"
+ }
+ },
+ // must come before impl/for rule later
+ {
+ begin: [
+ /for/,
+ /\s+/,
+ UNDERSCORE_IDENT_RE,
+ /\s+/,
+ /in/
+ ],
+ className: {
+ 1: "keyword",
+ 3: "variable",
+ 5: "keyword"
+ }
+ },
+ {
+ begin: [
+ /type/,
+ /\s+/,
+ UNDERSCORE_IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "title.class"
+ }
+ },
+ {
+ begin: [
+ /(?:trait|enum|struct|union|impl|for)/,
+ /\s+/,
+ UNDERSCORE_IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "title.class"
+ }
+ },
+ {
+ begin: hljs.IDENT_RE + '::',
+ keywords: {
+ keyword: "Self",
+ built_in: BUILTINS,
+ type: TYPES
+ }
+ },
+ {
+ className: "punctuation",
+ begin: '->'
+ },
+ FUNCTION_INVOKE
+ ]
+ };
+ }
+
const keywordWrapper = keyword => concat(
/\b/,
keyword,
@@ -3722,6 +4177,7 @@ var hljs = (function () {
'operator',
'optional', // contextual
'override', // contextual
+ 'package',
'postfix', // contextual
'precedencegroup',
'prefix', // contextual
@@ -4218,14 +4674,17 @@ var hljs = (function () {
}
] }
};
+
const KEYWORD_ATTRIBUTE = {
scope: 'keyword',
- match: concat(/@/, either(...keywordAttributes))
+ match: concat(/@/, either(...keywordAttributes), lookahead(either(/\(/, /\s+/))),
};
+
const USER_DEFINED_ATTRIBUTE = {
scope: 'meta',
match: concat(/@/, identifier)
};
+
const ATTRIBUTES = [
AVAILABLE_ATTRIBUTE,
KEYWORD_ATTRIBUTE,
@@ -4418,6 +4877,37 @@ var hljs = (function () {
end: /}/
};
+ const TYPE_DECLARATION = {
+ begin: [
+ /(struct|protocol|class|extension|enum|actor)/,
+ /\s+/,
+ identifier,
+ /\s*/,
+ ],
+ beginScope: {
+ 1: "keyword",
+ 3: "title.class"
+ },
+ keywords: KEYWORDS,
+ contains: [
+ GENERIC_PARAMETERS,
+ ...KEYWORD_MODES,
+ {
+ begin: /:/,
+ end: /\{/,
+ keywords: KEYWORDS,
+ contains: [
+ {
+ scope: "title.class.inherited",
+ match: typeIdentifier,
+ },
+ ...KEYWORD_MODES,
+ ],
+ relevance: 0,
+ },
+ ]
+ };
+
// Add supported submodes to string interpolation.
for (const variant of STRING.variants) {
const interpolation = variant.contains.find(mode => mode.label === "interpol");
@@ -4451,19 +4941,7 @@ var hljs = (function () {
...COMMENTS,
FUNCTION_OR_MACRO,
INIT_SUBSCRIPT,
- {
- beginKeywords: 'struct protocol class extension enum actor',
- end: '\\{',
- excludeEnd: true,
- keywords: KEYWORDS,
- contains: [
- hljs.inherit(hljs.TITLE_MODE, {
- className: "title.class",
- begin: /[A-Za-z$_][\u00C0-\u02B80-9A-Za-z$_]*/
- }),
- ...KEYWORD_MODES
- ]
- },
+ TYPE_DECLARATION,
OPERATOR_DECLARATION,
PRECEDENCEGROUP,
{
@@ -4487,323 +4965,6 @@ var hljs = (function () {
}
/*
- Language: C
- Category: common, system
- Website: https://en.wikipedia.org/wiki/C_(programming_language)
- */
-
- /** @type LanguageFn */
- function c(hljs) {
- const regex = hljs.regex;
- // added for historic reasons because `hljs.C_LINE_COMMENT_MODE` does
- // not include such support nor can we be sure all the grammars depending
- // on it would desire this behavior
- const C_LINE_COMMENT_MODE = hljs.COMMENT('//', '$', { contains: [ { begin: /\\\n/ } ] });
- const DECLTYPE_AUTO_RE = 'decltype\\(auto\\)';
- const NAMESPACE_RE = '[a-zA-Z_]\\w*::';
- const TEMPLATE_ARGUMENT_RE = '<[^<>]+>';
- const FUNCTION_TYPE_RE = '('
- + DECLTYPE_AUTO_RE + '|'
- + regex.optional(NAMESPACE_RE)
- + '[a-zA-Z_]\\w*' + regex.optional(TEMPLATE_ARGUMENT_RE)
- + ')';
-
-
- const TYPES = {
- className: 'type',
- variants: [
- { begin: '\\b[a-z\\d_]*_t\\b' },
- { match: /\batomic_[a-z]{3,6}\b/ }
- ]
-
- };
-
- // https://en.cppreference.com/w/cpp/language/escape
- // \\ \x \xFF \u2837 \u00323747 \374
- const CHARACTER_ESCAPES = '\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)';
- const STRINGS = {
- className: 'string',
- variants: [
- {
- begin: '(u8?|U|L)?"',
- end: '"',
- illegal: '\\n',
- contains: [ hljs.BACKSLASH_ESCAPE ]
- },
- {
- begin: '(u8?|U|L)?\'(' + CHARACTER_ESCAPES + "|.)",
- end: '\'',
- illegal: '.'
- },
- hljs.END_SAME_AS_BEGIN({
- begin: /(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,
- end: /\)([^()\\ ]{0,16})"/
- })
- ]
- };
-
- const NUMBERS = {
- className: 'number',
- variants: [
- { begin: '\\b(0b[01\']+)' },
- { begin: '(-?)\\b([\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)' },
- { begin: '(-?)(\\b0[xX][a-fA-F0-9\']+|(\\b[\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)([eE][-+]?[\\d\']+)?)' }
- ],
- relevance: 0
- };
-
- const PREPROCESSOR = {
- className: 'meta',
- begin: /#\s*[a-z]+\b/,
- end: /$/,
- keywords: { keyword:
- 'if else elif endif define undef warning error line '
- + 'pragma _Pragma ifdef ifndef include' },
- contains: [
- {
- begin: /\\\n/,
- relevance: 0
- },
- hljs.inherit(STRINGS, { className: 'string' }),
- {
- className: 'string',
- begin: /<.*?>/
- },
- C_LINE_COMMENT_MODE,
- hljs.C_BLOCK_COMMENT_MODE
- ]
- };
-
- const TITLE_MODE = {
- className: 'title',
- begin: regex.optional(NAMESPACE_RE) + hljs.IDENT_RE,
- relevance: 0
- };
-
- const FUNCTION_TITLE = regex.optional(NAMESPACE_RE) + hljs.IDENT_RE + '\\s*\\(';
-
- const C_KEYWORDS = [
- "asm",
- "auto",
- "break",
- "case",
- "continue",
- "default",
- "do",
- "else",
- "enum",
- "extern",
- "for",
- "fortran",
- "goto",
- "if",
- "inline",
- "register",
- "restrict",
- "return",
- "sizeof",
- "struct",
- "switch",
- "typedef",
- "union",
- "volatile",
- "while",
- "_Alignas",
- "_Alignof",
- "_Atomic",
- "_Generic",
- "_Noreturn",
- "_Static_assert",
- "_Thread_local",
- // aliases
- "alignas",
- "alignof",
- "noreturn",
- "static_assert",
- "thread_local",
- // not a C keyword but is, for all intents and purposes, treated exactly like one.
- "_Pragma"
- ];
-
- const C_TYPES = [
- "float",
- "double",
- "signed",
- "unsigned",
- "int",
- "short",
- "long",
- "char",
- "void",
- "_Bool",
- "_Complex",
- "_Imaginary",
- "_Decimal32",
- "_Decimal64",
- "_Decimal128",
- // modifiers
- "const",
- "static",
- // aliases
- "complex",
- "bool",
- "imaginary"
- ];
-
- const KEYWORDS = {
- keyword: C_KEYWORDS,
- type: C_TYPES,
- literal: 'true false NULL',
- // TODO: apply hinting work similar to what was done in cpp.js
- built_in: 'std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream '
- + 'auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set '
- + 'unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos '
- + 'asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp '
- + 'fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper '
- + 'isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow '
- + 'printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp '
- + 'strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan '
- + 'vfprintf vprintf vsprintf endl initializer_list unique_ptr',
- };
-
- const EXPRESSION_CONTAINS = [
- PREPROCESSOR,
- TYPES,
- C_LINE_COMMENT_MODE,
- hljs.C_BLOCK_COMMENT_MODE,
- NUMBERS,
- STRINGS
- ];
-
- const EXPRESSION_CONTEXT = {
- // This mode covers expression context where we can't expect a function
- // definition and shouldn't highlight anything that looks like one:
- // `return some()`, `else if()`, `(x*sum(1, 2))`
- variants: [
- {
- begin: /=/,
- end: /;/
- },
- {
- begin: /\(/,
- end: /\)/
- },
- {
- beginKeywords: 'new throw return else',
- end: /;/
- }
- ],
- keywords: KEYWORDS,
- contains: EXPRESSION_CONTAINS.concat([
- {
- begin: /\(/,
- end: /\)/,
- keywords: KEYWORDS,
- contains: EXPRESSION_CONTAINS.concat([ 'self' ]),
- relevance: 0
- }
- ]),
- relevance: 0
- };
-
- const FUNCTION_DECLARATION = {
- begin: '(' + FUNCTION_TYPE_RE + '[\\*&\\s]+)+' + FUNCTION_TITLE,
- returnBegin: true,
- end: /[{;=]/,
- excludeEnd: true,
- keywords: KEYWORDS,
- illegal: /[^\w\s\*&:<>.]/,
- contains: [
- { // to prevent it from being confused as the function title
- begin: DECLTYPE_AUTO_RE,
- keywords: KEYWORDS,
- relevance: 0
- },
- {
- begin: FUNCTION_TITLE,
- returnBegin: true,
- contains: [ hljs.inherit(TITLE_MODE, { className: "title.function" }) ],
- relevance: 0
- },
- // allow for multiple declarations, e.g.:
- // extern void f(int), g(char);
- {
- relevance: 0,
- match: /,/
- },
- {
- className: 'params',
- begin: /\(/,
- end: /\)/,
- keywords: KEYWORDS,
- relevance: 0,
- contains: [
- C_LINE_COMMENT_MODE,
- hljs.C_BLOCK_COMMENT_MODE,
- STRINGS,
- NUMBERS,
- TYPES,
- // Count matching parentheses.
- {
- begin: /\(/,
- end: /\)/,
- keywords: KEYWORDS,
- relevance: 0,
- contains: [
- 'self',
- C_LINE_COMMENT_MODE,
- hljs.C_BLOCK_COMMENT_MODE,
- STRINGS,
- NUMBERS,
- TYPES
- ]
- }
- ]
- },
- TYPES,
- C_LINE_COMMENT_MODE,
- hljs.C_BLOCK_COMMENT_MODE,
- PREPROCESSOR
- ]
- };
-
- return {
- name: "C",
- aliases: [ 'h' ],
- keywords: KEYWORDS,
- // Until differentiations are added between `c` and `cpp`, `c` will
- // not be auto-detected to avoid auto-detect conflicts between C and C++
- disableAutodetect: true,
- illegal: '</',
- contains: [].concat(
- EXPRESSION_CONTEXT,
- FUNCTION_DECLARATION,
- EXPRESSION_CONTAINS,
- [
- PREPROCESSOR,
- {
- begin: hljs.IDENT_RE + '::',
- keywords: KEYWORDS
- },
- {
- className: 'class',
- beginKeywords: 'enum class struct union',
- end: /[{;:<>=]/,
- contains: [
- { beginKeywords: "final class struct" },
- hljs.TITLE_MODE
- ]
- }
- ]),
- exports: {
- preprocessor: PREPROCESSOR,
- strings: STRINGS,
- keywords: KEYWORDS
- }
- };
- }
-
- /*
Language: OCaml
Author: Mehdi Dogguy <mehdi@dogguy.org>
Contributors: Nicolas Braud-Santoni <nicolas.braud-santoni@ens-cachan.fr>, Mickael Delahaye <mickael.delahaye@gmail.com>
@@ -4885,6 +5046,426 @@ var hljs = (function () {
};
}
+ /*
+ Language: Nim
+ Description: Nim is a statically typed compiled systems programming language.
+ Website: https://nim-lang.org
+ Category: system
+ */
+
+ function nim(hljs) {
+ const TYPES = [
+ "int",
+ "int8",
+ "int16",
+ "int32",
+ "int64",
+ "uint",
+ "uint8",
+ "uint16",
+ "uint32",
+ "uint64",
+ "float",
+ "float32",
+ "float64",
+ "bool",
+ "char",
+ "string",
+ "cstring",
+ "pointer",
+ "expr",
+ "stmt",
+ "void",
+ "auto",
+ "any",
+ "range",
+ "array",
+ "openarray",
+ "varargs",
+ "seq",
+ "set",
+ "clong",
+ "culong",
+ "cchar",
+ "cschar",
+ "cshort",
+ "cint",
+ "csize",
+ "clonglong",
+ "cfloat",
+ "cdouble",
+ "clongdouble",
+ "cuchar",
+ "cushort",
+ "cuint",
+ "culonglong",
+ "cstringarray",
+ "semistatic"
+ ];
+ const KEYWORDS = [
+ "addr",
+ "and",
+ "as",
+ "asm",
+ "bind",
+ "block",
+ "break",
+ "case",
+ "cast",
+ "const",
+ "continue",
+ "converter",
+ "discard",
+ "distinct",
+ "div",
+ "do",
+ "elif",
+ "else",
+ "end",
+ "enum",
+ "except",
+ "export",
+ "finally",
+ "for",
+ "from",
+ "func",
+ "generic",
+ "guarded",
+ "if",
+ "import",
+ "in",
+ "include",
+ "interface",
+ "is",
+ "isnot",
+ "iterator",
+ "let",
+ "macro",
+ "method",
+ "mixin",
+ "mod",
+ "nil",
+ "not",
+ "notin",
+ "object",
+ "of",
+ "or",
+ "out",
+ "proc",
+ "ptr",
+ "raise",
+ "ref",
+ "return",
+ "shared",
+ "shl",
+ "shr",
+ "static",
+ "template",
+ "try",
+ "tuple",
+ "type",
+ "using",
+ "var",
+ "when",
+ "while",
+ "with",
+ "without",
+ "xor",
+ "yield"
+ ];
+ const BUILT_INS = [
+ "stdin",
+ "stdout",
+ "stderr",
+ "result"
+ ];
+ const LITERALS = [
+ "true",
+ "false"
+ ];
+ return {
+ name: 'Nim',
+ keywords: {
+ keyword: KEYWORDS,
+ literal: LITERALS,
+ type: TYPES,
+ built_in: BUILT_INS
+ },
+ contains: [
+ {
+ className: 'meta', // Actually pragma
+ begin: /\{\./,
+ end: /\.\}/,
+ relevance: 10
+ },
+ {
+ className: 'string',
+ begin: /[a-zA-Z]\w*"/,
+ end: /"/,
+ contains: [ { begin: /""/ } ]
+ },
+ {
+ className: 'string',
+ begin: /([a-zA-Z]\w*)?"""/,
+ end: /"""/
+ },
+ hljs.QUOTE_STRING_MODE,
+ {
+ className: 'type',
+ begin: /\b[A-Z]\w+\b/,
+ relevance: 0
+ },
+ {
+ className: 'number',
+ relevance: 0,
+ variants: [
+ { begin: /\b(0[xX][0-9a-fA-F][_0-9a-fA-F]*)('?[iIuU](8|16|32|64))?/ },
+ { begin: /\b(0o[0-7][_0-7]*)('?[iIuUfF](8|16|32|64))?/ },
+ { begin: /\b(0(b|B)[01][_01]*)('?[iIuUfF](8|16|32|64))?/ },
+ { begin: /\b(\d[_\d]*)('?[iIuUfF](8|16|32|64))?/ }
+ ]
+ },
+ hljs.HASH_COMMENT_MODE
+ ]
+ };
+ }
+
+ /*
+ Language: Puck
+ Description: Puck is a whitespace-sensitive, memory-safe, interface-oriented, imperative language with functional underpinnings.
+ Website: https://puck-lang.org
+ Category: system
+ */
+
+ function puck(hljs) {
+ const KEYWORDS = [
+ "struct",
+ "tuple",
+ "union",
+ "enum",
+ "class",
+ "ref",
+ "refc",
+ "ptr",
+ "array",
+ "list",
+ "slice",
+ "int",
+ "uint",
+ "float",
+ "f32",
+ "f64",
+ "f128",
+ "dec64",
+ "dec128",
+ "void",
+ "never",
+ "bool",
+ "byte",
+ "char",
+ "str",
+ "pub",
+ "let",
+ "var",
+ "const",
+ "lent",
+ "mut",
+ "func",
+ "macro",
+ "type",
+ "mod",
+ "use",
+ "as",
+ "if",
+ "when",
+ "elif",
+ "else",
+ "then",
+ "match",
+ "of",
+ "where",
+ "try",
+ "with",
+ "finally",
+ "for",
+ "while",
+ "do",
+ "loop",
+ "block",
+ "quote",
+ "break",
+ "continue",
+ "return",
+ "raise",
+ "in",
+ "is",
+ "type"
+ ];
+ const BUILT_INS = [
+ "stdin",
+ "stdout",
+ "stderr",
+ "std",
+ "lib"
+ ];
+ const LITERALS = [
+ "unit",
+ "true",
+ "false",
+ "Some",
+ "None"
+ ];
+ return {
+ name: 'Puck',
+ aliases: [ 'pk' ],
+ contains: [
+ {
+ begin: [
+ /\n/,
+ /\s*/,
+ hljs.IDENT_RE,
+ /\s+/,
+ ],
+ className: {
+ 1: "function"
+ }
+ },
+ {
+ className: 'string',
+ begin: /[a-zA-Z]\w*"/,
+ end: /"/,
+ contains: [ { begin: /""/ } ]
+ },
+ {
+ className: 'string',
+ begin: /([a-zA-Z]\w*)?"""/,
+ end: /"""/
+ },
+ hljs.QUOTE_STRING_MODE,
+ {
+ className: 'type',
+ begin: /\b[A-Z]\w*\b/,
+ relevance: 0
+ },
+ {
+ className: 'keyword',
+ begin: /\bi\d+\b/,
+ relevance: 0
+ },
+ {
+ className: 'keyword',
+ begin: /\bu\d+\b/,
+ relevance: 0
+ },
+ {
+ className: 'number',
+ relevance: 0,
+ variants: [
+ { begin: /\b(0[xX][0-9a-fA-F][_0-9a-fA-F]*)/ },
+ { begin: /\b(0[oO][0-7][_0-7]*)/ },
+ { begin: /\b(0[bB][01][_01]*)/ },
+ { begin: /\b(\d[_\d]*)/ }
+ ]
+ },
+ {
+ begin: [
+ /let|var/,
+ /\s+/,
+ hljs.IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "variable"
+ }
+ },
+ {
+ begin: [
+ /const/,
+ /\s+/,
+ hljs.IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "constant"
+ }
+ },
+ {
+ begin: [
+ /func|macro|mod/,
+ /\s+/,
+ hljs.IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "function"
+ }
+ },
+ {
+ begin: [
+ /type/,
+ /\s+/,
+ hljs.IDENT_RE
+ ],
+ className: {
+ 1: "keyword",
+ 3: "type"
+ }
+ },
+ {
+ begin: [
+ hljs.IDENT_RE,
+ /\(/
+ ],
+ className: {
+ 1: "function"
+ }
+ },
+ {
+ begin: [
+ hljs.IDENT_RE,
+ /\:/
+ ],
+ className: {
+ 1: "params"
+ }
+ },
+ {
+ begin: [
+ hljs.IDENT_RE,
+ /\./
+ ],
+ className: {
+ 1: "variable"
+ }
+ },
+ {
+ begin: [
+ /\./,
+ hljs.IDENT_RE,
+ /\b/
+ ],
+ className: {
+ 2: "function"
+ }
+ },
+ {
+ className: "punctuation",
+ begin: '->'
+ },
+ {
+ className: "punctuation",
+ begin: '=>'
+ },
+ hljs.HASH_COMMENT_MODE
+ ],
+ keywords: {
+ keyword: KEYWORDS,
+ literal: LITERALS,
+ built_in: BUILT_INS
+ }
+ };
+ }
+
var builtIns = /*#__PURE__*/Object.freeze({
__proto__: null,
grmr_bash: bash,
@@ -4892,6 +5473,7 @@ var hljs = (function () {
grmr_nim: nim,
grmr_ocaml: ocaml,
grmr_puck: puck,
+ grmr_python: python,
grmr_rust: rust,
grmr_swift: swift
});
diff --git a/docs/book/tomorrow-night.css b/docs/book/tomorrow-night.css
index 81fe276..a362570 100644
--- a/docs/book/tomorrow-night.css
+++ b/docs/book/tomorrow-night.css
@@ -21,7 +21,7 @@
.css .hljs-id,
.css .hljs-class,
.css .hljs-pseudo {
- color: #cc6666;
+ color: #E06C75;
}
/* Tomorrow Orange */
@@ -38,7 +38,7 @@
/* Tomorrow Yellow */
.ruby .hljs-class .hljs-title,
.css .hljs-rule .hljs-attribute {
- color: #f0c674;
+ color: #E5C07B;
}
/* Tomorrow Green */
@@ -49,13 +49,14 @@
.hljs-name,
.ruby .hljs-symbol,
.xml .hljs-cdata {
- color: #b5bd68;
+ color: #98C379;
}
/* Tomorrow Aqua */
.hljs-title,
+.hljs-type,
.css .hljs-hexcolor {
- color: #8abeb7;
+ color: #56B6C2;
}
/* Tomorrow Blue */
@@ -67,13 +68,13 @@
.perl .hljs-sub,
.javascript .hljs-title,
.coffeescript .hljs-title {
- color: #81a2be;
+ color: #61AFEF;
}
-/* Tomorrow Purple */
+/* One Dark Purple */
.hljs-keyword,
.javascript .hljs-function {
- color: #b294bb;
+ color: #C678DD;
}
.hljs {