Deprecated angel3_symbol_table
This commit is contained in:
parent
242a70b7c9
commit
ae0b40079c
3 changed files with 38 additions and 12 deletions
|
@ -1,23 +1,35 @@
|
|||
# 2.0.2
|
||||
# Change Log
|
||||
|
||||
## 2.0.3
|
||||
|
||||
* Final release. Replaced by `belatuk_symbol_table` package.
|
||||
|
||||
## 2.0.2
|
||||
|
||||
* Resolved static analysis warnings
|
||||
|
||||
# 2.0.1
|
||||
## 2.0.1
|
||||
|
||||
* Resolved static analysis warnings
|
||||
|
||||
# 2.0.0
|
||||
## 2.0.0
|
||||
|
||||
* Migrated to work with Dart SDK 2.12.x NNBD
|
||||
|
||||
## 1.0.4
|
||||
#### 1.0.4
|
||||
|
||||
* Added `context` to `SymbolTable`.
|
||||
|
||||
## 1.0.3
|
||||
#### 1.0.3
|
||||
|
||||
* Converted `Visibility` into a `Comparable` class.
|
||||
* Renamed `add` -> `create`, `put` -> `assign`, and `allVariablesOfVisibility` -> `allVariablesWithVisibility`.
|
||||
* Added tests for `Visibility` comparing, and `depth`.
|
||||
* Added `uniqueName()` to `SymbolTable`.
|
||||
* Fixed a typo in `remove` that would have prevented it from working correctly.
|
||||
|
||||
## 1.0.2
|
||||
#### 1.0.2
|
||||
|
||||
* Added `depth` to `SymbolTable`.
|
||||
* Added `symbolTable` to `Variable`.
|
||||
* Deprecated the redundant `Constant` class.
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
# angel3_symbol_table
|
||||
[![version](https://img.shields.io/badge/pub-v2.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_symbol_table)
|
||||
# Angel3 Symbol Table
|
||||
|
||||
[![version](https://img.shields.io/badge/pub-v2.0.3-brightgreen)](https://pub.dartlang.org/packages/angel3_symbol_table)
|
||||
[![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/symbol_table/LICENSE)
|
||||
|
||||
**DEPRECATED: Replaced by [`belatuk_symbol_table`](https://pub.dartlang.org/packages/belatuk_symbol_table) package**
|
||||
|
||||
A generic symbol table implementation in Dart, with support for scopes and constants.
|
||||
The symbol tables produced by this package are hierarchical (in this case, tree-shaped),
|
||||
and utilize basic memoization to speed up repeated lookups.
|
||||
|
||||
# Variables
|
||||
|
||||
To represent a symbol, use `Variable`. I opted for the name
|
||||
`Variable` to avoid conflict with the Dart primitive `Symbol`.
|
||||
|
||||
|
@ -28,6 +32,7 @@ foo.value = 'baz'; // Also throws a StateError - Once a variable is locked, it c
|
|||
```
|
||||
|
||||
## Visibility
|
||||
|
||||
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.
|
||||
|
||||
|
@ -37,6 +42,7 @@ myVariable.visibility = Visibility.private;
|
|||
```
|
||||
|
||||
# Symbol Tables
|
||||
|
||||
It's easy to create a basic symbol table:
|
||||
|
||||
```dart
|
||||
|
@ -67,6 +73,7 @@ var symbol = doubles.resolveOrCreate('one', value: 1.0, constant: true);
|
|||
```
|
||||
|
||||
# Exporting Symbols
|
||||
|
||||
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
|
||||
(effectively accomplishing variable shadowing).
|
||||
|
@ -83,15 +90,17 @@ var exportedSymbols = mySymbolTable.allPublicVariables;
|
|||
```
|
||||
|
||||
It's easy to extract symbols of a given visibility:
|
||||
|
||||
```dart
|
||||
var exportedSymbols = mySymbolTable.allVariablesWithVisibility(Visibility.protected);
|
||||
```
|
||||
|
||||
# Child Scopes
|
||||
|
||||
There are three ways to create a new symbol table:
|
||||
|
||||
|
||||
## Regular Children
|
||||
|
||||
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
|
||||
correct scope.
|
||||
|
@ -102,10 +111,12 @@ var child = mySymbolTable.createChild(values: {...});
|
|||
```
|
||||
|
||||
### Depth
|
||||
|
||||
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`.
|
||||
|
||||
## Clones
|
||||
|
||||
This creates a scope at the same level as the current one, with all the same variables.
|
||||
|
||||
```dart
|
||||
|
@ -113,6 +124,7 @@ var clone = mySymbolTable.clone();
|
|||
```
|
||||
|
||||
## Forked Scopes
|
||||
|
||||
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
|
||||
to variables, the values of variables are copied into new ones.
|
||||
|
@ -129,6 +141,7 @@ var forked = mySymbolTable.fork(values: {...});
|
|||
```
|
||||
|
||||
# Creating Names
|
||||
|
||||
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
|
||||
an input name. The name is guaranteed to never be repeated within a specific scope.
|
||||
|
@ -140,6 +153,7 @@ var name2 = mySymbolTable.uniqueName('foo'); // foo2
|
|||
```
|
||||
|
||||
# `this` Context
|
||||
|
||||
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
|
||||
as follows:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel3_symbol_table
|
||||
version: 2.0.2
|
||||
version: 2.0.3
|
||||
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
|
||||
environment:
|
||||
|
|
Loading…
Reference in a new issue