Updated merge_map
This commit is contained in:
parent
4c9bc1c9be
commit
9cb60b0606
14 changed files with 146 additions and 90 deletions
|
@ -2,9 +2,13 @@
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
This repository contains the common utility packages required for developing backend framework.
|
This repository contains the common utility packages required for developing dart backend framework.
|
||||||
|
|
||||||
## Available Packages
|
## Available Packages
|
||||||
|
|
||||||
* html_builder
|
* Html Builder
|
||||||
|
* Code Buffer
|
||||||
|
* Combinator
|
||||||
|
* Merge Map
|
||||||
|
* Symbol Table
|
||||||
|
|
|
@ -1,16 +1,29 @@
|
||||||
# 2.0.2
|
# Change Log
|
||||||
|
|
||||||
|
## 3.0.0
|
||||||
|
|
||||||
|
* Upgraded from `pendantic` to `lints` linter
|
||||||
|
* Published as `belatuk_merge_map` package
|
||||||
|
* Fixed linter warnings
|
||||||
|
|
||||||
|
## 2.0.2
|
||||||
|
|
||||||
* Resolve static analysis warnings
|
* Resolve static analysis warnings
|
||||||
|
|
||||||
# 2.0.1
|
## 2.0.1
|
||||||
|
|
||||||
* Updated README
|
* Updated README
|
||||||
|
|
||||||
# 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
* Migrated to work with Dart SDK 2.12.x NNBD
|
* Migrated to work with Dart SDK 2.12.x NNBD
|
||||||
|
|
||||||
# 1.0.2
|
## 1.0.2
|
||||||
|
|
||||||
* Add an example, for Pub's sake.
|
* Add an example, for Pub's sake.
|
||||||
|
|
||||||
# 1.0.1
|
## 1.0.1
|
||||||
|
|
||||||
* Add a specific constraint on Dart versions, to prevent Pub from rejecting all packages that depend on
|
* Add a specific constraint on Dart versions, to prevent Pub from rejecting all packages that depend on
|
||||||
`merge_map` (the entire Angel framework).
|
`merge_map` (the entire Angel framework).
|
||||||
* Add generic type support
|
* Add generic type support
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
MIT License (MIT)
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2021 dukefirehawk.com
|
Copyright (c) 2021, dukefirehawk.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Redistribution and use in source and binary forms, with or without
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
modification, are permitted provided that the following conditions are met:
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
copies or substantial portions of the Software.
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
this list of conditions and the following disclaimer in the documentation
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
and/or other materials provided with the distribution.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
contributors may be used to endorse or promote products derived from
|
||||||
SOFTWARE.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
# angel3_merge_map
|
# Belatuk Merge Map
|
||||||
[![version](https://img.shields.io/badge/pub-v2.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_merge_map)
|
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
|
||||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
|
||||||
|
|
||||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/merge_map/LICENSE)
|
|
||||||
|
[![version](https://img.shields.io/badge/pub-v3.0.1-brightgreen)](https://pub.dartlang.org/packages/belatuk_merge_map)
|
||||||
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
|
[![License](https://img.shields.io/github/license/dart-backend/belatuk-common-utilities)](https://github.com/dart-backend/belatuk-common-utilities/packages/code_buffer/LICENSE)
|
||||||
|
|
||||||
|
**Replacement of `package:merge_map` with breaking changes to support NNBD.**
|
||||||
|
|
||||||
Combine multiple Maps into one. Equivalent to
|
Combine multiple Maps into one. Equivalent to
|
||||||
[Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
|
[Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
|
||||||
in JS.
|
in JS.
|
||||||
|
|
||||||
# Example
|
## Example
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
import "package:angel3_merge_map/angel3_merge_map.dart";
|
import "package:belatuk_merge_map/belatuk_merge_map.dart";
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Map map1 = {'hello': 'world'};
|
Map map1 = {'hello': 'world'};
|
||||||
|
@ -22,4 +24,4 @@ void main() {
|
||||||
|
|
||||||
// {hello: world, foo: {bar: baz, john: doe, this: overrides previous maps}}
|
// {hello: world, foo: {bar: baz, john: doe, this: overrides previous maps}}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,4 +1 @@
|
||||||
include: package:pedantic/analysis_options.yaml
|
include: package:lints/recommended.yaml
|
||||||
analyzer:
|
|
||||||
strong-mode:
|
|
||||||
implicit-casts: false
|
|
|
@ -1,4 +1,4 @@
|
||||||
import 'package:angel3_merge_map/angel3_merge_map.dart';
|
import 'package:belatuk_merge_map/belatuk_merge_map.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// ignore: omit_local_variable_types
|
// ignore: omit_local_variable_types
|
||||||
|
|
|
@ -2,15 +2,17 @@
|
||||||
library angel3_merge_map;
|
library angel3_merge_map;
|
||||||
|
|
||||||
dynamic _copyValues<K, V>(
|
dynamic _copyValues<K, V>(
|
||||||
Map<K, V> from, Map<K, V?>? to, bool recursive, bool acceptNull) {
|
Map<K, V> from, Map<K, V?> to, bool recursive, bool acceptNull) {
|
||||||
for (var key in from.keys) {
|
for (var key in from.keys) {
|
||||||
if (from[key] is Map<K, V> && recursive) {
|
if (from[key] is Map<K, V> && recursive) {
|
||||||
if (!(to![key] is Map<K, V>)) {
|
if (to[key] is! Map<K, V>) {
|
||||||
to[key] = <K, V>{} as V;
|
to[key] = <K, V>{} as V;
|
||||||
}
|
}
|
||||||
_copyValues(from[key] as Map, to[key] as Map?, recursive, acceptNull);
|
_copyValues(from[key] as Map, to[key] as Map, recursive, acceptNull);
|
||||||
} else {
|
} else {
|
||||||
if (from[key] != null || acceptNull) to![key] = from[key];
|
if (from[key] != null || acceptNull) {
|
||||||
|
to[key] = from[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +29,8 @@ dynamic _copyValues<K, V>(
|
||||||
Map<K, V> mergeMap<K, V>(Iterable<Map<K, V>> maps,
|
Map<K, V> mergeMap<K, V>(Iterable<Map<K, V>> maps,
|
||||||
{bool recursive = true, bool acceptNull = false}) {
|
{bool recursive = true, bool acceptNull = false}) {
|
||||||
var result = <K, V>{};
|
var result = <K, V>{};
|
||||||
maps.forEach((Map<K, V> map) {
|
for (var map in maps) {
|
||||||
_copyValues(map, result, recursive, acceptNull);
|
_copyValues(map, result, recursive, acceptNull);
|
||||||
});
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
name: angel3_merge_map
|
name: belatuk_merge_map
|
||||||
version: 2.0.2
|
version: 3.0.0
|
||||||
description: Combine multiple Maps into one. Equivalent to Object.assign in JS.
|
description: Combine multiple Maps into one. Equivalent to Object.assign in JS.
|
||||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/merge_map
|
homepage: https://github.com/dart-backend/belatuk-common-utilities/tree/main/packages/merge_map
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
test: ^1.17.4
|
test: ^1.17.4
|
||||||
pedantic: ^1.11.0
|
lints: ^1.0.0
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import 'package:angel3_merge_map/angel3_merge_map.dart';
|
import 'package:belatuk_merge_map/belatuk_merge_map.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
|
@ -1,16 +1,28 @@
|
||||||
# 2.0.2
|
# Change Log
|
||||||
|
|
||||||
|
## 3.0.0
|
||||||
|
|
||||||
|
* Upgraded from `pendantic` to `lints` linter
|
||||||
|
* Published as `belatuk_symbol_table` package
|
||||||
|
|
||||||
|
## 2.0.2
|
||||||
|
|
||||||
* Resolved static analysis warnings
|
* Resolved static analysis warnings
|
||||||
|
|
||||||
# 2.0.1
|
## 2.0.1
|
||||||
|
|
||||||
* Resolved static analysis warnings
|
* Resolved static analysis warnings
|
||||||
|
|
||||||
# 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
* Migrated to work with Dart SDK 2.12.x NNBD
|
* Migrated to work with Dart SDK 2.12.x NNBD
|
||||||
|
|
||||||
## 1.0.4
|
## 1.0.4
|
||||||
|
|
||||||
* Added `context` to `SymbolTable`.
|
* Added `context` to `SymbolTable`.
|
||||||
|
|
||||||
## 1.0.3
|
## 1.0.3
|
||||||
|
|
||||||
* Converted `Visibility` into a `Comparable` class.
|
* Converted `Visibility` into a `Comparable` class.
|
||||||
* Renamed `add` -> `create`, `put` -> `assign`, and `allVariablesOfVisibility` -> `allVariablesWithVisibility`.
|
* Renamed `add` -> `create`, `put` -> `assign`, and `allVariablesOfVisibility` -> `allVariablesWithVisibility`.
|
||||||
* Added tests for `Visibility` comparing, and `depth`.
|
* Added tests for `Visibility` comparing, and `depth`.
|
||||||
|
@ -18,9 +30,10 @@
|
||||||
* Fixed a typo in `remove` that would have prevented it from working correctly.
|
* Fixed a typo in `remove` that would have prevented it from working correctly.
|
||||||
|
|
||||||
## 1.0.2
|
## 1.0.2
|
||||||
|
|
||||||
* Added `depth` to `SymbolTable`.
|
* Added `depth` to `SymbolTable`.
|
||||||
* Added `symbolTable` to `Variable`.
|
* Added `symbolTable` to `Variable`.
|
||||||
* Deprecated the redundant `Constant` class.
|
* Deprecated the redundant `Constant` class.
|
||||||
* Deprecated `Variable.markAsPrivate()`.
|
* Deprecated `Variable.markAsPrivate()`.
|
||||||
* Added the `Visibility` enumerator.
|
* Added the `Visibility` enumerator.
|
||||||
* Added the field `visibility` to `Variable`.
|
* Added the field `visibility` to `Variable`.
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
MIT License (MIT)
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2021 dukefirehawk.com
|
Copyright (c) 2021, dukefirehawk.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Redistribution and use in source and binary forms, with or without
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
modification, are permitted provided that the following conditions are met:
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
copies or substantial portions of the Software.
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
this list of conditions and the following disclaimer in the documentation
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
and/or other materials provided with the distribution.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
contributors may be used to endorse or promote products derived from
|
||||||
SOFTWARE.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# angel3_symbol_table
|
# Belatuk Merge Map
|
||||||
[![version](https://img.shields.io/badge/pub-v2.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_symbol_table)
|
|
||||||
|
[![version](https://img.shields.io/badge/pub-v3.0.0-brightgreen)](https://pub.dartlang.org/packages/belatuk_symbol_table)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||||
|
|
||||||
|
@ -9,7 +10,8 @@ A generic symbol table implementation in Dart, with support for scopes and const
|
||||||
The symbol tables produced by this package are hierarchical (in this case, tree-shaped),
|
The symbol tables produced by this package are hierarchical (in this case, tree-shaped),
|
||||||
and utilize basic memoization to speed up repeated lookups.
|
and utilize basic memoization to speed up repeated lookups.
|
||||||
|
|
||||||
# Variables
|
## Variables
|
||||||
|
|
||||||
To represent a symbol, use `Variable`. I opted for the name
|
To represent a symbol, use `Variable`. I opted for the name
|
||||||
`Variable` to avoid conflict with the Dart primitive `Symbol`.
|
`Variable` to avoid conflict with the Dart primitive `Symbol`.
|
||||||
|
|
||||||
|
@ -28,6 +30,7 @@ foo.value = 'baz'; // Also throws a StateError - Once a variable is locked, it c
|
||||||
```
|
```
|
||||||
|
|
||||||
## Visibility
|
## Visibility
|
||||||
|
|
||||||
Variables are *public* by default, but can also be marked as *private* or *protected*. This can be helpful if you are trying
|
Variables are *public* by default, but can also be marked as *private* or *protected*. This can be helpful if you are trying
|
||||||
to determine which symbols should be exported from a library or class.
|
to determine which symbols should be exported from a library or class.
|
||||||
|
|
||||||
|
@ -36,7 +39,8 @@ myVariable.visibility = Visibility.protected;
|
||||||
myVariable.visibility = Visibility.private;
|
myVariable.visibility = Visibility.private;
|
||||||
```
|
```
|
||||||
|
|
||||||
# Symbol Tables
|
## Symbol Tables
|
||||||
|
|
||||||
It's easy to create a basic symbol table:
|
It's easy to create a basic symbol table:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
|
@ -66,7 +70,8 @@ var symbol = doubles.resolveOrCreate('one', value: 1.0);
|
||||||
var symbol = doubles.resolveOrCreate('one', value: 1.0, constant: true);
|
var symbol = doubles.resolveOrCreate('one', value: 1.0, constant: true);
|
||||||
```
|
```
|
||||||
|
|
||||||
# Exporting Symbols
|
## Exporting Symbols
|
||||||
|
|
||||||
Due to the tree structure of symbol tables, it is extremely easy to
|
Due to the tree structure of symbol tables, it is extremely easy to
|
||||||
extract a linear list of distinct variables, with variables lower in the hierarchy superseding their parents
|
extract a linear list of distinct variables, with variables lower in the hierarchy superseding their parents
|
||||||
(effectively accomplishing variable shadowing).
|
(effectively accomplishing variable shadowing).
|
||||||
|
@ -83,15 +88,17 @@ var exportedSymbols = mySymbolTable.allPublicVariables;
|
||||||
```
|
```
|
||||||
|
|
||||||
It's easy to extract symbols of a given visibility:
|
It's easy to extract symbols of a given visibility:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
var exportedSymbols = mySymbolTable.allVariablesWithVisibility(Visibility.protected);
|
var exportedSymbols = mySymbolTable.allVariablesWithVisibility(Visibility.protected);
|
||||||
```
|
```
|
||||||
|
|
||||||
# Child Scopes
|
## Child Scopes
|
||||||
|
|
||||||
There are three ways to create a new symbol table:
|
There are three ways to create a new symbol table:
|
||||||
|
|
||||||
|
### Regular Children
|
||||||
|
|
||||||
## Regular Children
|
|
||||||
This is what most interpreters need; it simply creates a symbol table with the current symbol table
|
This is what most interpreters need; it simply creates a symbol table with the current symbol table
|
||||||
as its parent. The new scope can define its own symbols, which will only shadow the ancestors within the
|
as its parent. The new scope can define its own symbols, which will only shadow the ancestors within the
|
||||||
correct scope.
|
correct scope.
|
||||||
|
@ -101,18 +108,21 @@ var child = mySymbolTable.createChild();
|
||||||
var child = mySymbolTable.createChild(values: {...});
|
var child = mySymbolTable.createChild(values: {...});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Depth
|
#### Depth
|
||||||
|
|
||||||
Every symbol table has an associated `depth` attached to it, with the `depth` at the root
|
Every symbol table has an associated `depth` attached to it, with the `depth` at the root
|
||||||
being `0`. When `createChild` is called, the resulting child has an incremented `depth`.
|
being `0`. When `createChild` is called, the resulting child has an incremented `depth`.
|
||||||
|
|
||||||
## Clones
|
### Clones
|
||||||
|
|
||||||
This creates a scope at the same level as the current one, with all the same variables.
|
This creates a scope at the same level as the current one, with all the same variables.
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
var clone = mySymbolTable.clone();
|
var clone = mySymbolTable.clone();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Forked Scopes
|
### Forked Scopes
|
||||||
|
|
||||||
If you are implementing a language with closure functions, you might consider looking into this.
|
If you are implementing a language with closure functions, you might consider looking into this.
|
||||||
A forked scope is a scope identical to the current one, but instead of merely copying references
|
A forked scope is a scope identical to the current one, but instead of merely copying references
|
||||||
to variables, the values of variables are copied into new ones.
|
to variables, the values of variables are copied into new ones.
|
||||||
|
@ -128,7 +138,8 @@ var forked = mySymbolTable.fork();
|
||||||
var forked = mySymbolTable.fork(values: {...});
|
var forked = mySymbolTable.fork(values: {...});
|
||||||
```
|
```
|
||||||
|
|
||||||
# Creating Names
|
## Creating Names
|
||||||
|
|
||||||
In languages with block scope, oftentimes, identifiers will collide within a global scope.
|
In languages with block scope, oftentimes, identifiers will collide within a global scope.
|
||||||
To avoid this, symbol tables expose a `uniqueName()` method that simply attaches a numerical suffix to
|
To avoid this, symbol tables expose a `uniqueName()` method that simply attaches a numerical suffix to
|
||||||
an input name. The name is guaranteed to never be repeated within a specific scope.
|
an input name. The name is guaranteed to never be repeated within a specific scope.
|
||||||
|
@ -139,7 +150,8 @@ var name1 = mySymbolTable.uniqueName('foo'); // foo1
|
||||||
var name2 = mySymbolTable.uniqueName('foo'); // foo2
|
var name2 = mySymbolTable.uniqueName('foo'); // foo2
|
||||||
```
|
```
|
||||||
|
|
||||||
# `this` Context
|
## `this` Context
|
||||||
|
|
||||||
Many languages handle a sort of `this` context that values within a scope may
|
Many languages handle a sort of `this` context that values within a scope may
|
||||||
optionally be resolved against. Symbol tables can easily set their context
|
optionally be resolved against. Symbol tables can easily set their context
|
||||||
as follows:
|
as follows:
|
||||||
|
@ -158,4 +170,4 @@ void bar() {
|
||||||
mySymbolTable.context = thisContext;
|
mySymbolTable.context = thisContext;
|
||||||
expect(mySymbolTable.createChild().createChild().context, thisContext);
|
expect(mySymbolTable.createChild().createChild().context, thisContext);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,4 +1 @@
|
||||||
include: package:pedantic/analysis_options.yaml
|
include: package:lints/recommended.yaml
|
||||||
analyzer:
|
|
||||||
strong-mode:
|
|
||||||
implicit-casts: false
|
|
|
@ -1,11 +1,11 @@
|
||||||
name: angel3_symbol_table
|
name: belatuk_symbol_table
|
||||||
version: 2.0.2
|
version: 3.0.0
|
||||||
description: A generic symbol table implementation in Dart, with support for scopes and constants.
|
description: A generic symbol table implementation in Dart, with support for scopes and constants.
|
||||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/symbol_table
|
homepage: https://github.com/dart-backend/belatuk-common-utilities/tree/main/packages/symbol_table
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
collection: ^1.15.0
|
collection: ^1.15.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
test: ^1.17.4
|
test: ^1.17.4
|
||||||
pedantic: ^1.11.0
|
lints: ^1.0.0
|
||||||
|
|
Loading…
Reference in a new issue