Open sum01 opened 6 years ago
Lua pattern matching is kind of weak, so I'm trying to implement Go's regexp
package. Problem is that FindAllString
is (incorrectly) asking for 3 input's, when the docs show it as only needing two (the input string and an int).
Wasn't JobSpawn not working anyway because of unordered execution?
Otherwise, should runit "git commit -m 'example'"
separate into 1. runit
2. git
3.commit -m
4. example
?
If so I think something like this would be easier but I may have missed the point of the regex
fun (input String){
// 1. strip `runit` somehow, then
while input{
i = 0
while (input[i] != " " && input[i] != "-") i++ {
if inout[i] == "-" {
i++
if input[i] == "-"; i++ // case "--option"
while input[i] alphanumeric; i++ // match the "option"
}
input = substring 0 .. i of input and add as an option
}
}
}
I fixed the unordered execution with a global var that holds the commands, and running them off of the JobSpawn's onExit
call.
But because of how JobSpawn passes args, the entire string 'example'
needs to be passed as a single arg for it to work, which requires doing regex like ([^\'"%s]+|\'.*\'|".*")
. I just can't get Go's FindAllString working, when I see nothing wrong with what I'm trying.
my point was just that it may be easier to use some homebrewed loop logic instead of digging through regex issues of any sort but your opinion may differ 😄
Good to know you found a way to sort out the ordering!
So I kind of found something that works, but I need to look into it more. Something like
local golib_regexp = import("regexp")
local regex_matches = golib_regexp.MustCompile('([^\'"\\s]+|\'.*\'|".*")'):FindAllString(input, -1)
returns something similar to what I want, but it's not there yet. But at least the import actually works, it's just sort of in a weird format compared to the Go docs.
edit: So it's returning a userdata
type, which isn't (easily) usable in Lua. I have the feeling that this just isn't implemented the way I need it in Micro itself...
Things like
runit "git commit -m 'example'"
don't currently work, but should.