microsoft/node-jsonc-parser

Question: Why are lineNumbers / column not a part of Node?

helsont opened this issue · 1 comments

I'm looking at both the Monaco Editor's source code, which uses lineNumber and column to describe the position of text data.

However, this json parser keeps track of offset for Nodes.

Is there a specific reason for this? Other parsers like this return the tree with lineNumber and column info too.

The reason is of course to keep the size of the Node as small as possible. That's quite important as parsing big JSON documents can result in a lot of nodes.

For offset to lineNumber/character conversion I always use the TextDocument from the vscode-languageserver-types module: https://github.com/microsoft/vscode-languageserver-node/blob/master/types

Otherwise, I recommend you to use the visit API. The JSONVisitor returns also lineNumber and column.
It's not difficult to build you own node tree using the visitor, see here