Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

BRAKING CHANGE: Add location to AST object #11

Merged
merged 3 commits into from
Jun 9, 2021
Merged

BRAKING CHANGE: Add location to AST object #11

merged 3 commits into from
Jun 9, 2021

Conversation

kamiazya
Copy link
Member

@kamiazya kamiazya commented Jun 9, 2021

What was a problem

The input dot language cannot specify the location in the character string, and the range of utilization of AST is limited.

How this PR fixes the problem

Include the location of the AST object in the string as an AST attribute.

const ast = AST.parse(`
  digraph example {
    node1 [
      label = "My Node",
    ]
  }
`);

console.log(inspect(ast, false, Infinity));
// {
//   type: 'graph',
//   id: {
//     type: 'literal',
//     value: 'example',
//     quoted: false,
//     location: {
//       start: { offset: 11, line: 2, column: 11 },
//       end: { offset: 18, line: 2, column: 18 }
//     }
//   },
//   directed: true,
//   strict: false,
//   body: [
//     {
//       type: 'node',
//       id: {
//         type: 'literal',
//         value: 'node1',
//         quoted: false,
//         location: {
//           start: { offset: 25, line: 3, column: 5 },
//           end: { offset: 30, line: 3, column: 10 }
//         }
//       },
//       attributes: [
//         {
//           type: 'attribute',
//           key: {
//             type: 'literal',
//             value: 'label',
//             quoted: false,
//             location: {
//               start: { offset: 39, line: 4, column: 7 },
//               end: { offset: 44, line: 4, column: 12 }
//             }
//           },
//           value: {
//             type: 'literal',
//             value: 'My Node',
//             quoted: true,
//             location: {
//               start: { offset: 47, line: 4, column: 15 },
//               end: { offset: 56, line: 4, column: 24 }
//             }
//           },
//           location: {
//             start: { offset: 39, line: 4, column: 7 },
//             end: { offset: 57, line: 4, column: 25 }
//           }
//         }
//       ],
//       location: {
//         start: { offset: 25, line: 3, column: 5 },
//         end: { offset: 66, line: 6, column: 3 }
//       }
//     }
//   ],
//   location: {
//     start: { offset: 0, line: 1, column: 1 },
//     end: { offset: 68, line: 7, column: 1 }
//   }
// }

Check lists (check x in [ ] of list items)

  • Test passed
  • Coding style (indentation, etc)

@kamiazya kamiazya marked this pull request as ready for review June 9, 2021 15:02
@kamiazya kamiazya merged commit f330a1d into main Jun 9, 2021
@kamiazya kamiazya deleted the add-location branch June 9, 2021 15:03
@kamiazya kamiazya added the enhancement New feature or request label Jun 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant