Hello all!
I am writing a function to tokenize a shell command as a string and tokenize it into the commad and its args.
For example:
Input: "sh -c \"while sleep 1; do echo \\\"${RANDOM}\\\"; done\""
Output: ["sh", "-c", "while sleep 1; do echo \"${RANDOM}\"; done"]
This is what I've come up with. Its a direct conversion of https://sourceforge.net/p/drjava/git_repo/ci/master/tree/drjava/src/edu/rice/cs/util/ArgumentTokenizer.java#l70
Need help in the follwing areas:
- How to collect the recur
s into a single recur
- Making it more idiomatic
- General feedback and improvements
All help is much appreciated! 😄
finite state transducer + reduce
which may or may not help, maybe look at automat
or maybe replace it with a regex