summaryrefslogtreecommitdiff
path: root/Userland/Shell/Parser.cpp
AgeCommit message (Collapse)Author
2021-06-12AK: Rename Vector::append(Vector) => Vector::extend(Vector)Andreas Kling
Let's make it a bit more clear when we're appending the elements from one vector to the end of another vector.
2021-05-24AK+Everywhere: Consolidate String::index_of() and String::find()Andreas Kling
We had two functions for doing mostly the same thing. Combine both of them into String::find() and use that everywhere. Also add some tests to cover basic behavior.
2021-05-19Shell: Avoid moving AK::Function instances while inside themAli Mohammad Pur
2021-05-10Shell: Parse '\t' in doublequoted strings as a tab characterAli Mohammad Pur
This not being recognised is surprising.
2021-05-10Shell: Add support for \uhhhhhhhh escapes in stringsAli Mohammad Pur
This will be replaced with the unicode character whose codepoint is given by the unsigned 32-bit number 'hhhhhhhh' (hex).
2021-05-01Shell: Move the heredocs vector to a local value before processing itAli Mohammad Pur
Otherwise we would end up trying to parse the same heredoc entry, if it contained a sequence terminated by a newline. e.g. `<<-x\n$({` would attempt to read a heredoc entry after `x`, and then after `{` while inside the first heredoc entry. To make this work, we can simply empty the instance vector and keep the state on the stack. Issue found through oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33852
2021-05-01Shell: Disallow non-bareword nodes as part of a heredoc keyAli Mohammad Pur
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33854
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: Avoid position push/pop when checking for next_is()Ali Mohammad Pur
This operation is not a rule and cannot produce nodes.
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-04-21Shell: Convert String::format() => String::formatted()Andreas Kling
2021-04-08Shell: Allow newlines between the function decl and its bodyAnotherTest
All other control structures are fine with this, so let's keep the behaviour consistent.
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-17Everywhere: Remove pessimizing and redundant move()Andreas Kling
2021-03-15Shell: Consume the username when parsing '~user'AnotherTest
Otherwise it will stay there and be parsed as a juxtaposition. Fixes #5798.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
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-07Shell: Do not parse history events in scriptsAnotherTest
That makes no sense!
2021-02-26Everywhere: Remove a bunch of redundant 'AK::' namespace prefixesLinus Groh
This is basically just for consistency, it's quite strange to see multiple AK container types next to each other, some with and some without the namespace prefix - we're 'using AK::Foo;' a lot and should leverage that. :^)
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-07Shell: Make history index values not fitting in i32 a syntax errorAnotherTest
A continuation of e3ec759. Also found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=30405
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-18Shell: Allow newlines between `else` and `if`'s closing braceAnotherTest
This is more flexible and intuitive. Fixes #4992.
2021-01-15Shell: Add (basic) support for history event designatorsAnotherTest
Closes #4888
2021-01-12Shell: Move to Userland/Shell/Andreas Kling