Protean-Labs / mesh

The Mesh Engine that implements the Mesh Language, a computational language for web3.
Apache License 2.0
1 stars 0 forks source link

Add location information to AST nodes #50

Closed cvauclair closed 3 years ago

cvauclair commented 3 years ago

Description

Add location information to AST nodes such that it becomes possible to recover the location in source of a given AST node.

Proposed approach

Add a new type to the Syntax module:

type loc('a) = {
  data: 'a,
  loc_start: int,
  loc_end: int
}

along with an operator to quickly access the node data

let ($) = (loc) => loc.data;

This type will be used to wrap both pattern and expr values in the AST. The locations are available thanks to Menhir's $startpos and $endpos built in variables.