column info seems to be off
Opened this issue · 3 comments
corno commented
I get unexpected column values when parsing a JSON file.
Have a look at the following code.
For example: I expect value 3 to have a column value of 78, but the tool reports 65
import * as c from "clarinet"
const { Readable } = require('stream')
// 1 2 3 4 5 6 7 8
//.4.6.8.0.2.4.6.8.0.2.4.6.8.0.2.4.6.8.0.2.4.6.8.0.2.4.6.8.0.2.4.6.8.0.2.4.6.8.0
const readable = Readable.from([`{
"a0": "x",
"b0": "x", "b1": 0, "b2": "", "b3": "", "b4": "", "b5": 1, "b6": 2, "b7": 3
}`])
var parse_stream = c.createStream()
parse_stream.on('openobject', function (name: string) {
console.log("openobj", name, "*", `${parse_stream._parser.line}:${parse_stream._parser.column}`, parse_stream._parser.position)
});
parse_stream.on('key', function (name: string) {
console.log("key", name, "*", `${parse_stream._parser.line}:${parse_stream._parser.column}`, parse_stream._parser.position)
});
parse_stream.on('string', function (name: string) {
console.log("string", name, "*", `${parse_stream._parser.line}:${parse_stream._parser.column}`, parse_stream._parser.position)
});
parse_stream.on('value', function (value: string) {
console.log("value", value, "*", `${parse_stream._parser.line}:${parse_stream._parser.column}`, parse_stream._parser.position)
});
// parse_stream.on('end', function () {
// console.log("nu end", `${parse_stream._parser.line}:${parse_stream._parser.column}`, parse_stream._parser.position)
// });
readable.pipe(parse_stream);
/*
output:
openobj a0 * 2:6 10
value x * 2:10 15
key b0 * 3:6 24
value x * 3:10 29
key b1 * 3:14 35
value 0 * 3:17 38
key b2 * 3:22 45
value * 3:26 49
key b3 * 3:30 55
value * 3:34 59
key b4 * 3:38 65
value * 3:42 69
key b5 * 3:46 75
value 1 * 3:49 78
key b6 * 3:54 85
value 2 * 3:57 88
key b7 * 3:62 95
value 3 * 3:65 98
*/
corno commented
I have decided to fork clarinet into 'bass-clarinet' (the name 'Oboe' was already taken, so that does not leave a lot of instruments left :) )
In that fork I fixed the issue
BrightSoul commented
The position
property is also wrong. It seems to be off by 1 character for each previously closed object.
e.g.
{
"a": { "value": 1 }, //Correct here
"b": { "value": 2 }, //Off by 1 here
"c": { "value": 3 } //Off by 2 here
}
@corno Can you please pinpoint the fix in your fork so I can send a pull request to this repo? Thanks.
corno commented
@BrightSoul please have a look at the following commits:
18a9368
27857cf
(but I guess that you tried out my package, so maybe this is not relevant anymore)