mirror of
https://github.com/sharkdp/bat.git
synced 2025-08-09 07:45:09 +02:00
Merge remote-tracking branch 'origin/master' into fix-1063
This commit is contained in:
52
tests/benchmarks/run-benchmarks.sh
vendored
52
tests/benchmarks/run-benchmarks.sh
vendored
@ -1,28 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
||||
|
||||
# Check that Hyperfine is installed.
|
||||
if ! command -v hyperfine > /dev/null 2>&1; then
|
||||
echo "'hyperfine' does not seem to be installed."
|
||||
echo "You can get it here: https://github.com/sharkdp/hyperfine"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine the target directories.
|
||||
get_target_dir() {
|
||||
if [[ -f "$HOME/.cargo/config" ]]; then
|
||||
grep 'target-dir[[:space:]]*=' "$HOME/.cargo/config" \
|
||||
| sed 's/^[[:space:]]*target-dir[[:space:]]*=//; s/^[[:space:]]*"//; s/"[[:space:]]*$//' \
|
||||
&& return 0
|
||||
fi
|
||||
|
||||
echo "../../target"
|
||||
}
|
||||
|
||||
TARGET_DIR="$(get_target_dir)"
|
||||
TARGET_DEBUG="${TARGET_DIR}/debug/bat"
|
||||
TARGET_RELEASE="${TARGET_DIR}/release/bat"
|
||||
|
||||
# Determine which target to benchmark.
|
||||
BAT=''
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--system) BAT="bat" ;;
|
||||
--debug) BAT="$TARGET_DEBUG" ;;
|
||||
--release) BAT="$TARGET_RELEASE" ;;
|
||||
--bat=*) BAT="${arg:6}" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$BAT" ]]; then
|
||||
echo "A build of 'bat' must be specified for benchmarking."
|
||||
echo "You can use '--system', '--debug', or '--release'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure that the target is built.
|
||||
if ! command -v "$BAT" &>/dev/null; then
|
||||
echo "Could not find the build of bat to benchmark."
|
||||
case "$BAT" in
|
||||
"bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
|
||||
"$TARGET_DEBUG") echo "Make you sure to 'cargo build' first." ;;
|
||||
"$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
|
||||
esac
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run the benchmark.
|
||||
echo "### Startup time"
|
||||
echo
|
||||
|
||||
hyperfine --warmup 3 bat
|
||||
hyperfine --warmup 3 "$BAT"
|
||||
|
||||
echo
|
||||
echo "### Plain text"
|
||||
echo
|
||||
|
||||
hyperfine --warmup 3 "bat --language txt --paging=never 'test-src/jquery-3.3.1.js'"
|
||||
hyperfine --warmup 3 "$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'"
|
||||
|
||||
echo
|
||||
echo "### Time to syntax-highlight large files"
|
||||
echo
|
||||
|
||||
for SRC in test-src/*; do
|
||||
hyperfine --warmup 3 "bat --style=full --color=always --paging=never '$SRC'"
|
||||
hyperfine --warmup 3 "$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")"
|
||||
done
|
||||
|
68
tests/syntax-tests/highlighted/Lean/test.lean
Normal file
68
tests/syntax-tests/highlighted/Lean/test.lean
Normal file
@ -0,0 +1,68 @@
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m data.matrix.notation[0m
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m data.vector2[0m
|
||||
|
||||
[38;2;117;113;94m/-![0m
|
||||
|
||||
[38;2;117;113;94mHelpers that don't currently fit elsewhere...[0m
|
||||
|
||||
[38;2;117;113;94m-/[0m
|
||||
|
||||
[38;2;249;38;114mlemma[0m[38;2;248;248;242m [0m[38;2;166;226;46msplit_eq[0m[38;2;248;248;242m [0m[38;2;248;248;242m{m n : [0m[3;38;2;102;217;239mType[0m[38;2;248;248;242m*} (x : m × n) (p p' : m × n) :[0m
|
||||
[38;2;248;248;242m p = x ∨ p' = x ∨ (x ≠ p ∧ x ≠ p') := [0m[38;2;249;38;114mby[0m[38;2;248;248;242m tauto[0m
|
||||
|
||||
[38;2;117;113;94m--[0m[38;2;117;113;94m For `playfield`s, the piece type and/or piece index type.[0m
|
||||
[38;2;249;38;114mvariables[0m[38;2;248;248;242m (X : [0m[3;38;2;102;217;239mType[0m[38;2;248;248;242m*)[0m
|
||||
[38;2;249;38;114mvariables[0m[38;2;248;248;242m [has_repr X][0m
|
||||
|
||||
[38;2;249;38;114mnamespace[0m[38;2;248;248;242m chess.utils[0m
|
||||
|
||||
[38;2;249;38;114msection[0m[38;2;248;248;242m repr[0m
|
||||
|
||||
[38;2;117;113;94m/--[0m
|
||||
[38;2;117;113;94mAn auxiliary wrapper for `option X` that allows for overriding the `has_repr` instance[0m
|
||||
[38;2;117;113;94mfor `option`, and rather, output just the value in the `some` and a custom provided[0m
|
||||
[38;2;117;113;94m`string` for `none`.[0m
|
||||
[38;2;117;113;94m-/[0m
|
||||
[38;2;249;38;114mstructure[0m[38;2;248;248;242m [0m[38;2;166;226;46moption_wrapper[0m[38;2;248;248;242m [0m[38;2;248;248;242m:=[0m
|
||||
[38;2;248;248;242m(val : option X)[0m
|
||||
[38;2;248;248;242m(none_s : string)[0m
|
||||
|
||||
[38;2;249;38;114minstance[0m[38;2;248;248;242m [0m[38;2;166;226;46mwrapped_option_repr[0m[38;2;248;248;242m [0m[38;2;248;248;242m: has_repr (option_wrapper X) :=[0m
|
||||
[38;2;248;248;242m⟨[0m[38;2;249;38;114mλ[0m[38;2;248;248;242m ⟨val, s⟩, (option.map has_repr.repr val).get_or_else s⟩[0m
|
||||
|
||||
[38;2;249;38;114mvariables[0m[38;2;248;248;242m {X}[0m
|
||||
[38;2;117;113;94m/--[0m
|
||||
[38;2;117;113;94mConstruct an `option_wrapper` term from a provided `option X` and the `string`[0m
|
||||
[38;2;117;113;94mthat will override the `has_repr.repr` for `none`.[0m
|
||||
[38;2;117;113;94m-/[0m
|
||||
[38;2;249;38;114mdef[0m[38;2;248;248;242m [0m[38;2;166;226;46moption_wrap[0m[38;2;248;248;242m [0m[38;2;248;248;242m(val : option X) (none_s : string) : option_wrapper X := ⟨val, none_s⟩[0m
|
||||
|
||||
[38;2;117;113;94m--[0m[38;2;117;113;94m The size of the "vectors" for a `fin n' → X`, for `has_repr` definitions[0m
|
||||
[38;2;249;38;114mvariables[0m[38;2;248;248;242m {m' n' : ℕ}[0m
|
||||
|
||||
[38;2;117;113;94m/--[0m
|
||||
[38;2;117;113;94mFor a "vector" `X^n'` represented by the type `Π n' : ℕ, fin n' → X`, where[0m
|
||||
[38;2;117;113;94mthe `X` has a `has_repr` instance itself, we can provide a `has_repr` for the "vector".[0m
|
||||
[38;2;117;113;94mThis definition is used for displaying rows of the playfield, when it is defined[0m
|
||||
[38;2;117;113;94mvia a `matrix`, likely through notation.[0m
|
||||
[38;2;117;113;94m-/[0m
|
||||
[38;2;249;38;114mdef[0m[38;2;248;248;242m [0m[38;2;166;226;46mvec_repr[0m[38;2;248;248;242m [0m[38;2;248;248;242m: Π {n' : ℕ}, (fin n' → X) → string :=[0m
|
||||
[38;2;249;38;114mλ[0m[38;2;248;248;242m _ v, string.intercalate [0m[38;2;230;219;116m"[0m[38;2;230;219;116m, [0m[38;2;230;219;116m"[0m[38;2;248;248;242m ((vector.of_fn v).to_list.map repr)[0m
|
||||
|
||||
[38;2;249;38;114minstance[0m[38;2;248;248;242m [0m[38;2;166;226;46mvec_repr_instance[0m[38;2;248;248;242m [0m[38;2;248;248;242m: has_repr (fin n' → X) := ⟨vec_repr⟩[0m
|
||||
|
||||
[38;2;117;113;94m/--[0m
|
||||
[38;2;117;113;94mFor a `matrix` `X^(m' × n')` where the `X` has a `has_repr` instance itself,[0m
|
||||
[38;2;117;113;94mwe can provide a `has_repr` for the matrix, using `vec_repr` for each of the rows of the matrix.[0m
|
||||
[38;2;117;113;94mThis definition is used for displaying the playfield, when it is defined[0m
|
||||
[38;2;117;113;94mvia a `matrix`, likely through notation.[0m
|
||||
[38;2;117;113;94m-/[0m
|
||||
[38;2;249;38;114mdef[0m[38;2;248;248;242m [0m[38;2;166;226;46mmatrix_repr[0m[38;2;248;248;242m [0m[38;2;248;248;242m: Π {m' n'}, matrix (fin m') (fin n') X → string :=[0m
|
||||
[38;2;249;38;114mλ[0m[38;2;248;248;242m _ _ M, string.intercalate [0m[38;2;230;219;116m"[0m[38;2;230;219;116m;[0m[38;2;190;132;255m\n[0m[38;2;230;219;116m"[0m[38;2;248;248;242m ((vector.of_fn M).to_list.map repr)[0m
|
||||
|
||||
[38;2;249;38;114minstance[0m[38;2;248;248;242m [0m[38;2;166;226;46mmatrix_repr_instance[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m
|
||||
[38;2;248;248;242m has_repr (matrix (fin n') (fin m') X) := ⟨matrix_repr⟩[0m
|
||||
|
||||
[38;2;249;38;114mend[0m[38;2;248;248;242m repr[0m
|
||||
|
||||
[38;2;249;38;114mend[0m[38;2;248;248;242m chess.utils[0m
|
107
tests/syntax-tests/highlighted/Zig/example.zig
Normal file
107
tests/syntax-tests/highlighted/Zig/example.zig
Normal file
@ -0,0 +1,107 @@
|
||||
[38;2;117;113;94m//! this is a top level doc, starts with "//!"[0m
|
||||
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m std [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114m@import[0m[38;2;248;248;242m([0m[38;2;230;219;116m"std"[0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;249;38;114mpub[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mfn[0m[38;2;248;248;242m [0m[38;2;166;226;46mmain[0m[38;2;248;248;242m([0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[3;38;2;102;217;239manyerror[0m[38;2;249;38;114m![0m[3;38;2;102;217;239mvoid[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mconst[0m[38;2;248;248;242m stdout [0m[38;2;249;38;114m=[0m[38;2;248;248;242m std.io.[0m[38;2;248;248;242mgetStdOut[0m[38;2;248;248;242m([0m[38;2;248;248;242m)[0m[38;2;248;248;242m.[0m[38;2;248;248;242mwriter[0m[38;2;248;248;242m([0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mtry[0m[38;2;248;248;242m stdout.[0m[38;2;248;248;242mprint[0m[38;2;248;248;242m([0m[38;2;230;219;116m"Hello, {}![0m[38;2;190;132;255m\n[0m[38;2;230;219;116m"[0m[38;2;248;248;242m,[0m[38;2;248;248;242m .[0m[38;2;248;248;242m{[0m[38;2;230;219;116m"world"[0m[38;2;248;248;242m}[0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m expect [0m[38;2;249;38;114m=[0m[38;2;248;248;242m std.testing.expect[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[3;38;2;102;217;239mtest[0m[38;2;248;248;242m [0m[38;2;230;219;116m"comments"[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m// comments start with "//" until newline[0m
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m// foo bar baz[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mconst[0m[38;2;248;248;242m x [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m[38;2;248;248;242m;[0m[38;2;248;248;242m [0m[38;2;117;113;94m// another comment[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242mexpect[0m[38;2;248;248;242m([0m[38;2;248;248;242mx[0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m/// a doc comment starts with "///"[0m
|
||||
[38;2;117;113;94m/// multiple lines are merged together[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m [0m[38;2;166;226;46mTimestamp[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mstruct[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m/// number of seconds since epoch[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mseconds[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mi64[0m[38;2;248;248;242m,[0m
|
||||
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m/// number of nanoseconds past the second[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mnano[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mu32[0m[38;2;248;248;242m,[0m
|
||||
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mconst[0m[38;2;248;248;242m Self [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;102;217;239m@This[0m[38;2;248;248;242m([0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mpub[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mfn[0m[38;2;248;248;242m [0m[38;2;166;226;46munixEpoch[0m[38;2;248;248;242m([0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mSelf[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mSelf[0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m .seconds [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m .nanos [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m}[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m}[0m
|
||||
[38;2;248;248;242m}[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m my_val [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mswitch[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[38;2;248;248;242mstd.Target.current.os.tag[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;190;132;255m.linux[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;249;38;114m>[0m[38;2;248;248;242m [0m[38;2;230;219;116m"Linux"[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114melse[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;249;38;114m>[0m[38;2;248;248;242m [0m[38;2;230;219;116m"not Linux"[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m}[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m [0m[38;2;166;226;46mBook[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[3;38;2;102;217;239menum[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m paperback[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m hardcover[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m ebook[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m pdf[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m}[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m [0m[38;2;166;226;46mTokenType[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[3;38;2;102;217;239munion[0m[38;2;248;248;242m([0m[3;38;2;102;217;239menum[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mint[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239misize[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mfloat[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mf64[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mstring[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [][0m[38;2;249;38;114mconst[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mu8[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m}[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m [0m[38;2;255;255;255marray_lit[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [[0m[38;2;190;132;255m4[0m[38;2;248;248;242m][0m[3;38;2;102;217;239mu8[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m .[0m[38;2;248;248;242m{[0m[38;2;248;248;242m [0m[38;2;190;132;255m11[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m22[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m33[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m44[0m[38;2;248;248;242m [0m[38;2;248;248;242m}[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m sentinal_lit [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [[0m[38;2;190;132;255m_[0m[38;2;248;248;242m:[0m[38;2;190;132;255m0[0m[38;2;248;248;242m][0m[3;38;2;102;217;239mu8[0m[38;2;248;248;242m{[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m4[0m[38;2;248;248;242m [0m[38;2;248;248;242m}[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[3;38;2;102;217;239mtest[0m[38;2;248;248;242m [0m[38;2;230;219;116m"address of syntax"[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m// Get the address of a variable:[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mconst[0m[38;2;248;248;242m [0m[38;2;255;255;255mx[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mi32[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m1234[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mconst[0m[38;2;248;248;242m x_ptr [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114m&[0m[38;2;248;248;242mx[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m// Dereference a pointer:[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242mexpect[0m[38;2;248;248;242m([0m[38;2;248;248;242mx_ptr[0m[38;2;249;38;114m.*[0m[38;2;248;248;242m [0m[38;2;249;38;114m==[0m[38;2;248;248;242m [0m[38;2;190;132;255m1234[0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m// When you get the address of a const variable, you get a const pointer to a single item.[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242mexpect[0m[38;2;248;248;242m([0m[38;2;102;217;239m@TypeOf[0m[38;2;248;248;242m([0m[38;2;248;248;242mx_ptr[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m==[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;249;38;114mconst[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mi32[0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m// If you want to mutate the value, you'd need an address of a mutable variable:[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mvar[0m[38;2;248;248;242m [0m[38;2;255;255;255my[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mi32[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m5678[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mconst[0m[38;2;248;248;242m y_ptr [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114m&[0m[38;2;248;248;242my[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242mexpect[0m[38;2;248;248;242m([0m[38;2;102;217;239m@TypeOf[0m[38;2;248;248;242m([0m[38;2;248;248;242my_ptr[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m==[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[3;38;2;102;217;239mi32[0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m y_ptr[0m[38;2;249;38;114m.*[0m[38;2;248;248;242m [0m[38;2;249;38;114m+=[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242mexpect[0m[38;2;248;248;242m([0m[38;2;248;248;242my_ptr[0m[38;2;249;38;114m.*[0m[38;2;248;248;242m [0m[38;2;249;38;114m==[0m[38;2;248;248;242m [0m[38;2;190;132;255m5679[0m[38;2;248;248;242m)[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m// integer literals[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m decimal_int [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m98222[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m hex_int [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0xff[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m another_hex_int [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0xFF[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m octal_int [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0o755[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m binary_int [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0b11110000[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;117;113;94m// underscores may be placed between two digits as a visual separator[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m one_billion [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m1_000_000_000[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m binary_mask [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0b1_1111_1111[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m permissions [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0o7_5_5[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m big_address [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0xFF80_0000_0000_0000[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;117;113;94m// float literals[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m floating_point [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m123.0E+77[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m another_float [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m123.0[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m yet_another [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m123.0e+77[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m hex_floating_point [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0x103.70p-5[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m another_hex_float [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0x103.70[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m yet_another_hex_float [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0x103.70P-5[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[38;2;117;113;94m// underscores may be placed between two digits as a visual separator[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m lightspeed [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m299_792_458.000_000[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m nanosecond [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0.000_000_001[0m[38;2;248;248;242m;[0m
|
||||
[38;2;249;38;114mconst[0m[38;2;248;248;242m more_hex [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0x1234_5678.9ABC_CDEFp-10[0m[38;2;248;248;242m;[0m
|
||||
|
||||
[3;38;2;102;217;239mfn[0m[38;2;248;248;242m [0m[38;2;166;226;46mmax[0m[38;2;248;248;242m([0m[3;38;2;102;217;239mcomptime[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mT[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mtype[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[3;38;2;253;151;31ma[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mT[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mb[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mT[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mT[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[38;2;248;248;242ma [0m[38;2;249;38;114m>[0m[38;2;248;248;242m b[0m[38;2;248;248;242m)[0m[38;2;248;248;242m a [0m[38;2;249;38;114melse[0m[38;2;248;248;242m b[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m}[0m
|
@ -54,4 +54,4 @@ TEST_ESCAPE="escaped characters \n \t \r \" \' \$ or maybe a backslash \\..."
|
||||
TEST_DOUBLE="Lorem {$VAR1} ${VAR2} $VAR3 ipsum dolor sit amet\n\r\t\\"
|
||||
|
||||
# Single Quotes
|
||||
TEST_SINGLE='Lorem {$VAR1} ${VAR2} $VAR3 ipsum dolor sit amet\n\r\t\\'
|
||||
TEST_SINGLE='Lorem {$VAR1} ${VAR2} $VAR3 ipsum dolor sit amet\n\r\t\\'
|
||||
|
68
tests/syntax-tests/source/Lean/test.lean
Normal file
68
tests/syntax-tests/source/Lean/test.lean
Normal file
@ -0,0 +1,68 @@
|
||||
import data.matrix.notation
|
||||
import data.vector2
|
||||
|
||||
/-!
|
||||
|
||||
Helpers that don't currently fit elsewhere...
|
||||
|
||||
-/
|
||||
|
||||
lemma split_eq {m n : Type*} (x : m × n) (p p' : m × n) :
|
||||
p = x ∨ p' = x ∨ (x ≠ p ∧ x ≠ p') := by tauto
|
||||
|
||||
-- For `playfield`s, the piece type and/or piece index type.
|
||||
variables (X : Type*)
|
||||
variables [has_repr X]
|
||||
|
||||
namespace chess.utils
|
||||
|
||||
section repr
|
||||
|
||||
/--
|
||||
An auxiliary wrapper for `option X` that allows for overriding the `has_repr` instance
|
||||
for `option`, and rather, output just the value in the `some` and a custom provided
|
||||
`string` for `none`.
|
||||
-/
|
||||
structure option_wrapper :=
|
||||
(val : option X)
|
||||
(none_s : string)
|
||||
|
||||
instance wrapped_option_repr : has_repr (option_wrapper X) :=
|
||||
⟨λ ⟨val, s⟩, (option.map has_repr.repr val).get_or_else s⟩
|
||||
|
||||
variables {X}
|
||||
/--
|
||||
Construct an `option_wrapper` term from a provided `option X` and the `string`
|
||||
that will override the `has_repr.repr` for `none`.
|
||||
-/
|
||||
def option_wrap (val : option X) (none_s : string) : option_wrapper X := ⟨val, none_s⟩
|
||||
|
||||
-- The size of the "vectors" for a `fin n' → X`, for `has_repr` definitions
|
||||
variables {m' n' : ℕ}
|
||||
|
||||
/--
|
||||
For a "vector" `X^n'` represented by the type `Π n' : ℕ, fin n' → X`, where
|
||||
the `X` has a `has_repr` instance itself, we can provide a `has_repr` for the "vector".
|
||||
This definition is used for displaying rows of the playfield, when it is defined
|
||||
via a `matrix`, likely through notation.
|
||||
-/
|
||||
def vec_repr : Π {n' : ℕ}, (fin n' → X) → string :=
|
||||
λ _ v, string.intercalate ", " ((vector.of_fn v).to_list.map repr)
|
||||
|
||||
instance vec_repr_instance : has_repr (fin n' → X) := ⟨vec_repr⟩
|
||||
|
||||
/--
|
||||
For a `matrix` `X^(m' × n')` where the `X` has a `has_repr` instance itself,
|
||||
we can provide a `has_repr` for the matrix, using `vec_repr` for each of the rows of the matrix.
|
||||
This definition is used for displaying the playfield, when it is defined
|
||||
via a `matrix`, likely through notation.
|
||||
-/
|
||||
def matrix_repr : Π {m' n'}, matrix (fin m') (fin n') X → string :=
|
||||
λ _ _ M, string.intercalate ";\n" ((vector.of_fn M).to_list.map repr)
|
||||
|
||||
instance matrix_repr_instance :
|
||||
has_repr (matrix (fin n') (fin m') X) := ⟨matrix_repr⟩
|
||||
|
||||
end repr
|
||||
|
||||
end chess.utils
|
107
tests/syntax-tests/source/Zig/example.zig
Normal file
107
tests/syntax-tests/source/Zig/example.zig
Normal file
@ -0,0 +1,107 @@
|
||||
//! this is a top level doc, starts with "//!"
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
try stdout.print("Hello, {}!\n", .{"world"});
|
||||
}
|
||||
|
||||
const expect = std.testing.expect;
|
||||
|
||||
test "comments" {
|
||||
// comments start with "//" until newline
|
||||
// foo bar baz
|
||||
const x = true; // another comment
|
||||
expect(x);
|
||||
}
|
||||
|
||||
/// a doc comment starts with "///"
|
||||
/// multiple lines are merged together
|
||||
const Timestamp = struct {
|
||||
/// number of seconds since epoch
|
||||
seconds: i64,
|
||||
|
||||
/// number of nanoseconds past the second
|
||||
nano: u32,
|
||||
|
||||
const Self = @This();
|
||||
|
||||
pub fn unixEpoch() Self {
|
||||
return Self{
|
||||
.seconds = 0,
|
||||
.nanos = 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const my_val = switch (std.Target.current.os.tag) {
|
||||
.linux => "Linux",
|
||||
else => "not Linux",
|
||||
};
|
||||
|
||||
const Book = enum {
|
||||
paperback,
|
||||
hardcover,
|
||||
ebook,
|
||||
pdf,
|
||||
};
|
||||
|
||||
const TokenType = union(enum) {
|
||||
int: isize,
|
||||
float: f64,
|
||||
string: []const u8,
|
||||
};
|
||||
|
||||
const array_lit: [4]u8 = .{ 11, 22, 33, 44 };
|
||||
const sentinal_lit = [_:0]u8{ 1, 2, 3, 4 };
|
||||
|
||||
test "address of syntax" {
|
||||
// Get the address of a variable:
|
||||
const x: i32 = 1234;
|
||||
const x_ptr = &x;
|
||||
|
||||
// Dereference a pointer:
|
||||
expect(x_ptr.* == 1234);
|
||||
|
||||
// When you get the address of a const variable, you get a const pointer to a single item.
|
||||
expect(@TypeOf(x_ptr) == *const i32);
|
||||
|
||||
// If you want to mutate the value, you'd need an address of a mutable variable:
|
||||
var y: i32 = 5678;
|
||||
const y_ptr = &y;
|
||||
expect(@TypeOf(y_ptr) == *i32);
|
||||
y_ptr.* += 1;
|
||||
expect(y_ptr.* == 5679);
|
||||
}
|
||||
|
||||
// integer literals
|
||||
const decimal_int = 98222;
|
||||
const hex_int = 0xff;
|
||||
const another_hex_int = 0xFF;
|
||||
const octal_int = 0o755;
|
||||
const binary_int = 0b11110000;
|
||||
|
||||
// underscores may be placed between two digits as a visual separator
|
||||
const one_billion = 1_000_000_000;
|
||||
const binary_mask = 0b1_1111_1111;
|
||||
const permissions = 0o7_5_5;
|
||||
const big_address = 0xFF80_0000_0000_0000;
|
||||
|
||||
// float literals
|
||||
const floating_point = 123.0E+77;
|
||||
const another_float = 123.0;
|
||||
const yet_another = 123.0e+77;
|
||||
|
||||
const hex_floating_point = 0x103.70p-5;
|
||||
const another_hex_float = 0x103.70;
|
||||
const yet_another_hex_float = 0x103.70P-5;
|
||||
|
||||
// underscores may be placed between two digits as a visual separator
|
||||
const lightspeed = 299_792_458.000_000;
|
||||
const nanosecond = 0.000_000_001;
|
||||
const more_hex = 0x1234_5678.9ABC_CDEFp-10;
|
||||
|
||||
fn max(comptime T: type, a: T, b: T) T {
|
||||
return if (a > b) a else b;
|
||||
}
|
Reference in New Issue
Block a user