summaryrefslogtreecommitdiffstats
path: root/src/poem/read.rs
Commit message (Collapse)AuthorAgeFilesLines
* Refactor Verse::clause()Rory Dudley2024-09-021-4/+2
| | | | | | | | There is no reason to return an option for clause(), since it makes us perform a match twice, and since a blank vector is perfectly acceptable in all cases where the verse at hand may not have a clause. Signed-off-by: Rory Dudley <rory@netc.lu>
* Allow escaping charactersRory Dudley2024-09-021-0/+9
| | | | | | | This patch adds the '\' character as a new rune, Rune::Special. This is for escaping special characters. Also works in strings (", '). Signed-off-by: Rory Dudley <rory@netc.lu>
* Fix a bug with channelsRory Dudley2024-07-081-2/+8
| | | | | | | | | When using IO operations from within a file, the channel would get overriden before pushing a filename to the appropriate vector (op, ep, or both). This is because Rune::Continue is used for newlines, and was resetting the channel to None, before the push operation. Rune::Continue is now broken out into its own match clause, that doesn't set the channel before calling verse.add().
* Add/update doc commentsRory Dudley2024-06-301-6/+33
| | | | | This patch update a ton of the documentation comments throughout the codebase, refactoring some areas, and adding new comments to others.
* Updated the way built-in commands are called/usedRory Dudley2024-06-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, built-in commands were fairly primitive, merely outputting STDOUT and STDERR with the print! macros. However, we need them to behave like normal programs, that is: - Acknowledge their verse's meter (forking, piping, etc.), - Ability to capture STDOUT and STDERR (>, 2>), - and Affect the currently running environment. For these reasons, the anthology was reworked, and now contains the Anthology struct, which mimics both std::process::{Child, Command}. The AnthologyStdin helper struct was also created, for built-ins to take input on STDIN, though no built-in is currently using it. Each built-ins' incant functions were updated to return a std::process::Output. It contains output from STDOUT, output from STDERR, and the exit code of the "process". A fix was also implemented for aliases, where the STDOUT and STDERR vectors were not being copied to the newly constructed verse. Notes: There is some cleanup that needs to happen on this patch. For one, the spellcheck function is no longer being used, so there is a generic OS error if the program cannot be found in the $PATH. Also, anthology::lookup gets called twice, which shouldn't need to happen.
* Update doc comments for Poem::read functionsRory Dudley2024-05-201-3/+16
| | | | | Update documentation comments for the Poem::read() function, as well as the Poem::add() function (which is crucial for read()).
* Allow aliases with the same name as their verbRory Dudley2024-05-201-7/+17
| | | | | | | | | | | | | | | | | Previously, when trying to add an alias that used the same name as its command, an infinite recursion loop would occur, and the program would panic after the call stack got too deep. For instance, something like: alias grep='grep --color=always' would cause it to panic. This patch adds a new field to the Environment struct called 'cs' (for call stack), which can be used to keep track of how many levels deep into the Poem::read() function we are in. At the moment, it only allows going two levels deep, but since it's just a u8 value, this could be increased in the future. The above example now works correctly, but it does mean that aliases within aliases are not possible, currently.
* Handle STDERR, in addition to STDOUTRory Dudley2024-05-191-34/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch overhauls the reading and reciting of verses, such that the redirection of STDERR (in addition to STDOUT, which was already a feature), is now possible. Removed the 'stdout' argument from recite(), since it is no longer needed with how incantations function. A verse's couplet indicator is now a u8, instead of a bool, with certain values corresponding to types of couplets, for instance: ls | grep Ca | lolcat ^ ^ ^ | | 2: right side of a couplet | 3: both sides of a couplet 1: left side of a couplet Incantions are no longer hanlded in rune.rs, and the task macros have been removed. Now, a verse incants itself, matching on its own meter to determine how to handle the next verse. The following runes were added to help with handling STDERR: Write2 -> 2> WriteAll -> &> Addendum2 -> 2>> AddendumAll -> &>> The 'io' field in verse was changed from an Option<Rune>, to an array of Runes, since a single verse might have multiple IO operations. The following fields were added to Verse, to assist with handling STDERR: ip -> List of filenames to read into STDIN op -> List of filenames to send STDOUT to ep -> List of filenames to send STDERR to Keep track of channels when reading a poem. Channels are relating to IO operations. If channel is None, words get pushed to the verse's primary stanza (i.e. the verb or the clause). If a channel is selected, words are pushed to one of the aforementioned new fields in Verse. Read -> ip Write/Addedum -> op Write2/Addedum2 -> ep WriteAll/AddendumAll -> op and ep Notes: This commit also added tests for the new Runes.
* Rewrite of the next! macroRory Dudley2024-05-171-3/+4
| | | | | | | This patch replaces the next! macro with a next() function. It serves the same purpose, but instead of only checking for two different runes (a fallback, or one that matches the peek), it can now take a list of runes/characters to look ahead for, in addition to the fallback.
* Remove a println!()Rory Dudley2024-05-161-1/+0
| | | | | Removed a println!() that was used for debugging, and was accidentally left in.
* Fix another another regression with aliasesRory Dudley2024-05-131-1/+4
| | | | | | For aliases, only set couplet for the last verse, if the original verse has its couplet set. Otherwise, the alias could have trouble with piping.
* Fix another regression with aliasesRory Dudley2024-05-131-17/+11
| | | | | | | | The last commit (1415c8f9b89699000ef8d864ff8f0e1bebca4a5f) fixed the issue with pipes, however, it did not fix it for IO. This patch adds some logic for the aliased verse to inherit the properties of the original verse, so that recite works properly for all verse types (regardless of IO, couplet, or meter).
* Fix regression with aliasesRory Dudley2024-05-121-14/+65
| | | | | | | | | Fixed a regression that was introduced in: 1415c8f9b89699000ef8d864ff8f0e1bebca4a5f. Moving aliases to read() broke how pipes worked. This commit removes the troublesome append!() macro, and replaces it with some logic in the add() function (impl Appendable for Poem).
* Add 'strings' to the verse after the string!() macroRory Dudley2024-04-061-0/+4
| | | | | | This patches fixes a bug, where sometimes, when a Rune::String was detected, the resulting string from the string!() macro wasn't getting pushed to the current verse.
* Handle aliases in read()Rory Dudley2024-04-041-13/+21
| | | | | | Instead of handling aliases in the recite() function, which requires two loops to handle properly with the current implementation, offload checking for aliases to the read() function.
* Add comments (`#`) to the parserRory Dudley2024-03-281-1/+6
| | | | | The parser will now interpret the '#' character as a single-line comment string, which works on it's own line, or at the end of an existing line.
* Remove defunct code from read() and recite()Rory Dudley2024-03-241-13/+0
| | | | | Remove some commented out code, that is no longer needed after the parser overhaul.
* read() and recite() overhaulRory Dudley2024-03-231-0/+261
Rebuilt the LR parser (i.e. read()) from the ground up. This required that some changes be made to recite(), in order to accomodate the new data structures. These data structures were each split out into their own file, in order to make working with each component a bit easier. In addition to reworking the parts of the parser already present, some new features were also added, such as: - Support for strings (' and ") - Support for environment variables ($) - Support for interpreting tild as $HOME (~) - Support for sub-reading and sub-reciting (`) Notes: This is a huge commit that changes almost the entire program (main.rs is still the same, except for imports). Ideally, huge sweeping changes like this should not occur on the codebase, but since this is still pre-alpha, I guess this is acceptable. This is far from the end of patch set, however, as there is quite a lot of cleanup that needs to be done. For instance, checking for internal poems and environment variables should get split out to their own functions/macros. There is also some defunct code (that's commented out), that is unlikely to be useful in the future.