Last active
January 25, 2026 22:19
-
-
Save lucassha/3387ec8bd1da3140bc1d1400c9173b97 to your computer and use it in GitHub Desktop.
tracing parse_input logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| echo hi > file & | |
| START: | |
| start = 0 | |
| arguments = 1 | |
| last_char_valid updated to 1 | |
| ... space found (echo ) | |
| start = 0 | |
| end = 4 (index where ' ' is) | |
| last_char_valid updated to 0 | |
| ... next word started (echo hi) | |
| arguments = 2 | |
| last_char_valid updated to 1 | |
| ... space found (echo hi ) | |
| end = 7 | |
| last_char_valid updated to 1 | |
| ... redirect found (echo hi >) | |
| # check if redirect is > start (it is not because it's been set to 0 to start with) | |
| redirect = 8 | |
| last_char_valid stays at 1 | |
| ... space found (echo hi > ) | |
| end = 9 | |
| last_char_valid updated to 0 | |
| ... next word started (echo hi > file) | |
| arguments = 3 | |
| last_char_valid updated to 1 | |
| ... space found (echo hi > file ) | |
| end = 14 | |
| last_char_valid updated to 0 | |
| ... ampersand pid found (echo hi > file &) | |
| # last_char_valid == 0 so end not set | |
| # output_len = [end - redirect] == [14 - 8] | |
| output_len = 6 | |
| # output[0] == input[8] and so on | |
| i = 9, j = 0 | |
| output[] = " file\0" | |
| end = 8 | |
| # command_len = 8 - 0 + 9 | |
| command_len = 7 | |
| command = "echo hi\0" | |
| command_args = [echo, hi] | |
| output_tokens = [file] | |
| # everything resets and start again |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment