Skip to content

Commit

Permalink
docs and test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sjhorn committed Apr 14, 2024
1 parent 0cc666c commit 0bbca33
Show file tree
Hide file tree
Showing 27 changed files with 755 additions and 292 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Scott Horn
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,39 @@ From [wikipedia](https://en.wikipedia.org/wiki/VisiCalc)
Simple usage examples below:

```dart
final rows = {
'A1'.a1: '-12.2',
'A2'.a1: '(a5 + 45)',
'A3'.a1: '13',
'A4'.a1: '+A2 + A5 - A6',
'A5'.a1: '-A3 / 2 + 2 ',
'A6'.a1: '.23 * 2',
'B1'.a1: 'A1 + A3 * 3',
'B2'.a1: '(A1 + A3) * 3',
import 'package:a1/a1.dart';
import 'package:visicalc_engine/visicalc_engine.dart';
void main(List<String> arguments) {
final sheet = {
'A1'.a1: '/FR-12.2',
'A2'.a1: '(a5+45)',
'A3'.a1: '/F*13',
'A4'.a1: '+A2+A5-A6',
'A5'.a1: '-A3/2+2',
'A6'.a1: '/F\$.23*2',
'B1'.a1: '+A1+A3*3',
'B2'.a1: '(A1+A3)*3',
'B3'.a1: '12.23e-12',
'B4'.a1: '.23e12',
'B5'.a1: 'b4',
'B6'.a1: 'b2',
'B7'.a1: '@sum(a1...b6)' // 1 + 1 + 28
'B5'.a1: '/FRb4',
'B6'.a1: '+b2',
'B7'.a1: '@sum(a1...b6)',
'D13'.a1: '+b2',
};
final evaluator = Evaluator();
final parser = evaluator.build();
final Map<A1, FormulaType> varMap = <A1, FormulaType>{};
for (final MapEntry(:key, :value) in rows.entries) {
final ast = parser.parse(value);
if (ast is Success) {
varMap[key] = ast.value;
}
}
for (final MapEntry(:key, :value) in varMap.entries) {
final evalResult = value.eval(ResultCacheMap(varMap));
print('$key -> ${evalResult.runtimeType} -> $evalResult');
}
final worksheet = Engine(sheet, parseErrorThrows: true);
print(worksheet);
// Change cell
var b5 = worksheet["B5".a1];
print('B5 formula was ${b5?.formulaType?.asFormula} = $b5');
print('Now setting B5 to formula a1');
worksheet['B5'.a1] = '+a1';
b5 = worksheet["B5".a1];
print('Now B5 formula is ${b5?.formulaType?.asFormula} = $b5');
print(worksheet);
}
```
The `test/` directory explores other use cases for the A1 types and library.

Expand Down
8 changes: 4 additions & 4 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ void main(List<String> arguments) {
'A4'.a1: '+A2+A5-A6',
'A5'.a1: '-A3/2+2',
'A6'.a1: '/F\$.23*2',
'B1'.a1: 'A1+A3*3',
'B1'.a1: '+A1+A3*3',
'B2'.a1: '(A1+A3)*3',
'B3'.a1: '12.23e-12',
'B4'.a1: '.23e12',
'B5'.a1: '/FRb4',
'B6'.a1: 'b2',
'B6'.a1: '+b2',
'B7'.a1: '@sum(a1...b6)',
'D13'.a1: 'b2',
'D13'.a1: '+b2',
};
final worksheet = Engine(sheet, parseErrorThrows: true);
print(worksheet);
Expand All @@ -25,7 +25,7 @@ void main(List<String> arguments) {
var b5 = worksheet["B5".a1];
print('B5 formula was ${b5?.formulaType?.asFormula} = $b5');
print('Now setting B5 to formula a1');
worksheet['B5'.a1] = 'a1';
worksheet['B5'.a1] = '+a1';

b5 = worksheet["B5".a1];
print('Now B5 formula is ${b5?.formulaType?.asFormula} = $b5');
Expand Down
Loading

0 comments on commit 0bbca33

Please sign in to comment.