sum01 / cmdlog-micro

An integrated terminal plugin for the Micro text-editor
GNU General Public License v3.0
1 stars 0 forks source link

Correctly parse strings #3

Open sum01 opened 6 years ago

sum01 commented 6 years ago

Things like runit "git commit -m 'example'" don't currently work, but should.

sum01 commented 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).

ghost commented 6 years ago

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
        }
    }
}
sum01 commented 6 years ago

I fixed the unordered execution with a global var that holds the commands, and running them off of the JobSpawn's onExit call.

sum01 commented 6 years ago

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.

ghost commented 6 years ago

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!

sum01 commented 6 years ago

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...