It works in two passes. First it fills spans bottom-up: a composite node with no
Source
of its own gets
{Min[childstarts],Max[childends]}
from the offset spans of its children, so an interior node spans exactly the source its subtree covers. Then it converts every offset span - leaves' and composites' alike - to
{{line,column},{line,column}}
against source, counting newlines for the line and characters since the last newline for the column.
▪
A node that already has a
Source
(an explicit offset span) is kept and only converted, not re-spanned from its children.
▪
source is the original input string the offsets index into. It is needed because the offset-to-line/column conversion depends on where the newlines fall.
▪
This is what turns the raw offset spans into the
{{startLine,startColumn},{endLine,endColumn}}
convention
CodeParser
uses, so the finished tree's
Source
matches Wolfram's own LineColumn shape. A language entry point such as