visitCapture method

  1. @override
ExpressionGenerator visitCapture(
  1. CaptureExpression node
)
inherited

Implementation

@override
ExpressionGenerator visitCapture(CaptureExpression node) {
  final g = ExpressionGenerator(node);
  g.generate = (block) {
    g.declareVariable(block);
    final child = node.expression;
    if (g.variable == null) {
      final g1 = acceptChild(child, g);
      g1.addVariables(g);
      g1.generate(block);
    } else {
      final start = g.store(block, Members.pos);
      final g1 = acceptChild(child, g);
      g1.addVariables(g);
      g1.generate(block);
      block.if$(ref(Members.ok), (block) {
        final args = [ref(start), ref(Members.pos)];
        final call =
            methodCallExpression(ref(Members.source), 'substring', args);
        block.assign(g.variable!, call);
      });
    }
  };

  return g;
}