Doesnt allow toplevel arrays
bend-n opened this issue · comments
[]
=>
Syntax { line: 1, col: 1, code: UnexpectedChar, at: "[]" }
How exactly do you test ?
This works:
let arr: Vec<u8> = deser_hjson::from_str("[]").unwrap();
assert_eq!(arr, vec![]);
Can you please write a reproducible test ?
So turns out I was trying to parse
[abc, def, hjk]
then did not realize that this was invalid hjson, then tried to find a issue, and deserialized a list into a object.
Hm. In fact I don't see in the Hjson spec anything preventing [abc, def, hjk]
from being valid.
I'll have a look at quoteless strings in arrays.
I would love if that was possible; but it would technically be diverging from the hjson spec, which says quoteless strings carry on until the next line.
So [string]
is invalid, as is {string: string}
Although the hjson does forbid {} in quoteless strings anyways, so maybe you dont break anything by supporting this, just make it a little more convenient.
Yes, reading the spec again, I see it's explicitely forbidden.
As they can't contain any of {}[],:,
I don't see any reason.
I'll probably try to see if that would break anything, and maybe define a feature for a strict mode.
That would be lovely!
If I say that a string value in an array (if not at the start of the line) may be quoteless but stops at the first comma, ']' or LF, then we can have [abc, def, hjk]
.
But there's a problem.
Some Hjson which was valid before, starts to be either invalid or to have another meaning.
See this exemple, valid with the official Hjson specification and the released deser_hjson:
let arr: Vec<String> = deser_hjson::from_str(r#"
[a, 3]
]
"#
).unwrap();
assert_eq!(arr, vec!["a, 3]"]);
According to the spec, the first element is recognized as a quoteless string. Which means it goes till the LF.
So the first and only element of the array is "a, 3]"
...
IMO the Hjson specification isn't good there, but departing from it without an official change would break too much.