import 'dart:async'; import 'ast/ast.dart'; import 'stream_reader.dart'; import 'token.dart'; class Parser implements StreamConsumer { bool _closed = false; final StreamReader _reader = new StreamReader(); final StreamController _onNode = new StreamController(); Stream get onNode => _onNode.stream; @override Future addStream(Stream stream) async { if (_closed) throw new StateError('Parser is already closed.'); stream.pipe(_reader); } @override Future close() async { _closed = true; await _onNode.close(); } }