shashi / FileTrees.jl

Parallel computing with a tree of files metaphor
http://shashi.biz/FileTrees.jl
Other
88 stars 6 forks source link

parse multiline tree string? #78

Closed bdklahn closed 10 months ago

bdklahn commented 10 months ago

This is a nice/handy library. Thanks!

Might it be nice to be able to parse the output of Base.show(tree) back into a tree. If, for example, one wants to store a "tree literal" as a string, I think this . . .

tree_string = """
    mydir/
    ├─ foo/
    │  └─ baz
    └─ bar
    """

tree1 = parse_tree_string(tree_string)

. . . might look cleaner than . . .

tree1 = maketree(
    "mydir" => [
        "foo" => [
            "baz"
            ],
        "bar"
        ]
    )

Maybe it could also be implemented as a Non-standard String Literal? https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals.

-just a thought. Thanks!

shashi commented 10 months ago

Looks cleaner, but much harder to type :)

This could be a nice helper package/gist, and not a feature that needs to go into this package.

bdklahn commented 10 months ago

Looks cleaner, but much harder to type :)

This is true. I guess I was thinking it could maybe be generated from some example instantiated tree, not by hand. I mean . . . Julia is a programming language, not a text editor, right? Again, it looks like the Base.show() already outputs a string, in that format. Also, the *nix tree command (mostly) already outputs into that format. It would just be a matter of completing that "round-trip"

This could be a nice helper package/gist, and not a feature that needs to go into this package.

That's true. And this is not central to the core functionality of this (but neither is that implementation of Base.show(), in here). A gist is not really meant to be repackaged, and used. It is more to provide example code for reusable artifacts. So, I suppose, a helper package could be created. I guess it might be one file, with one function, like the following.

macro filetree_str(s)
    # parse multiline string s
    # construct FileTree
end

But, I guess, the Base.show() display's something a little more complex, which would have to be dealt with, etc.

So, yeah, this might not be worth it, given it might not even get much use.

I was just wondering about it.

Feel free to close this issue.