parse method

D4rtProgram parse(
  1. String source, {
  2. String? basePath,
})

Parses source once into a D4rtProgram that executeProgram can run any number of times, on this interpreter or another (woneprpd132, mirrors tom_d4rt).

This is execute split at its one expensive step that does not depend on the run: an embedder that runs the same script repeatedly caches the program and pays for the parse once. A parse error is raised here, as the SourceCodeD4rtException execute would raise.

The program carries only syntax. Everything a run derives from it — declarations, static coordinates, the environment — is rebuilt by each executeProgram, so two runs of one program share no state.

Implementation

D4rtProgram parse(String source, {String? basePath}) => D4rtProgram._(
  source: source,
  basePath: basePath,
  unit: _parseExecutableSource(source),
);