Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1510)

Side by Side Diff: packages/petitparser/lib/src/lisp/environment.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 part of petitparser.lisp;
2
3 /// Environment of bindings.
4 class Environment {
5
6 /// The owning environment.
7 final Environment _owner;
8
9 /// The internal environment bindings.
10 final Map<Name, dynamic> _bindings;
11
12 /// Constructor for the nested environment.
13 Environment([this._owner]) : _bindings = new Map();
14
15 /// Constructor for a nested environment.
16 Environment create() => new Environment(this);
17
18 /// Return the binding for [key].
19 operator [](Name key) {
20 if (_bindings.containsKey(key)) {
21 return _bindings[key];
22 } else if (_owner != null) {
23 return _owner[key];
24 } else {
25 return _invalidBinding(key);
26 }
27 }
28
29 /// Updates the binding for [key] with a [value].
30 void operator []=(Name key, value) {
31 if (_bindings.containsKey(key)) {
32 _bindings[key] = value;
33 } else if (_owner != null) {
34 _owner[key] = value;
35 } else {
36 _invalidBinding(key);
37 }
38 }
39
40 /// Defines a new binding from [key] to [value].
41 define(Name key, value) {
42 return _bindings[key] = value;
43 }
44
45 /// Returns the keys of the bindings.
46 Iterable<Name> get keys => _bindings.keys;
47
48 /// Returns the parent of the bindings.
49 Environment get owner => _owner;
50
51 /// Called when a missing binding is accessed.
52 _invalidBinding(Name key) {
53 throw new ArgumentError('Unknown binding for $key');
54 }
55 }
OLDNEW
« no previous file with comments | « packages/petitparser/lib/src/lisp/cons.dart ('k') | packages/petitparser/lib/src/lisp/grammar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698