syntax-tree / unist

Universal Syntax Tree used by @unifiedjs
https://unifiedjs.com
875 stars 19 forks source link

`line`, `column`, and `offset` in `point` underspecified #20

Closed brainkim closed 6 years ago

brainkim commented 6 years ago

According to docs:

The end field of Position represents the place of the first character after the parsed source region.

If the last parsed character is a newline, does end have a column of 0 and a line of current line + 1? If we are at the end of the source, does the end position represent an imaginary character after the end of the document?

wooorm commented 6 years ago

For the string \n, and if the newline was present in a syntax tree, if would have {start: {line: 1, column: 1, offset: 0}, end: {line: 2, column: 1, offset: 1}}

does end have a column of 0

No, as a line starts at column: 1

a line of current line + 1

Yes

If we are at the end of the source, does the end position represent an imaginary character after the end of the document?

Yes, I took this wording from estree. What wording do you suggest?

brainkim commented 6 years ago

Hmm. I guess adding these additional qualifications for these two cases would be nice. Something like:

The start field of Position represents the place of the first character of the parsed source region. The end field of Position represents the place of the first character after the parsed source region. (If the parsed source region ends in a newline character, the end field represents the place of the first character of the next line. If the parsed source region ends the document, the end field represents the place of an imaginary character appended to the end of the document.) The value of the start and end fields implement the Point interface.

Thanks for the response.

wooorm commented 6 years ago

I feel that’s a bit more verbose that it needs to be! But I’m super open to a PR clarifying this!

wooorm commented 6 years ago

Done!