platform/lib/src/language/parser.dart

27 lines
595 B
Dart
Raw Normal View History

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