summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-23 14:38:19 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-23 14:38:19 -0600
commitbb1245976f10806634d2a60edd6218ecc23c8894 (patch)
treea3a8faf8770ac22ee66c39c8d2a4a60fbdff0931
parent6cbfdbf1b2a9f5e2aecb54662c71c6424ba32972 (diff)
downloadzash-chore/editor-and-lint-hints.tar.gz
chore: clangd sysroot note, shellcheck header, typst formattingchore/editor-and-lint-hints
-rw-r--r--.clangd17
-rw-r--r--formal/zash-spec.typ209
-rw-r--r--tests/posix/expand-edge.sh3
3 files changed, 182 insertions, 47 deletions
diff --git a/.clangd b/.clangd
index a3af66e..cb5b5f4 100644
--- a/.clangd
+++ b/.clangd
@@ -10,13 +10,16 @@ CompileFlags:
Remove: [-fzos-le-char-mode=*, -m64]
CompilationDatabase: .
----
-# The z/OS layer includes <spawn.h> constants that Linux headers lack, so
-# do not flag them while editing on Linux.
-If:
- PathMatch: src/sys_zos\.c
-Diagnostics:
- Suppress: ['*']
+# src/sys_zos.c is never built on Linux, but it can still be checked: point
+# clangd at a z/OS sysroot (/usr/include copied off a z/OS host) with the
+# editor's own clangd config, e.g.
+# If: {PathMatch: .*/src/sys_zos\.c}
+# CompileFlags:
+# Add: [-m32, -D__LL, -D__builtin_zos_va_list=__builtin_va_list,
+# -D_ALL_SOURCE, -D_EXT, -D_OPEN_SYS_FILE_EXT=1,
+# -isystem, /path/to/sysroots/zos/usr/include]
+# The path is per machine, so it does not belong in this file.
+
---
# Tests and benchmarks are shell scripts, not C.
diff --git a/formal/zash-spec.typ b/formal/zash-spec.typ
index 439568e..bf6fda8 100644
--- a/formal/zash-spec.typ
+++ b/formal/zash-spec.typ
@@ -8,7 +8,10 @@
#set heading(numbering: "1.1")
#show raw: set text(font: ("DejaVu Sans Mono", "Liberation Mono"), size: 9pt)
#show raw.where(block: true): block.with(
- fill: luma(245), inset: 8pt, radius: 3pt, width: 100%,
+ fill: luma(245),
+ inset: 8pt,
+ radius: 3pt,
+ width: 100%,
)
#show link: underline
@@ -20,24 +23,96 @@
#let mono = ("DejaVu Sans Mono", "Liberation Mono")
#let command-names = (
- ".", ":", "[", "alias", "alloc", "bg", "bind", "break", "cd", "chdir",
- "command", "continue", "echo", "eval", "exec", "exit", "export", "false",
- "fc", "fg", "free", "getopts", "hash", "integer", "jobs", "kill", "let",
- "local", "print", "printf", "pwd", "read", "readonly", "return", "set",
- "setvar", "shift", "tag", "test", "times", "trap", "true", "type",
- "typeset", "ulimit", "umask", "unalias", "unset", "wait", "whence",
+ ".",
+ ":",
+ "[",
+ "alias",
+ "alloc",
+ "bg",
+ "bind",
+ "break",
+ "cd",
+ "chdir",
+ "command",
+ "continue",
+ "echo",
+ "eval",
+ "exec",
+ "exit",
+ "export",
+ "false",
+ "fc",
+ "fg",
+ "free",
+ "getopts",
+ "hash",
+ "integer",
+ "jobs",
+ "kill",
+ "let",
+ "local",
+ "print",
+ "printf",
+ "pwd",
+ "read",
+ "readonly",
+ "return",
+ "set",
+ "setvar",
+ "shift",
+ "tag",
+ "test",
+ "times",
+ "trap",
+ "true",
+ "type",
+ "typeset",
+ "ulimit",
+ "umask",
+ "unalias",
+ "unset",
+ "wait",
+ "whence",
// utilities the text names
- "cat", "cmp", "diff", "sed", "sh", "zash", "dash", "bash", "ksh",
+ "cat",
+ "cmp",
+ "diff",
+ "sed",
+ "sh",
+ "zash",
+ "dash",
+ "bash",
+ "ksh",
)
#let reserved-names = (
- "!", "{", "}", "case", "do", "done", "elif", "else", "esac", "fi", "for",
- "function", "if", "in", "then", "time", "until", "while", "[[", "]]",
+ "!",
+ "{",
+ "}",
+ "case",
+ "do",
+ "done",
+ "elif",
+ "else",
+ "esac",
+ "fi",
+ "for",
+ "function",
+ "if",
+ "in",
+ "then",
+ "time",
+ "until",
+ "while",
+ "[[",
+ "]]",
)
#let cmd-style(s) = text(fill: rgb("#1f5fa8"), weight: "bold", s)
#let kw-style(s) = text(fill: rgb("#7a3e9d"), weight: "bold", s)
#let known(w) = w in command-names or w in reserved-names
-#let styled(w) = if w in command-names { cmd-style(w) } else if w in reserved-names { kw-style(w) } else { w }
+#let styled(w) = if w in command-names { cmd-style(w) } else if (
+ w in reserved-names
+) { kw-style(w) } else { w }
// A short span gets a padded, rounded box. A box cannot break across
// lines, so a long span gets a flat highlight instead. The highlight has
// no horizontal extent: Typst draws it once per text run, and a run with
@@ -45,8 +120,13 @@
#let code-bg(body, len: 0) = if len <= 32 {
box(fill: luma(240), inset: (x: 1.6pt), outset: (y: 1.6pt), radius: 2pt, body)
} else {
- highlight(fill: luma(240), extent: 0pt, top-edge: "ascender",
- bottom-edge: "descender", body)
+ highlight(
+ fill: luma(240),
+ extent: 0pt,
+ top-edge: "ascender",
+ bottom-edge: "descender",
+ body,
+ )
}
// The first word is highlighted if it names a command or a reserved word.
@@ -87,15 +167,20 @@
let id = "R-" + prefix + "-" + str(c.get().first())
if key != none [#metadata(id)#label("rule-" + key)]
block(
- width: 100%, inset: (left: 8pt, y: 4pt),
- stroke: (left: 2pt + luma(160)), breakable: true,
+ width: 100%,
+ inset: (left: 8pt, y: 4pt),
+ stroke: (left: 2pt + luma(160)),
+ breakable: true,
)[
#text(weight: "bold", font: ("DejaVu Sans Mono",), size: 8.5pt)[#id]
#if status != none [ #text(fill: rgb("#a33"), size: 8.5pt)[(#status)] ]
#h(0.5em) #body
#if tests.len() > 0 [
#linebreak()
- #text(size: 8.5pt, fill: luma(90))[Tests: #tests.map(t => raw(t)).join(", ")]
+ #text(
+ size: 8.5pt,
+ fill: luma(90),
+ )[Tests: #tests.map(t => raw(t)).join(", ")]
]
]
}
@@ -109,12 +194,18 @@
/// Something the specification does not yet decide.
#let open(body) = block(
- width: 100%, fill: rgb("#fff4e0"), inset: 8pt, radius: 3pt,
+ width: 100%,
+ fill: rgb("#fff4e0"),
+ inset: 8pt,
+ radius: 3pt,
)[*Open.* #body]
/// A note: explanation, not a rule.
#let note(body) = block(
- width: 100%, fill: rgb("#eef3fb"), inset: 8pt, radius: 3pt,
+ width: 100%,
+ fill: rgb("#eef3fb"),
+ inset: 8pt,
+ radius: 3pt,
)[*Note.* #body]
// Semantic brackets.
@@ -145,7 +236,9 @@
Describes zash at commit #raw("b4d7dc3") with the audit fixes applied
]
#v(4pt)
- #text(size: 10pt, fill: luma(80))[#datetime.today().display("[month repr:long] [day], [year]")]
+ #text(size: 10pt, fill: luma(80))[#(
+ datetime.today().display("[month repr:long] [day], [year]")
+ )]
]
#v(1fr)
#block(width: 100%, inset: (x: 0.4in))[
@@ -314,8 +407,12 @@ expansion have used it (@expansion); nothing is encoded in the text.
and quoted:
#table(
- columns: 2, inset: 4pt, stroke: 0.4pt + luma(180),
- [`\a \b \e \f \n \r \t \v`], [the control character so named (`\e` is escape)],
+ columns: 2,
+ inset: 4pt,
+ stroke: 0.4pt + luma(180),
+ [`\a \b \e \f \n \r \t \v`],
+ [the control character so named (`\e` is escape)],
+
[`\\` `\'` `\"` `\?`], [the character itself],
[`\`_ooo_], [the byte with octal value _ooo_ (one to three digits)],
[`\x`_hh_], [the byte with hexadecimal value _hh_ (one or two digits)],
@@ -337,7 +434,11 @@ expansion have used it (@expansion); nothing is encoded in the text.
== Reserved words <reserved>
-#rule("LEX", tests: ("posix/syntax", "zash/function-kw", "zash/cond"), key: "reserved")[
+#rule(
+ "LEX",
+ tests: ("posix/syntax", "zash/function-kw", "zash/cond"),
+ key: "reserved",
+)[
The reserved words are
```
@@ -620,7 +721,9 @@ $pi_1$ from $Q^*$ to $B^*$ applied to every resulting field.
The conditional forms, for a parameter $x$ and a word $w$, yield:
#table(
- columns: 4, inset: 4pt, stroke: 0.4pt + luma(180),
+ columns: 4,
+ inset: 4pt,
+ stroke: 0.4pt + luma(180),
[*form*], [*$x$ set, non-empty*], [*$x$ set, empty*], [*$x$ unset*],
[`${x:-w}`], [$x$], [#sem($w$)], [#sem($w$)],
[`${x-w}`], [$x$], [empty], [#sem($w$)],
@@ -793,9 +896,11 @@ are _IFS delimiters_.
#rule("PAT", key: "match")[
For a pattern $p$ and a string $s$, $"match"(p, s)$ holds when $p$
matches the whole of $s$. It is defined by:
- $ "match"(epsilon, s) &<==> s = epsilon \
- "match"(* p', s) &<==> exists i. "match"(p', s[i..]) \
- "match"(e p', c s') &<==> e "matches" c and "match"(p', s') $
+ $
+ "match"(epsilon, s) & <==> s = epsilon \
+ "match"(* p', s) & <==> exists i. "match"(p', s[i..]) \
+ "match"(e p', c s') & <==> e "matches" c and "match"(p', s')
+ $
where $e$ is `?`, a bracket expression or a literal byte.
]
@@ -1115,16 +1220,23 @@ subshells.
for the others. The target word is expanded as one field (@expansion).
#table(
- columns: 2, inset: 4pt, stroke: 0.4pt + luma(180),
+ columns: 2,
+ inset: 4pt,
+ stroke: 0.4pt + luma(180),
[`n<f`], [open _f_ for reading],
- [`n>f`], [create or truncate _f_; an error if `set -C` is on and _f_
+ [`n>f`],
+ [create or truncate _f_; an error if `set -C` is on and _f_
is an existing regular file],
+
[`n>|f`], [as `>`, ignoring `set -C`],
[`n>>f`], [open _f_ for appending, creating it if it does not exist],
- [`n<>f`], [open _f_ for reading and writing, creating it if it does
+ [`n<>f`],
+ [open _f_ for reading and writing, creating it if it does
not exist],
+
[`n<&m`, `n>&m`], [make _n_ a copy of descriptor _m_; `-` closes _n_],
- [`n<<d`, `n<<-d`], [open the here-document body for reading on
+ [`n<<d`, `n<<-d`],
+ [open the here-document body for reading on
descriptor _n_],
)
]
@@ -1196,7 +1308,9 @@ subshells.
shell is interactive:
#table(
- columns: 3, inset: 4pt, stroke: 0.4pt + luma(180),
+ columns: 3,
+ inset: 4pt,
+ stroke: 0.4pt + luma(180),
[*error*], [*non-interactive*], [*interactive*],
[syntax error], [exit, status 2], [status 2, next command],
[special builtin error], [exit], [status, next command],
@@ -1285,7 +1399,9 @@ encoding and process creation, not script semantics.
= Differences from POSIX and other shells <differences>
#table(
- columns: (auto, 1fr), inset: 4pt, stroke: 0.4pt + luma(180),
+ columns: (auto, 1fr),
+ inset: 4pt,
+ stroke: 0.4pt + luma(180),
[*rule*], [*difference*],
[#rref("stdin")], [standard input is never read ahead of the running command],
[#rref("dsq")], [`$'...'` escapes, `\c`_X_ in ASCII builds only],
@@ -1295,7 +1411,9 @@ encoding and process creation, not script semantics.
[#rref("bracket")], [`[^...]` negates],
[#rref("byteorder")], [ranges and sorting by byte code, not locale],
[#rref("arincr")], [`++`, `--` and `,`],
- [#rref("arivars")], [variable values evaluated as expressions, 16 levels deep],
+ [#rref("arivars")],
+ [variable values evaluated as expressions, 16 levels deep],
+
[#rref("laststage")], [last pipeline stage in the current shell],
[#rref("return")], [`return 300` gives 44],
[#rref("local")], [`local`, `typeset` with dynamic scope],
@@ -1314,20 +1432,31 @@ encoding and process creation, not script semantics.
Each chapter becomes one Lean module. The first things to formalise:
#table(
- columns: (auto, 1fr), inset: 4pt, stroke: 0.4pt + luma(180),
+ columns: (auto, 1fr),
+ inset: 4pt,
+ stroke: 0.4pt + luma(180),
[*chapter*], [*what to formalise first*],
- [Patterns], [`match` as an inductive predicate (#rref("match")); prove the
+ [Patterns],
+ [`match` as an inductive predicate (#rref("match")); prove the
trimming rule (#rref("trim")) correct for the shortest and longest match],
- [Arithmetic], [the grammar as an inductive type and #sem($e$) as a total
+
+ [Arithmetic],
+ [the grammar as an inductive type and #sem($e$) as a total
function into `Int64`; prove #rref("wrap") (wrapping) and #rref("shortcircuit")
(unevaluated operands have no effect)],
- [Field splitting], [#rref("split") as a function on flagged bytes; prove that
+
+ [Field splitting],
+ [#rref("split") as a function on flagged bytes; prove that
quoted bytes are never split (#rref("order"))],
- [Grammar], [the productions as an inductive type; the `((` rule
+
+ [Grammar],
+ [the productions as an inductive type; the `((` rule
(#rref("dparen")) as a decidable predicate],
- [Commands], [a small-step semantics over an environment; last-stage
+
+ [Commands],
+ [a small-step semantics over an environment; last-stage
and subshell isolation as theorems (#rref("laststage"), #rref("subshell"))],
)
Differential testing then checks the C code against the model, with the
-existing suite and random inputs. CBMC checks the smallest pieces. \ No newline at end of file
+existing suite and random inputs. CBMC checks the smallest pieces.
diff --git a/tests/posix/expand-edge.sh b/tests/posix/expand-edge.sh
index 230578e..6a80500 100644
--- a/tests/posix/expand-edge.sh
+++ b/tests/posix/expand-edge.sh
@@ -1,3 +1,6 @@
+# shellcheck shell=sh
+# shellcheck disable=SC1037,SC2005,SC2006,SC2016,SC2028,SC2034,SC2046,SC2068,SC2086,SC2116,SC2145,SC3058
+# ^ the point of this file: expansions written the wrong way on purpose.
# Expansion corner cases.
set -- "a b" "" c
printf '<%s>' "$@"; echo