mirror of
https://github.com/sharkdp/bat
synced 2024-11-15 08:37:12 +00:00
Merge remote-tracking branch 'origin/master' into fix-1063
This commit is contained in:
commit
478233f795
24 changed files with 630 additions and 55 deletions
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
@ -7,33 +7,41 @@ assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!-- Hey there, thank you for creating an issue! -->
|
||||||
Hey there, thanks for creating an issue!
|
|
||||||
|
|
||||||
In order to reproduce your issue, we might need to know a little bit more about the environment
|
|
||||||
which you're running `bat` on.
|
|
||||||
|
|
||||||
If you're on Linux or MacOS:
|
|
||||||
Please run the script at https://github.com/sharkdp/bat/blob/master/diagnostics/info.sh and
|
|
||||||
paste the output at the bottom of the bug report.
|
|
||||||
|
|
||||||
If you're on Windows:
|
|
||||||
Please tell us about your Windows Version (e.g. "Windows 10 1908") at the
|
|
||||||
bottom of the bug report.
|
|
||||||
-->
|
|
||||||
|
|
||||||
**What version of `bat` are you using?**
|
**What version of `bat` are you using?**
|
||||||
[paste the output of `bat --version` here]
|
|
||||||
|
<!-- Output of `bat --version` -->
|
||||||
|
|
||||||
|
|
||||||
**Describe the bug you encountered:**
|
**Describe the bug you encountered:**
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
**What did you expect to happen instead?**
|
**What did you expect to happen instead?**
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
**How did you install `bat`?**
|
**How did you install `bat`?**
|
||||||
|
|
||||||
<!-- apt-get, homebrew, GitHub release, etc. -->
|
<!-- apt-get, homebrew, GitHub release, etc. -->
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[paste the output of `info.sh` here]
|
**Evironment**
|
||||||
|
|
||||||
|
<!--
|
||||||
|
In order to reproduce your issue, please add some information about the environment
|
||||||
|
in which you're running bat.
|
||||||
|
|
||||||
|
Linux and MacOS:
|
||||||
|
Please run the script at
|
||||||
|
|
||||||
|
https://github.com/sharkdp/bat/blob/master/diagnostics/info.sh
|
||||||
|
|
||||||
|
(click "Raw" to get the actual source code) and paste the Markdown output here.
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
Please add your Windows Version (e.g. "Windows 10 1908")
|
||||||
|
-->
|
||||||
|
|
2
.github/workflows/CICD.yml
vendored
2
.github/workflows/CICD.yml
vendored
|
@ -27,7 +27,7 @@ jobs:
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: clippy
|
command: clippy
|
||||||
args: --all-targets --all-features
|
args: --all-targets --all-features -- --allow clippy::style
|
||||||
- name: Test
|
- name: Test
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
|
6
.gitmodules
vendored
6
.gitmodules
vendored
|
@ -207,3 +207,9 @@
|
||||||
path = assets/themes/gruvbox
|
path = assets/themes/gruvbox
|
||||||
url = https://github.com/subnut/gruvbox-tmTheme.git
|
url = https://github.com/subnut/gruvbox-tmTheme.git
|
||||||
branch = bat-source
|
branch = bat-source
|
||||||
|
[submodule "assets/syntaxes/02_Extra/Lean"]
|
||||||
|
path = assets/syntaxes/02_Extra/Lean
|
||||||
|
url = https://github.com/leanprover/vscode-lean.git
|
||||||
|
[submodule "assets/syntaxes/02_Extra/Zig"]
|
||||||
|
path = assets/syntaxes/02_Extra/Zig
|
||||||
|
url = https://github.com/ziglang/sublime-zig-language.git
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
|
|
||||||
## Syntaxes
|
## Syntaxes
|
||||||
|
|
||||||
|
- Added Zig syntax, see #1470 (@paulsmith)
|
||||||
|
- Added Lean syntax, see #1446 (@Julian)
|
||||||
|
- Added `.resource` extension for Robot Framework files, see #1386
|
||||||
|
|
||||||
## New themes
|
## New themes
|
||||||
|
|
||||||
- `ansi` replaces `ansi-dark` and `ansi-light`, see #1104 and #1412 (@mk12)
|
- `ansi` replaces `ansi-dark` and `ansi-light`, see #1104 and #1412 (@mk12)
|
||||||
|
|
41
Cargo.lock
generated
41
Cargo.lock
generated
|
@ -253,9 +253,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "console"
|
name = "console"
|
||||||
version = "0.13.0"
|
version = "0.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a50aab2529019abfabfa93f1e6c41ef392f91fbf179b347a7e96abb524884a08"
|
checksum = "7cc80946b3480f421c2f17ed1cb841753a371c7c5104f51d507e13f532c856aa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"encode_unicode",
|
"encode_unicode",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
@ -264,7 +264,6 @@ dependencies = [
|
||||||
"terminal_size",
|
"terminal_size",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
"winapi",
|
"winapi",
|
||||||
"winapi-util",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -499,9 +498,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "git2"
|
name = "git2"
|
||||||
version = "0.13.12"
|
version = "0.13.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca6f1a0238d7f8f8fd5ee642f4ebac4dbc03e03d1f78fbe7a3ede35dcf7e2224"
|
checksum = "44f267c9da8a4de3c615b59e23606c75f164f84896e97f4dd6c15a4294de4359"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -609,9 +608,9 @@ checksum = "aa7087f49d294270db4e1928fc110c976cd4b9e5a16348e0a1df09afa99e6c98"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libgit2-sys"
|
name = "libgit2-sys"
|
||||||
version = "0.12.14+1.1.0"
|
version = "0.12.17+1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f25af58e6495f7caf2919d08f212de550cfa3ed2f5e744988938ea292b9f549"
|
checksum = "f4ebdf65ca745126df8824688637aa0535a88900b83362d8ca63893bcf4e8841"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -850,9 +849,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates"
|
name = "predicates"
|
||||||
version = "1.0.5"
|
version = "1.0.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "96bfead12e90dccead362d62bb2c90a5f6fc4584963645bc7f71a735e0b0735a"
|
checksum = "73dd9b7b200044694dfede9edf907c1ca19630908443e9447e624993700c6932"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"difference",
|
"difference",
|
||||||
"float-cmp",
|
"float-cmp",
|
||||||
|
@ -951,9 +950,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.3.9"
|
version = "1.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
|
checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -963,9 +962,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.6.18"
|
version = "0.6.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
|
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "remove_dir_all"
|
name = "remove_dir_all"
|
||||||
|
@ -1036,18 +1035,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.117"
|
version = "1.0.118"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
|
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.117"
|
version = "1.0.118"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
|
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1148,9 +1147,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syntect"
|
name = "syntect"
|
||||||
version = "4.4.0"
|
version = "4.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4e3978df05b5850c839a6b352d3c35ce0478944a4be689be826b53cf75363e88"
|
checksum = "2bfac2b23b4d049dc9a89353b4e06bbc85a8f42020cccbe5409a115cf19031e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
@ -1191,9 +1190,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "terminal_size"
|
name = "terminal_size"
|
||||||
version = "0.1.13"
|
version = "0.1.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9a14cd9f8c72704232f0bfc8455c0e861f0ad4eb60cc9ec8a170e231414c1e13"
|
checksum = "4bd2d183bd3fac5f5fe38ddbeb4dc9aec4a39a9d7d59e7491d900302da01cbe1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"winapi",
|
"winapi",
|
||||||
|
|
|
@ -37,7 +37,7 @@ regex-fancy = ["syntect/regex-fancy"] # Use the rust-only "fancy-regex" engine
|
||||||
atty = { version = "0.2.14", optional = true }
|
atty = { version = "0.2.14", optional = true }
|
||||||
ansi_term = "^0.12.1"
|
ansi_term = "^0.12.1"
|
||||||
ansi_colours = "^1.0"
|
ansi_colours = "^1.0"
|
||||||
console = "0.13.0"
|
console = "0.14.0"
|
||||||
dirs = { version = "3.0", optional = true }
|
dirs = { version = "3.0", optional = true }
|
||||||
lazy_static = { version = "1.4", optional = true }
|
lazy_static = { version = "1.4", optional = true }
|
||||||
wild = { version = "2.0", optional = true }
|
wild = { version = "2.0", optional = true }
|
||||||
|
@ -57,7 +57,7 @@ optional = true
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.syntect]
|
[dependencies.syntect]
|
||||||
version = "4.4.0"
|
version = "4.5.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["parsing", "yaml-load", "dump-load", "dump-create"]
|
features = ["parsing", "yaml-load", "dump-load", "dump-create"]
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ default-features = false
|
||||||
tempdir = "0.3"
|
tempdir = "0.3"
|
||||||
assert_cmd = "1.0.2"
|
assert_cmd = "1.0.2"
|
||||||
serial_test = "0.5.1"
|
serial_test = "0.5.1"
|
||||||
predicates = "1.0.5"
|
predicates = "1.0.6"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
clap = { version = "2.33", optional = true }
|
clap = { version = "2.33", optional = true }
|
||||||
|
|
|
@ -180,7 +180,7 @@ The [`prettybat`](https://github.com/eth-p/bat-extras/blob/master/doc/prettybat.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
[![Packaging status](https://repology.org/badge/vertical-allrepos/bat.svg)](https://repology.org/project/bat/versions)
|
[![Packaging status](https://repology.org/badge/vertical-allrepos/bat-cat.svg)](https://repology.org/project/bat-cat/versions)
|
||||||
|
|
||||||
### On Ubuntu (using `apt`)
|
### On Ubuntu (using `apt`)
|
||||||
*... and other Debian-based Linux distributions.*
|
*... and other Debian-based Linux distributions.*
|
||||||
|
|
2
assets/syntaxes/02_Extra/Julia
vendored
2
assets/syntaxes/02_Extra/Julia
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 6c0d770fc74e6bc037c70cae1f94fe113b60fd95
|
Subproject commit e2b1cb549d57368b7b22e79430a1d5f47555e802
|
1
assets/syntaxes/02_Extra/Lean
vendored
Submodule
1
assets/syntaxes/02_Extra/Lean
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 7e99440b33c834b11deda67144a6a7ce5a666f0e
|
125
assets/syntaxes/02_Extra/Lean.sublime-syntax
vendored
Normal file
125
assets/syntaxes/02_Extra/Lean.sublime-syntax
vendored
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
# http://www.sublimetext.com/docs/3/syntax.html
|
||||||
|
name: Lean
|
||||||
|
file_extensions:
|
||||||
|
- lean
|
||||||
|
scope: source.lean
|
||||||
|
contexts:
|
||||||
|
main:
|
||||||
|
- include: comments
|
||||||
|
- match: '\b(?<!\.)(inductive|coinductive|structure|theorem|axiom|axioms|abbreviation|lemma|definition|def|instance|class|constant)\b\s+(\{[^}]*\})?'
|
||||||
|
captures:
|
||||||
|
1: keyword.other.definitioncommand.lean
|
||||||
|
push:
|
||||||
|
- meta_scope: meta.definitioncommand.lean
|
||||||
|
- match: '(?=\bwith\b|\bextends\b|[:\|\(\[\{⦃<>])'
|
||||||
|
pop: true
|
||||||
|
- include: comments
|
||||||
|
- include: definitionName
|
||||||
|
- match: ","
|
||||||
|
- match: \b(Prop|Type|Sort)\b
|
||||||
|
scope: storage.type.lean
|
||||||
|
- match: '\battribute\b\s*\[[^\]]*\]'
|
||||||
|
scope: storage.modifier.lean
|
||||||
|
- match: '@\[[^\]]*\]'
|
||||||
|
scope: storage.modifier.lean
|
||||||
|
- match: \b(?<!\.)(private|meta|mutual|protected|noncomputable)\b
|
||||||
|
scope: keyword.control.definition.modifier.lean
|
||||||
|
- match: \b(sorry)\b
|
||||||
|
scope: invalid.illegal.lean
|
||||||
|
- match: '#print\s+(def|definition|inductive|instance|structure|axiom|axioms|class)\b'
|
||||||
|
scope: keyword.other.command.lean
|
||||||
|
- match: '#(print|eval|reduce|check|help|exit|find|where)\b'
|
||||||
|
scope: keyword.other.command.lean
|
||||||
|
- match: \b(?<!\.)(import|export|prelude|theory|definition|def|abbreviation|instance|renaming|hiding|exposing|parameter|parameters|begin|constant|constants|lemma|variable|variables|theorem|example|open|axiom|inductive|coinductive|with|structure|universe|universes|alias|precedence|reserve|postfix|prefix|infix|infixl|infixr|notation|end|using|namespace|section|local|set_option|extends|include|omit|class|classes|instances|raw|run_cmd|restate_axiom)(?!\.)\b
|
||||||
|
scope: keyword.other.lean
|
||||||
|
- match: \b(?<!\.)(calc|have|this|match|do|suffices|show|by|in|at|let|forall|fun|exists|assume|from|obtain|haveI|λ)(?!\.)\b
|
||||||
|
scope: keyword.other.lean
|
||||||
|
- match: «
|
||||||
|
push:
|
||||||
|
- meta_content_scope: entity.name.lean
|
||||||
|
- match: »
|
||||||
|
pop: true
|
||||||
|
- match: \b(?<!\.)(if|then|else)\b
|
||||||
|
scope: keyword.control.lean
|
||||||
|
- match: '"'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.begin.lean
|
||||||
|
push:
|
||||||
|
- meta_scope: string.quoted.double.lean
|
||||||
|
- match: '"'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.end.lean
|
||||||
|
pop: true
|
||||||
|
- match: '\\[\\"nt'']'
|
||||||
|
scope: constant.character.escape.lean
|
||||||
|
- match: '\\x[0-9A-Fa-f][0-9A-Fa-f]'
|
||||||
|
scope: constant.character.escape.lean
|
||||||
|
- match: '\\u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]'
|
||||||
|
scope: constant.character.escape.lean
|
||||||
|
- match: '''[^\\'']'''
|
||||||
|
scope: string.quoted.single.lean
|
||||||
|
- match: '''(\\(x..|u....|.))'''
|
||||||
|
scope: string.quoted.single.lean
|
||||||
|
captures:
|
||||||
|
1: constant.character.escape.lean
|
||||||
|
- match: '`+[^\[(]\S+'
|
||||||
|
scope: entity.name.lean
|
||||||
|
- match: '\b([0-9]+|0([xX][0-9a-fA-F]+))\b'
|
||||||
|
scope: constant.numeric.lean
|
||||||
|
blockComment:
|
||||||
|
- match: /-
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.block.lean
|
||||||
|
- match: "-/"
|
||||||
|
pop: true
|
||||||
|
- include: scope:source.lean.markdown
|
||||||
|
- include: blockComment
|
||||||
|
comments:
|
||||||
|
- include: dashComment
|
||||||
|
- include: docComment
|
||||||
|
- include: stringBlock
|
||||||
|
- include: modDocComment
|
||||||
|
- include: blockComment
|
||||||
|
dashComment:
|
||||||
|
- match: (--)
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.comment.lean
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.line.double-dash.lean
|
||||||
|
- match: $
|
||||||
|
pop: true
|
||||||
|
- include: scope:source.lean.markdown
|
||||||
|
definitionName:
|
||||||
|
- match: '\b[^:«»\(\)\{\}[:space:]=→λ∀?][^:«»\(\)\{\}[:space:]]*'
|
||||||
|
scope: entity.name.function.lean
|
||||||
|
- match: «
|
||||||
|
push:
|
||||||
|
- meta_content_scope: entity.name.function.lean
|
||||||
|
- match: »
|
||||||
|
pop: true
|
||||||
|
docComment:
|
||||||
|
- match: /--
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.block.documentation.lean
|
||||||
|
- match: "-/"
|
||||||
|
pop: true
|
||||||
|
- include: scope:source.lean.markdown
|
||||||
|
- include: blockComment
|
||||||
|
modDocComment:
|
||||||
|
- match: /-!
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.block.documentation.lean
|
||||||
|
- match: "-/"
|
||||||
|
pop: true
|
||||||
|
- include: scope:source.lean.markdown
|
||||||
|
- include: blockComment
|
||||||
|
stringBlock:
|
||||||
|
- match: /-"
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.block.string.lean
|
||||||
|
- match: '"-/'
|
||||||
|
pop: true
|
||||||
|
- include: scope:source.lean.markdown
|
||||||
|
- include: blockComment
|
|
@ -4,6 +4,7 @@
|
||||||
name: Robot Framework
|
name: Robot Framework
|
||||||
file_extensions:
|
file_extensions:
|
||||||
- robot
|
- robot
|
||||||
|
- resource
|
||||||
scope: source.robot
|
scope: source.robot
|
||||||
contexts:
|
contexts:
|
||||||
main:
|
main:
|
||||||
|
|
2
assets/syntaxes/02_Extra/SCSS_Sass
vendored
2
assets/syntaxes/02_Extra/SCSS_Sass
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit bc6332c1be2c5590d334a2a58d3b83a8d07ac7ef
|
Subproject commit 4868322030c3644d6b8cfff68c85849789d9bdb2
|
2
assets/syntaxes/02_Extra/TypeScript
vendored
2
assets/syntaxes/02_Extra/TypeScript
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 603ebb48b162bc453a0bb2cbb0192f3606819f6d
|
Subproject commit a607ddfec90648c1c2f33f8306733f6aec5d2b78
|
1
assets/syntaxes/02_Extra/Zig
vendored
Submodule
1
assets/syntaxes/02_Extra/Zig
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 87ecbcae6fb5718369ce3bb3472ca0b2634e78e6
|
2
assets/themes/dracula-sublime
vendored
2
assets/themes/dracula-sublime
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 26c57ec282abcaa76e57e055f38432bd827ac34e
|
Subproject commit c2de0acf5af67042393cf70de68013153c043656
|
2
assets/themes/zenburn
vendored
2
assets/themes/zenburn
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit cb746f69624e635f6f4d127fa9244658e690c34b
|
Subproject commit 7f6fb86e0dcdd06d3c5181ad1cbe94c970834143
|
|
@ -16,16 +16,51 @@ in the `.sublime-syntax` format.
|
||||||
*New Syntax from XXX.tmLanguage...*. Save the new file in the `assets/syntaxes` folder.
|
*New Syntax from XXX.tmLanguage...*. Save the new file in the `assets/syntaxes` folder.
|
||||||
|
|
||||||
3. Run the `assets/create.sh` script. It calls `bat cache --build` to parse all available
|
3. Run the `assets/create.sh` script. It calls `bat cache --build` to parse all available
|
||||||
`.sublime-syntax` files and serialize them to a `syntaxes.bin` file (in this folder).
|
`.sublime-syntax` files and serialize them to a `syntaxes.bin` file.
|
||||||
|
|
||||||
4. Re-compile `bat`. At compilation time, the `syntaxes.bin` file will be stored inside the
|
4. Re-compile `bat`. At compilation time, the `syntaxes.bin` file will be stored inside the
|
||||||
`bat` binary.
|
`bat` binary.
|
||||||
|
|
||||||
5. Use `bat --list-languages` to check if the new languages are available.
|
5. Use `bat --list-languages` to check if the new languages are available.
|
||||||
|
|
||||||
6. If you send a pull request with your changes, please do *not* include the changed `syntaxes.bin`
|
6. Add a syntax test for the new language. See [#Syntax-tests](below) for details.
|
||||||
|
|
||||||
|
7. If you send a pull request with your changes, please do *not* include the changed `syntaxes.bin`
|
||||||
file. A new binary cache file will be created once before every new release of `bat`.
|
file. A new binary cache file will be created once before every new release of `bat`.
|
||||||
|
|
||||||
|
### Syntax tests
|
||||||
|
|
||||||
|
`bat` has a set of syntax highlighting regression tests in `tests/syntax-tests`. The main idea is
|
||||||
|
make sure that we do not run into issues we had in the past where either (1) syntax highlighting
|
||||||
|
for some language is suddenly not working anymore or (2) `bat` suddenly crashes for some input (due
|
||||||
|
to `regex` incompatibilities between `syntect` and Sublime Text).
|
||||||
|
|
||||||
|
In order to add a new test file, please follow these steps (let's take "Ruby" as an example):
|
||||||
|
|
||||||
|
1. Make sure that you are running the **latest version of `bat`** and that `bat` is available on
|
||||||
|
the path. If you are creating a syntax test for a new builtin syntax (see above), make sure that
|
||||||
|
your version of `bat` already has the new syntax builtin.
|
||||||
|
2. Find an example Ruby source file or write one yourself. If possible, the file should aim to be
|
||||||
|
"comprehensive" (i.e. include a lot of the possible syntax), but this is not strictly necessary.
|
||||||
|
A simple file is better than none at all. Also, the files shouldn't be gigantic.
|
||||||
|
3. Save the file in `tests/syntax-tests/source/Ruby` (adapt for your language). The file name could
|
||||||
|
be `test.rb` (adapt extension) but can also be adapted if that is necessary in order for `bat` to
|
||||||
|
highlight it correctly (e.g. `Makefile`).
|
||||||
|
4. If you have copied the file from somewhere else, please make sure that the file *may* be copied
|
||||||
|
under the respective license and that the license is compatible with `bat`s license. If it
|
||||||
|
requires attribution, please add a `LICENSE.md` in the same folder with a text like this:
|
||||||
|
```
|
||||||
|
The `test.rb` file has been added from [enter source here] under the following license:
|
||||||
|
|
||||||
|
[add license text here]
|
||||||
|
```
|
||||||
|
5. Go to `tests/syntax-tests` and run the `update.sh` Bash script. A new file should be generated
|
||||||
|
in the `highlighted` folder (e.g. `highlighted/Ruby/test.rb`).
|
||||||
|
6. Use `cat` or `bat --language=txt` to display the content of this file and make sure that the
|
||||||
|
syntax highlighting looks correct.
|
||||||
|
7. `git add` the new files in the `source` folder as well as the autogenerated files in the
|
||||||
|
`highlighted` folder.
|
||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
|
|
||||||
Make sure that the local cache does not interfere with the internally stored syntaxes and
|
Make sure that the local cache does not interfere with the internally stored syntaxes and
|
||||||
|
@ -44,7 +79,7 @@ The following files have been manually modified after converting from a `.tmLang
|
||||||
* `INI.sublime-syntax` => added `.hgrc`, `hgrc`, and `desktop` file types and support for comments after section headers
|
* `INI.sublime-syntax` => added `.hgrc`, `hgrc`, and `desktop` file types and support for comments after section headers
|
||||||
* `Org mode.sublime-syntax` => removed `task` file type.
|
* `Org mode.sublime-syntax` => removed `task` file type.
|
||||||
* `SML.sublime_syntax` => removed `ml` file type.
|
* `SML.sublime_syntax` => removed `ml` file type.
|
||||||
* `Robot.sublime_syntax` => changed name to "Robot Framework"
|
* `Robot.sublime_syntax` => changed name to "Robot Framework", added `.resource` extension
|
||||||
|
|
||||||
### Non-submodule additions
|
### Non-submodule additions
|
||||||
|
|
||||||
|
@ -59,3 +94,4 @@ The following files have been manually modified after converting from a `.tmLang
|
||||||
https://github.com/seanjames777/SML-Language-Definition/blob/master/sml.tmLanguage
|
https://github.com/seanjames777/SML-Language-Definition/blob/master/sml.tmLanguage
|
||||||
* `Cabal.sublime_syntax` has been added manually from
|
* `Cabal.sublime_syntax` has been added manually from
|
||||||
https://github.com/SublimeHaskell/SublimeHaskell/ - we don't want to include the whole submodule because it includes other syntaxes ("Haskell improved") as well.
|
https://github.com/SublimeHaskell/SublimeHaskell/ - we don't want to include the whole submodule because it includes other syntaxes ("Haskell improved") as well.
|
||||||
|
* `Lean.sublime-syntax` has been added manually from https://github.com/leanprover/vscode-lean/blob/master/syntaxes/lean.json via conversion.
|
||||||
|
|
52
tests/benchmarks/run-benchmarks.sh
vendored
52
tests/benchmarks/run-benchmarks.sh
vendored
|
@ -1,28 +1,72 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
||||||
|
|
||||||
|
# Check that Hyperfine is installed.
|
||||||
if ! command -v hyperfine > /dev/null 2>&1; then
|
if ! command -v hyperfine > /dev/null 2>&1; then
|
||||||
echo "'hyperfine' does not seem to be installed."
|
echo "'hyperfine' does not seem to be installed."
|
||||||
echo "You can get it here: https://github.com/sharkdp/hyperfine"
|
echo "You can get it here: https://github.com/sharkdp/hyperfine"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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 "### Startup time"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
hyperfine --warmup 3 bat
|
hyperfine --warmup 3 "$BAT"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "### Plain text"
|
echo "### Plain text"
|
||||||
echo
|
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
|
||||||
echo "### Time to syntax-highlight large files"
|
echo "### Time to syntax-highlight large files"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
for SRC in test-src/*; do
|
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
|
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
|
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;
|
||||||
|
}
|
Loading…
Reference in a new issue