Publish symbol_table
This commit is contained in:
parent
8a30a91a27
commit
e6a7496d66
7 changed files with 23 additions and 22 deletions
|
@ -1,6 +1,9 @@
|
|||
# symbol_table
|
||||
[![Pub](https://img.shields.io/pub/v/symbol_table.svg)](https://pub.dartlang.org/packages/symbol_table)
|
||||
[![build status](https://travis-ci.org/thosakwe/symbol_table.svg)](https://travis-ci.org/thosakwe/symbol_table)
|
||||
# angel3_symbol_table
|
||||
[![version](https://img.shields.io/badge/pub-v2.0.0-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)
|
||||
|
||||
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),
|
||||
|
@ -11,11 +14,11 @@ To represent a symbol, use `Variable`. I opted for the name
|
|||
`Variable` to avoid conflict with the Dart primitive `Symbol`.
|
||||
|
||||
```dart
|
||||
var foo = new Variable<String>('foo');
|
||||
var bar = new Variable<String>('bar', value: 'baz');
|
||||
var foo = Variable<String>('foo');
|
||||
var bar = Variable<String>('bar', value: 'baz');
|
||||
|
||||
// Call `lock` to mark a symbol as immutable.
|
||||
var shelley = new Variable<String>('foo', value: 'bar')..lock();
|
||||
var shelley = Variable<String>('foo', value: 'bar')..lock();
|
||||
|
||||
foo.value = 'bar';
|
||||
shelley.value = 'Mary'; // Throws a StateError - constants cannot be overwritten.
|
||||
|
@ -37,8 +40,8 @@ myVariable.visibility = Visibility.private;
|
|||
It's easy to create a basic symbol table:
|
||||
|
||||
```dart
|
||||
var mySymbolTable = new SymbolTable<int>();
|
||||
var doubles = new SymbolTable<double>(values: {
|
||||
var mySymbolTable = SymbolTable<int>();
|
||||
var doubles = SymbolTable<double>(values: {
|
||||
'hydrogen': 1.0,
|
||||
'avogadro': 6.022e23
|
||||
});
|
||||
|
|
|
@ -88,7 +88,7 @@ class SymbolTable<T> {
|
|||
}
|
||||
|
||||
crawl(this);
|
||||
return new List<Variable<T>>.unmodifiable(out);
|
||||
return List<Variable<T>>.unmodifiable(out);
|
||||
}
|
||||
|
||||
/// Helper for calling [allVariablesWithVisibility] to fetch all public variables.
|
||||
|
@ -126,7 +126,7 @@ class SymbolTable<T> {
|
|||
}
|
||||
|
||||
crawl(this);
|
||||
return new List<Variable<T>>.unmodifiable(out);
|
||||
return List<Variable<T>>.unmodifiable(out);
|
||||
}
|
||||
|
||||
Variable<T>? operator [](String name) => resolve(name);
|
||||
|
@ -152,11 +152,11 @@ class SymbolTable<T> {
|
|||
Variable<T> create(String name, {T? value, bool? constant}) {
|
||||
// Check if it exists first.
|
||||
if (_variables.any((v) => v.name == name))
|
||||
throw new StateError(
|
||||
throw StateError(
|
||||
'A symbol named "$name" already exists within the current context.');
|
||||
|
||||
_wipeLookupCache(name);
|
||||
Variable<T> v = new Variable._(name, this, value: value);
|
||||
Variable<T> v = Variable._(name, this, value: value);
|
||||
if (constant == true) v.lock();
|
||||
_variables.add(v);
|
||||
return v;
|
||||
|
@ -282,7 +282,7 @@ class SymbolTable<T> {
|
|||
.._root = _root;
|
||||
|
||||
table._variables.addAll(_variables.map((Variable v) {
|
||||
Variable<T> variable = new Variable._(v.name, this, value: v.value);
|
||||
Variable<T> variable = Variable._(v.name, this, value: v.value);
|
||||
variable.visibility = v.visibility;
|
||||
|
||||
if (v.isImmutable) variable.lock();
|
||||
|
|
|
@ -33,8 +33,7 @@ class Variable<T> {
|
|||
|
||||
void set value(T? value) {
|
||||
if (_locked)
|
||||
throw new StateError(
|
||||
'The value of constant "$name" cannot be overwritten.');
|
||||
throw StateError('The value of constant "$name" cannot be overwritten.');
|
||||
_value = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
name: symbol_table
|
||||
name: angel3_symbol_table
|
||||
version: 2.0.0
|
||||
description: A generic symbol table implementation in Dart, with support for scopes and constants.
|
||||
homepage: https://github.com/thosakwe/symbol_table
|
||||
publish_to: none
|
||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/symbol_table
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
collection: ^1.15.0
|
||||
dev_dependencies:
|
||||
test: ^1.17.3
|
||||
test: ^1.17.4
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:symbol_table/symbol_table.dart';
|
||||
import 'package:angel3_symbol_table/angel3_symbol_table.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
void main() {
|
||||
late SymbolTable<int> scope;
|
||||
|
||||
setUp(() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# angel3_test
|
||||
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_tet)
|
||||
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_test)
|
||||
[![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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue