summaryrefslogtreecommitdiff
path: root/Userland/Shell/AST.h
AgeCommit message (Collapse)Author
2022-07-04Shell: Immediately resolve value when setting a variableAli Mohammad Pur
The lazy resolution mechanism made it so that the variables were linked together, causing unexpected behaviour: true x=$? # expected: x=0 false echo $x # expected: 0, actual: 1
2022-04-18Shell: Add support for regex match patternsAli Mohammad Pur
We previously allowed globs as match pattern, but for more complex matching needs, it's nice to have regular expressions. And as the existing "name a part of the match" concept maps nicely to named capture groups, we can simply reuse the same code and make groups with names available in the match body.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-26Shell: Implement program-aware autocompletionAli Mohammad Pur
A program can either respond to `--complete -- some args to complete` directly, or add a `_complete_<program name>` invokable (i.e. shell function, or just a plain binary in PATH) that completes the given command and lists the completions on stdout. Should such a completion fail or yield no results, we'll fall back to the previous completion algorithm.
2022-03-24Shell: Use default constructors/destructorsLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-06Shell: Implement leftmost_trivial_literal() for Sequence nodesAli Mohammad Pur
2022-03-06Shell: Allow completing StringLiterals as pathsAli Mohammad Pur
This auto-escapes the token as well :^)
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-08Shell: Replace Result<T, E> use with ErrorOr<T>Andreas Kling
2021-09-16Shell: Use default instead of an empty constructor/destructorBrian Gianforcaro
Default implementations allow for more optimizations. See: https://pvs-studio.com/en/docs/warnings/v832/
2021-09-03AK: Rename create<T> => make_ref_counted<T>Andreas Kling
And also try_create<T> => try_make_ref_counted<T>. A global "create" was a bit much. The new name matches make<T> better, which we've used for making single-owner objects since forever.
2021-08-02Shell: Improve the parsing of history event designatorsTheFightingCatfish
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-16Shell: Remove unused InlineLinkedList header includeBrian Gianforcaro
2021-06-13Userland: Allow building SerenityOS with -funsigned-charGunnar Beutner
Some of the code assumed that chars were always signed while that is not the case on ARM hosts. Also, some of the code tried to use EOF (-1) in a way similar to what fgetc() does, however instead of storing the characters in an int variable a char was used. While this seemed to work it also meant that character 0xFF would be incorrectly seen as an end-of-file. Careful reading of fgetc() reveals that fgetc() stores character data in an int where valid characters are in the range of 0-255 and the EOF value is explicitly outside of that range (usually -1).
2021-05-01Shell: Make set_is_syntax_error() also copy the error locationAli Mohammad Pur
2021-04-29Shell: Add support for heredocsAli Mohammad Pur
Closes #4283. Heredocs are implemented in a way that makes them feel more like a string (and not a weird redirection, a la bash). There are two tunables, whether the string is dedented (`<<-` vs `<<~`) and whether it allows interpolation (quoted key vs not). To the familiar people, this is how Ruby handles them, and I feel is the most elegant heredoc syntax. Unlike the oddjob that is bash, heredocs are treated exactly as normal strings, and can be used _anywhere_ where a string can be used. They are *required* to appear in the same order as used after a newline is seen when parsing the sequence that the heredoc is used in. For instance: ```sh echo <<-doc1 <<-doc2 | blah blah contents for doc1 doc1 contents for doc2 doc2 ``` The typical nice errors are also implemented :^)
2021-04-29Shell: Allow Syntax errors to be mutated while parsingAli Mohammad Pur
Some nodes (such as heredocs) cannot be validated immediately, so the entire tree will need to be revalidated if we don't allow mutating syntax errors.
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-22Shell: Add support for indexing into variablesAnotherTest
Now a variable may have an optional slice (only _one_ slice), which can also use negative indices to index from the end. This works on both lists and strings. The contents of the slice have the same semantics as brace expansions. For example: ```sh $ x=(1 2 3 4 5 6) $ echo $x[1..3] # select indices 1, 2, 3 2 3 4 $ echo $x[3,4,1,0] # select indices 3, 4, 1, 0 (in that order) 4 5 2 1 $ x="Well Hello Friends!" $ echo $x[5..9] Hello ```
2021-03-07Shell: Add support for enumerating lists in for loopsAnotherTest
With some odd syntax to boot: ```sh $ for index i x in $whatever {} ```
2021-03-07Shell: Add support for 'immediate' expressions as variable substitutionsAnotherTest
This commit adds a few basic variable substitution operations: - length Find the length of a string or a list - length_across Find the lengths of things inside a list - remove_{suffix,prefix} Remove a suffix or a prefix from all the passed values - regex_replace Replace all matches of a given regex with a given template - split Split the given string with the given delimiter (or to its code points if the delimiter is empty) - concat_lists concatenates any given lists into one Closes #4316 (the ancient version of this same feature)
2021-03-04Shell: Make Node::hit_test_position() constAnotherTest
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-03Shell: Make history range values larger than u32 a syntax errorAnotherTest
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29792&sort=reported&q=serenity
2021-01-23Shell: Make the parser read consecutive sequences without recursingAnotherTest
This fixes (the easy) part of #4976.
2021-01-19Shell: Make 'if' expressions return the unevaluated value of blocksAnotherTest
This makes it possible to actually put them in a sequence and cast them to commands.
2021-01-19Shell: Mark control structures to be executed in the current processAnotherTest
2021-01-19Shell: Implement `for_each_entry()` for syntactic list nodesAnotherTest
This allows correct iteration over nested lists. Also store values to variables without resolving them, to delay the resolution step as much as possible (this helps with storing nested lists in variables).
2021-01-15Shell: Add (basic) support for history event designatorsAnotherTest
Closes #4888
2021-01-12Shell: Move to Userland/Shell/Andreas Kling