encoder library

Dart-to-ball encoder — translates ANY valid Dart source code into ball programs.

Uses package:analyzer for parsing (official Dart SDK parser), so every valid Dart file is parsed correctly. The encoder maps ALL Dart constructs to ball primitives:

  • Operators → std.add, std.subtract, std.bitwise_and, etc.
  • Control flow → std.if, std.for, std.while, std.try, etc.
  • Type operations → std.is, std.as, std.null_check, etc.
  • Dart constructs → std.cascade, std.spread, std.record, etc. (universal std)
  • Classes → DescriptorProto (fields) + FunctionDefinition (methods)
  • Lambdas/closures → FunctionDefinition with name = "" (anonymous)
  • Everything else → FunctionCall to std module with MessageCreation input

Language-specific metadata (import URIs, class modifiers, etc.) is preserved in google.protobuf.Struct metadata fields for lossless round-tripping.

Classes

DartEncoder
Encodes Dart source code into a ball Program.

Exceptions / Errors

EncoderError
Error thrown by the encoder in strict mode when it encounters malformed metadata or an unrecoverable encoding problem.