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

structured data #155

Open
errordeveloper opened this issue Jan 9, 2017 · 6 comments
Open

structured data #155

errordeveloper opened this issue Jan 9, 2017 · 6 comments

Comments

@errordeveloper
Copy link

errordeveloper commented Jan 9, 2017

One of the major downsides of traditional shells is the lack of direct support for any of well-known structured data formats (e.g. JSON, YAML, or even XML example). As a modern implementation, Nash seems to be well positioned to implement support for such a data format, namely it'd be a great win if there was a way to read, modify, query and compose JSON in a syntactically meaningful way.

@i4ki
Copy link
Collaborator

i4ki commented Jan 11, 2017

I agree with you that it would be very nice to work with such data structures in a meaningful way in nash scripts (without external tools like jq), but I'm not sure this will ever happen... I'm not against someone implementing this as long as it's not built in. Nash libraries could be created for that and we can ship this nashscript libraries alongside nash, but it'll not be easy to develop with current nash, mostly because nash language is very minimal and this data formats are pretty complex. You may think that json is simple, but not so much for a language that only has string, list and function as data types. JSON is achievable, but YAML and XML are definitely very very hard (if not impossible to do).

For example, nash doesn't have an hash table data structure, nor the concept of objects/structs, then the json/yaml/etc must be parsed into a list representing an object. A list is a powerful data structure that you can store almost everything, but a tree/object or a hash table is very inefficient and hard to work with on top of it. Schemers (r5rs ones) create such libraries this way, but it sucks.

As I do think this would be great, we can discuss improvements in nash supported data structures and syntax-constructs to easy creating that in the future (if more people involved see value, of course). Adding a hash table data type is something I'm thinking for a long time, but adding other types as integers, floats, and so on, bring some interesting trade offs.
@katcipis @geyslan @vitorarins @lborguetti

Apart from that, there are one missing features in nash to enable creating such libraries in scripts. A typeof-like built in function must be created, it will be needed to marshal the list (representing a tree) into a string (json output for example).

An external tool can be used to generate the lexical tokens of the input, but even the lexer could be done in nash script if we add support to range over the characters/runes of a string in a for-loop.

I do use json on some of my scripts, but they rely on jq. Jq supports some dynamic way to compose json, but it sucks...

@geyslan
Copy link

geyslan commented Jan 11, 2017

@tiago4orion, do you mean a proper hash table or an abstract map implementation?

@i4ki
Copy link
Collaborator

i4ki commented Jan 11, 2017

I meant a built in abstract map implementation because a hash table implemented in shell should be a disaster (in terms of performance).

@vitorarins
Copy link
Member

IMO JSON/Yaml handling would add a considerable amount of complexity to nash. I agree that in some cases would be nice to have a simple way to generate JSON files, I just don't think it's a good idea to make this a built in feature for nash.

@errordeveloper
Copy link
Author

errordeveloper commented Jan 12, 2017 via email

@katcipis
Copy link
Member

katcipis commented Apr 1, 2017

Added #202

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

No branches or pull requests

5 participants