// A function definition: its name, its span from head to body, and the // definition it sits in. import { Schema } from "effect"; /** * One function definition of a script, `NAME() body` or `function NAME body`: * text bash stores and runs only when the function is called. * * @remarks * `name` is the name word as written, backslash-newlines removed (a word * bash would reject as a name is kept as written, and a `function` with no * word after it has the empty name). `start` is the offset of * the name, or of `function`, and `end` the offset past the body's closing * word (`}`, `)`, `fi`, `done` or `esac`). `closed` is `false` when the body * never closes, so `end` is the end of the source, or is not one this * package tracks, so `end` is where what came instead starts and none of it * is part of the definition. bash takes only a compound command as a body, * with nothing but newlines before it, and rejects the script otherwise * (`f() echo x`, `f(); { x; }`, `f() >o { x; }`); it also accepts a * `[[ … ]]` or `(( … ))` body, which is left unmarked, over-reporting. `parent` is the index in `ShellScript.functions` of * the definition it sits in, `None` at the top level, so definitions are * numbered in source order with a parent before its children. * * Every segment of a definition, its head (`f`, `function f`) included, * names it in `ShellSegment.function`. Its commands are still parsed and * reported by `ShellScript.commands()`: a guard that allows a definition but * not a call must then track the names a script defines, since `f` later * runs the body without naming it. * * @public */ export class ShellFunction extends Schema.Class("ShellFunction")({ name: Schema.String, start: Schema.Number, end: Schema.Number, parent: Schema.Option(Schema.Number), closed: Schema.Boolean, }) {}