platform/packages/jael/jael2/example/main.dart

38 lines
977 B
Dart
Raw Normal View History

2018-04-03 05:04:34 +00:00
import 'dart:io';
import 'package:charcode/charcode.dart';
import 'package:code_buffer/code_buffer.dart';
import 'package:jael/jael.dart' as jael;
import 'package:symbol_table/symbol_table.dart';
main() {
while (true) {
2019-07-29 22:12:52 +00:00
var buf = StringBuffer();
2018-04-03 05:04:34 +00:00
int ch;
print('Enter lines of Jael text, terminated by CTRL^D.');
print('All environment variables are injected into the template scope.');
while ((ch = stdin.readByteSync()) != $eot && ch != -1) {
buf.writeCharCode(ch);
}
var document = jael.parseDocument(
buf.toString(),
sourceUrl: 'stdin',
onError: stderr.writeln,
);
if (document == null) {
stderr.writeln('Could not parse the given text.');
} else {
2019-07-29 22:12:52 +00:00
var output = CodeBuffer();
2018-04-03 05:04:34 +00:00
const jael.Renderer().render(
document,
output,
2019-07-29 22:12:52 +00:00
SymbolTable(values: Platform.environment),
2018-04-03 05:04:34 +00:00
strictResolution: false,
);
print('GENERATED HTML:\n$output');
}
}
}