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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « petitparser/lib/src/lisp/cons.dart ('k') | petitparser/lib/src/lisp/grammar.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 part of lisp;
2
3 /**
4 * Environment of bindings.
5 */
6 class Environment {
7
8 /** The owning environment. */
9 final Environment _owner;
10
11 /** The internal environment bindings. */
12 final Map<Name, dynamic> _bindings;
13
14 /** Constructor for the nested environment. */
15 Environment([this._owner]) : _bindings = new Map();
16
17 /** Constructor for a nested environment. */
18 Environment create() => new Environment(this);
19
20 /** Return the binding for [key]. */
21 operator [](Name key) {
22 if (_bindings.containsKey(key)) {
23 return _bindings[key];
24 } else if (_owner != null) {
25 return _owner[key];
26 } else {
27 return _invalidBinding(key);
28 }
29 }
30
31 /** Updates the binding for [key] with a [value]. */
32 void operator []=(Name key, value) {
33 if (_bindings.containsKey(key)) {
34 _bindings[key] = value;
35 } else if (_owner != null) {
36 _owner[key] = value;
37 } else {
38 _invalidBinding(key);
39 }
40 }
41
42 /** Defines a new binding from [key] to [value]. */
43 define(Name key, value) {
44 return _bindings[key] = value;
45 }
46
47 /** Returns the keys of the bindings. */
48 Iterable<Name> get keys => _bindings.keys;
49
50 /** Returns the parent of the bindings. */
51 Environment get owner => _owner;
52
53 /** Called when a missing binding is accessed. */
54 _invalidBinding(Name key) {
55 throw new ArgumentError('Unknown binding for $key');
56 }
57 }
OLDNEW
« no previous file with comments | « petitparser/lib/src/lisp/cons.dart ('k') | petitparser/lib/src/lisp/grammar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698