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.
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:along with an operator to quickly access the node data
This type will be used to wrap both
pattern
andexpr
values in the AST. The locations are available thanks to Menhir's$startpos
and$endpos
built in variables.