Skip to content

Format of the Position keys #2

@Seb35

Description

@Seb35

Current state

In the initial (current) version of this plug-in, the position of each substring is encoded in the keys start and end with type int, alongside with the other keys about the capture (rule, text, and children, see JSON schema):

{
  rule: "rule-name",
  text: "captured text",
  start: 0,
  end: 13,
  children: []
}

Proposed changes

I wonder about changing this into one of these two forms:

{
  rule: "rule-name",
  text: "captured text",
  start: { line: 1, column: 1, offset: 0 },
  end: { line: 1, column: 14, offset: 13 },
  children: []
}

or

{
  rule: "rule-name",
  text: "captured text",
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 1, column: 14, offset: 13 }
  },
  children: []
}

The second one is more popular: used in PEG.js itself in the location() function (although without specific reference to the key name position) and in unist.

Adding line and column will probably be easier in most use cases – it was not my original use case because my grammar dealt only with single-line texts. An additional detail is: should the plug-in let the user choose their output format for the position? Some users could not need full details, more verbose and sometimes not useful.

I would appreciate if users of this plug-in give their opinion about this. This issue will stay open for multiple months before – perhaps – a change will happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions