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

column info seems to be off #68

Open
corno opened this issue Feb 3, 2020 · 3 comments
Open

column info seems to be off #68

corno opened this issue Feb 3, 2020 · 3 comments

Comments

@corno
Copy link

corno commented Feb 3, 2020

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
Copy link
Author

corno commented Feb 4, 2020

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
Copy link

BrightSoul commented Oct 7, 2020

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
Copy link
Author

corno commented Oct 11, 2020

@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)

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

2 participants