Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually parse sed scripts #424

Merged
merged 10 commits into from
Jun 3, 2024
Merged

Actually parse sed scripts #424

merged 10 commits into from
Jun 3, 2024

Conversation

AtkinsSJ
Copy link
Collaborator

@AtkinsSJ AtkinsSJ commented May 24, 2024

Finally, sed is actually useful! 🎉

In the end, I did manage to parse things like the s and y commands using the grammar DSL instead of a custom Parser class for them. For s it's about half as much code, too. Pretty nice! Thought that's not including the code for the DelimiterParser.

@AtkinsSJ AtkinsSJ force-pushed the sed branch 3 times, most recently from 831cc4e to d230460 Compare May 31, 2024 14:19
@AtkinsSJ AtkinsSJ changed the title WIP: Actually parse sed scripts Actually parse sed scripts May 31, 2024
I've found this useful for stubbing out parts of a grammar during
development.
The counterpart of stringOf(), it reads characters until it matches its
parameter.
Let's organise this a bit.
This is ported over from an old forgotten branch I'd deleted, then
thankfully managed to dig up again. 😅

Instead of making GroupCommand contain child commands, use a flat array
for commands and implement groups as GroupStartCommand and
GroupEndCommand. This makes it much simpler to iterate the commands
list in order to jump to labels.

Then implement those labels and the commands that use them: b, t, and T.

Also add the s SubstituteCommand, and combine the code for the q and Q
commands.
Some shell apps care about what order the arguments appear in. When
`parseArgs()` is called with `tokens: true`, it produces this `tokens`
array which represents all the command line options and arguments, in
order, which is useful for these more advanced cases.
Sed is now finally able to actually run scripts, instead of ignoring all
input and running a hard-coded test script!
These make more sense combined into one Command which is controlled by
constructor parameters:

- b, t and T
- d and D
- g and G
- h and H
- p and P
@AtkinsSJ AtkinsSJ marked this pull request as ready for review May 31, 2024 14:49
@AtkinsSJ
Copy link
Collaborator Author

I think this is ready now. sed still has some missing features, but the majority of it is there.

@KernelDeimos KernelDeimos merged commit 2a2a42c into HeyPuter:main Jun 3, 2024
6 checks passed
@AtkinsSJ AtkinsSJ deleted the sed branch June 4, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants