6 ms·
Take the JSON encoding example. How does it know that 802 is a number? What if I want to have "802" as a string? Is it because visitors.mozilla has a fixed sche
by zimbatm 9y ago
Take the JSON encoding example. How does it know that 802 is a number? What if I want to have "802" as a string? Is it because visitors.mozilla has a fixed schema that it's value is an int or does it try to parse the string as an int first and then bails off back to a string if it doesn't work?
- drostie 9y agoIt's the latter. The JSON encoding example is actually a really bad example for this language because there is a huge class of JSON which it cannot easily be seen to encode, though you can probably make some exceptions. An example of the many undefined things would be: {"abc def": ["123 456", 789, 101112, null, false]} A better DSL for JSON would have to include actual data types or so, obj abc def arr str 123 456 num 789 num 101112 null bool f ...or so.
- breck 9y agoThe paper takes the example from jsonETN. The first letter is the data type. s: StringNode n: NumberNode a: ArrayNode o: ObjectNode b: BooleanNode j: OtherNode I just posted the repo here if you're curious. https://github.com/breck7/jsonetn https://github.com/breck7/jsonetn It used to pass every test, but I haven't touched it in a while and seems like a few lines need to be updated to bring it up to date with TN 4.0 (it's on 3.8 now). Handles the tricky JSON edge cases fine. It would be great if someone wanted to maintain a solid JsonETN! I'm on to the Turing Complete ETNs nowadays, but a JSON ETN would be great and would let you use ETN tools to work with JSON. Package.json for NPM should eventually switch to an ETN. Would provide noticeable benefits.
- breck 9y agoI do like the 3 letter word better than my 1 letter word. Nice job!
- breck 9y agoIn the jsonETN I whipped up, the first word indicates the node type. n is number, s is string. Seemed good enough. Probably could be a better ETN for JSON if someone wants to give it a whirl. (For reference; https://github.com/breck7/jsonetn https://github.com/breck7/jsonetn)
- zimbatm 9y agosince each line is parsed a second time, couldn't you take yaml's approach to value encoding and asking ambiguous strings to be quoted?