Zig implementation progress/thoughts
See original GitHub issueI’ll comment out the pointer to zig-nestedtext for now. Let me know when it is ready.
_Originally posted by @KenKundert in https://github.com/KenKundert/nestedtext/issues/20#issuecomment-787214182_
@KenKundert zig-nestedtext is looking pretty good now, I think it’s handling everything in the spec except for quotes around object keys (and the error reporting is extremely minimal). My next job will be to hook it up to your suite of testcases to iron out these remaining bits.
The main aspect of the language spec I’m questioning at this point is the fact that keys may be quoted - is there really a need to allow keys to start with -
or >
, or contain :
or whitespace? This feels like unnecessary complexity for a language spec that strives to be simple, and indeed leads to more than two thirds of the text in the file format spec for dictionary lines:
The key must be quoted if it:
- starts with a list-item or string-item tag,
- contains a dict-item tag,
- starts with a quote character, or
- has leading or trailing spaces or tabs.
A key is quoted by delimiting it with matching single or double quote characters, which are discarded. Unlike traditional programming languages, a quoted key delimited with single quote characters may contain additional single quote characters. Similarly, a quoted key delimited with double quote characters may contain additional double quote characters. Also, backslash is not used as an escape character; backslash has no special meaning anywhere in NestedText.
A quoted key starts with the leading quote character and ends when the matching quote character is found along with a trailing colon (there may be white space between the closing quote and the colon). A key is invalid if it contains two or more instances of a quote character separated from :␣ by zero or more space characters where the quote character in one is a single quote and the quote character in another is the double quote. In this case the key cannot be quoted with either character so that the separator from the key and value can be identified unambiguously.
Here’s an example of it working (modulo spaces in object keys and object field ordering):
$./zig-cache/bin/nt-cli -f samples/employees.nt | jq
{
"treasurer": [
{
"email": "fumiko.purvis@hotmail.com",
"name": "Fumiko Purvis",
"address": "3636 Buffalo Ave\nTopeka, Kansas 20692\n",
"phone": "1-268-555-0280",
"additional-roles": [
"accounting task force"
]
},
{
"email": "merrill.eldridge@yahoo.com",
"name": "Merrill Eldridge",
"phone": "1-268-555-3602"
}
],
"vice-president": {
"email": "margaret.hodge@ku.edu",
"name": "Margaret Hodge",
"address": "2586 Marigold Lane\nTopeka, Kansas 20682\n",
"phone": "1-470-555-0398",
"additional-roles": [
"new membership task force",
"accounting task force"
]
},
"president": {
"email": "KateMcD@aol.com",
"name": "Katheryn McDaniel",
"address": "138 Almond Street\nTopeka, Kansas 20697\n",
"phone": {
"cell": "1-210-555-5297",
"home": "1-210-555-8470"
},
"additional-roles": [
"board member"
]
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (8 by maintainers)
First, on multiline strings
becomes “Hey now!”, whereas
becomes “Hey now!\n”
See https://github.com/KenKundert/nestedtext/issues/16#issuecomment-718904027: