summaryrefslogtreecommitdiff
path: root/Shell/AST.cpp
AgeCommit message (Collapse)Author
2021-01-03Shell: Move AST::create() into the header and use itAnotherTest
2020-12-30AK+Format: Remove TypeErasedFormatParams& from format function.asynts
2020-12-29Shell: Fix wrong step value for brace rangesAnotherTest
This fixes numeric ranges like {1..10}.
2020-12-29Shell: Add runtime errors and implement break/continueAnotherTest
Such errors are raised when SyntaxError nodes are executed, and are also used for internal control flow. The 'break' and 'continue' commands are currently only allowed inside for loops, and outside function bodies. This also adds a 'loop' keyword for infinite loops.
2020-12-29Shell: Make for/match/functions put their variables only in the new scopeAnotherTest
Otherwise, a function would, for example, overwrite its parent scope: ```sh foo(x) { } x=1 foo 2 # would make x=2 otherwise ```
2020-12-15Shell: Make Subshell actually create a subshellAnotherTest
Previously, a "subshell" would just be executed in the parent shell.
2020-12-08Shell: Replace all dbg()'s with dbgln()AnotherTest
2020-12-08Shell: Make <return> go to a new line when the command is incompleteAnotherTest
"incomplete" meaning that it has a syntax error that can be recovered from by continuing the input.
2020-11-01Shell: Store LocalFrames as NonnullOwnPtr<LocalFrame> insteadAnotherTest
As Vector<T> will relocate objects to resize, we cannot assume that the address of a specific LocalFrame will stay constant, or that the reference will not be dangling to begin with. Fixes an assertion that fires when a frame push causes the Vector to reallocate.
2020-10-29Shell: Allow parts of globs to be named in match expressionsAnotherTest
This patchset allows a match expression to have a list of names for its glob parts, which are assigned to the matched values in the body of the match. For example, ```sh stuff=foobarblahblah/target_{1..30} for $stuff { match $it { */* as (dir sub) { echo "doing things with $sub in $dir" make -C $dir $sub # or whatever... } } } ``` With this, match expressions are now significantly more powerful!
2020-10-29Shell: Add redirections to the formatted command stringAnotherTest
2020-10-29Shell: Rename {source,dest}_fd to {old,new}_fdAnotherTest
This makes `Rewiring' much more understandable, and un-confuses the uses of `dup2()'. Also fixes `dup2()' bugs.
2020-10-26Shell: Implement AK::Formatter::format() for AST::CommandAnotherTest
...and use that to display jobs.
2020-10-25Shell: Add support for brace expansionsAnotherTest
This adds support for (basic) brace expansions with the following syntaxes: - `{expr?,expr?,expr?,...}` which is directly equivalent to `(expr expr expr ...)`, with the missing expressions replaced with an empty string literal. - `{expr..expr}` which is a new range expansion, with two modes: - if both expressions are one unicode code point long, the range is equivalent to the two code points and all code points between the two (numerically). - if both expressions are numeric, the range is equivalent to both numbers, and all numbers between the two. - otherwise, it is equivalent to `(expr expr)`. Closes #3832.
2020-10-04Shell: Fix closest command node detection in Pipes and SequencesAnotherTest
This makes --option completions work for pipes and sequences too.
2020-10-04Shell: Move everything to the Shell namespaceAnotherTest
Also provide a basic default-constructor.
2020-09-30Shell: Track line numbers and the positions of some keywordsAnotherTest
2020-09-26Shell: Rename two 'fd' class members to have an 'm_' prefixAnotherTest
2020-09-26Shell: Use NonnullRefPtr to store non-null subnodesAnotherTest
Also replaces null-is-invalid nodes with syntax error nodes.
2020-09-15Shell: Add 'match' expressionsAnotherTest
This commit adds an equivalent to the sh 'case' construct, except it's much more pleasing to look at and write: ```sh match "$something" { p1 { echo "p1!" } p2 { echo "p2!" } * { echo "string catch-all!" } } ``` is the equivalent of: ```sh case $something in p1) echo "p1!" ;; p2) echo "p2!" ;; *) echo "catch-all!" ;; esac ``` Since our shell does not treat lists as strings, matching lists is also possible: ```sh match (1foo 2foo foo3) { (?foo 2* *) { echo wowzers! } (* * *) { echo 3-element list catch-all } } ```
2020-09-15Shell: Make Node::resolve_as_list(nullptr) resolve to a 'pure' reprAnotherTest
'pure' as in "not requiring a shell", similar to JS::Value::to_string_without_side_effects().
2020-09-15AK: Remove OutputMemoryStream for DuplexMemoryStream.asynts
OutputMemoryStream was originally a proxy for DuplexMemoryStream that did not expose any reading API. Now I need to add another class that is like OutputMemoryStream but only for static buffers. My first idea was to make OutputMemoryStream do that too, but I think it's much better to have a distinct class for that. I originally wanted to call that class FixedOutputMemoryStream but that name is really cumbersome and it's a bit unintuitive because InputMemoryStream is already reading from a fixed buffer. So let's just use DuplexMemoryStream instead of OutputMemoryStream for any dynamic stuff and create a new OutputMemoryStream for static buffers.
2020-09-14Shell: Allow builtins and functions as conditions for 'if'AnotherTest
2020-09-14Shell: Complete named function parameters inside the function bodyAnotherTest
2020-09-14Shell: Add support for functionsAnotherTest
This implementation does not have support for 'return' yet.
2020-09-10Shell: Do not reset the terminal attributes when command is run in bgAnotherTest
Also removes a FIXME that no longer applies.
2020-09-09Shell: Add the (now) free subshell supportAnotherTest
2020-09-09Shell: Allow control structures to appear in pipe sequencesAnotherTest
This makes commands like the following to be possible: ```sh $ ls && for $(seq 10) { echo $it } $ ls | for $(seq 1) { cat > foobar } ```
2020-09-09Shell: Announce job events at the right timesAnotherTest
This fixes a duplicate message when running `jobs` for the first time after a job has been moved to the background. Also actually announces background exits now :^)
2020-09-09Shell: Fix job control and backgroundingAnotherTest
This patchset makes the shell capable of lazily resolving and executing sequences of commands, to allow for putting logical sequences in the background. In particular, it enables And/Or/Sequence nodes to be run in the background, and consequently unmarks them as `would_execute`. Doing so also fixes job control to an extent, as jobs are now capable of having 'tails', so sequences can be put in the background while preserving their following sequences.
2020-09-01AK: Move memory streams into their own header.asynts
2020-08-22Shell: Add 'if' expressionsAnotherTest
```sh if foo bar baz { quux } else if foobar || whatever { echo I ran out of example words } else { exit 2 } ```
2020-08-22Shell: Actually process for loop entries as a streamAnotherTest
This actually does what d4bcc68 meant to do.
2020-08-22Shell: Do not flatten syntactic lists in for_each_entry()AnotherTest
2020-08-22Shell: Mark AST::Background as would_execute if its subnode doesAnotherTest
2020-08-21Shell: Make 'for' loops read their input as an streamAnotherTest
i.e. process an element as it becomes available.
2020-08-19Shell: Name the pipe ends correctlyAnotherTest
2020-08-12Shell: Add create() factory function for PathRedirectionAndreas Kling
2020-08-12Shell: Fix another FdRedirection reference leakAndreas Kling
Add a create() factory function to prevent this from happening again.
2020-08-12Shell: Eliminate reference leak in AST::Execute::run()AnotherTest
2020-08-12Shell: Moves pipelined processes to one process groupAnotherTest
2020-08-10Shell: Cancel a running for loop upon receiving any non-SIGINT signalAnotherTest
And keep the old behaviour of needing two interruptions on SIGINT.
2020-08-09Shell: Stop a for loop upon receiving two consecutive interruptionsAnotherTest
This does not work perfectly (just like every other shell...), if the running program handles the signal (SIGINT in this case) and quits cleanly, the shell cannot detect the interruption. This is the case with our `sleep(1)`.
2020-08-07Shell: Make resolve_without_cast() return NonnullRefPtr<Value>Andreas Kling
2020-08-07Shell: Store ListValue's values in a NonnullRefPtrVector<Value>Andreas Kling
A ListValue never stores null Values, so it makes sense to restrict it. This also propagates use of NonnullRefPtr to the create() helpers. There's a small bit of awkwardness around the use of initializer_list, since we cannot directly construct a NonnullRefPtrVector from one.
2020-08-06Shell: Make run_command() return a NonnullRefPtrVector<Job>Andreas Kling
This never returns null Job pointers.
2020-08-04Shell: Use NonnullRefPtr to simplify some things in the parser/ASTAndreas Kling
2020-08-04Shell: Correct FdRedirection inheriting from two RefCounted basesAnotherTest
Also add missing calls to `adopt()`.
2020-08-04Shell: Add support for ARGV (and $*, $#)AnotherTest
This patchset also adds the 'shift' builtin, as well as the usual tests. closes #2948.
2020-08-04Shell: factor out updating the path cache into a function.Mathieu PATUREL