# A collection of example programs in various different languages, # used by the syntastica examples. The keys specify the language name. rust = ''' fn fib(n: usize) -> usize { if n < 2 { n } else { fib(n - 1) + fib(n - 2) } } fn main() { Regex::new(r"[a-fA-F0-9_]\s(.*)$"); let a = regex!(r"[a-fA-F0-9_]\s(.*)$"); if regex_is_match!(/* comment */ r"[a-fA-F0-9_]\s(.*)$"i, r"raw text \s[a-f]") { return; } } ''' python = ''' import re def fib(n: int) -> int: if n < 2: return n return fib(n - 1) + fib(n - 2) def main(): re.compile(r'[a-fA-F0-9_]\s(.*)$') print(f"fib(10) = {fib(10)}") ''' c = ''' int fib(int n) { if (n < 2) { return n; } return fib(n - 1) + fib(n - 2); } ''' cpp = ''' #include int main() { unsigned int a = 1, b = 1; unsigned int target = 48; for (unsigned int n = 3; n <= target; ++n) { unsigned int fib = a + b; std::cout << "F("<< n << ") = " << fib << std::endl; a = b; b = fib; } return 0; } ''' css = ''' :root { --bg-dark: #000; } #app.dark { background-color: var(--bg-dark); } ''' go = ''' import ( "math/big" ) func fib(n uint64) *big.Int { if n < 2 { return big.NewInt(int64(n)) } a, b := big.NewInt(0), big.NewInt(1) for n--; n > 0; n-- { a.Add(a, b) a, b = b, a } return b } func main() { regexp.Compile(`[a-fA-F0-9_]\s(.*)$`) } ''' html = ''' rush Playground
''' java = ''' class Fibonacci { /** * O(log(n)) */ public static long fib(long n) { if (n <= 0) return 0; long i = (int) (n - 1); long a = 1, b = 0, c = 0, d = 1, tmp1,tmp2; while (i > 0) { if (i % 2 != 0) { tmp1 = d * b + c * a; tmp2 = d * (b + a) + c * b; a = tmp1; b = tmp2; } tmp1 = (long) (Math.pow(c, 2) + Math.pow(d, 2)); tmp2 = d * (2 * c + d); c = tmp1; d = tmp2; i = i / 2; } return a + b; } } ''' javascript = ''' /** * Calculate a number as of the Fibonacci sequence. * * @example * var result = fib(10); // results in 55 * * @param {number} n: index of number to calculate */ var fib = (function(cache){ return cache = cache || {}, function(n){ if (cache[n]) return cache[n]; else return cache[n] = n == 0 ? 0 : n < 0 ? -fib(-n) : n <= 2 ? 1 : fib(n-2) + fib(n-1); }; })(); ''' json = ''' { "key": "value", "good": false, "age": 42, "percentage": 0.3, "nothing": null, "list": [1, 2, 3], "object": { "key": "value" } } ''' tsx = ''' interface FooProp { name: string; X: number; Y: number; } declare function AnotherComponent(prop: { name: string }); function ComponentFoo(prop: FooProp) { return ; } const Button = (prop: { value: string }, context: { color: string }) => (