You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import'dart:io';
import'package:path/path.dart'as p;
import'package:ngast/ngast.dart';
RecoveringExceptionHandler exceptionHandler =RecoveringExceptionHandler();
List<StandaloneTemplateAst> parse(String template) =>constNgParser().parse(
template,
sourceUrl:'/test/parser_test.dart#inline',
exceptionHandler: exceptionHandler,
desugar:false,
);
voidmain() {
String input;
exceptionHandler.exceptions.clear();
var fileDir = p.join('test', 'ast_cli_tester_source.html');
var file =File(fileDir.toString());
input = file.readAsStringSync();
//input = stdin.readLineSync(encoding: UTF8);var ast =parse(input);
print('----------------------------------------------');
if (exceptionHandler isThrowingExceptionHandler) {
print('CORRECT!');
print(ast);
}
var exceptionsList = exceptionHandler.exceptions;
if (exceptionsList.isEmpty) {
print('CORRECT!');
print(ast);
} else {
var visitor =constHumanizingTemplateAstVisitor();
var fixed = ast.map((t) => t.accept(visitor)).join('');
print('ORGNL: $input');
print('FIXED: $fixed');
print('\n\nERRORS:');
for (var e in exceptionHandler.exceptions) {
var context = input.substring(e.offset!, e.offset!+ e.length!);
print('${e.errorCode.message} :: $context at ${e.offset}');
}
}
}
I would rewrite like this:
import'dart:io';
import'package:path/path.dart'as p;
import'package:ngast/ngast.dart';
// global & no use outside - without typefinal exceptionHandler =RecoveringExceptionHandler();
// not function literal - full functionList<StandaloneTemplateAst> parse(String template) {
returnconstNgParser().parse(
template,
sourceUrl:'/test/parser_test.dart#inline',
exceptionHandler: exceptionHandler,
desugar:false,
);
}
voidmain() {
exceptionHandler.exceptions.clear();
// empty line before variable declarationvar fileDir = p.join('test', 'ast_cli_tester_source.html');
var file =File(fileDir);
var input = file.readAsStringSync();
var ast =parse(input);
print('----------------------------------------------');
// empty line around blocksif (exceptionHandler isThrowingExceptionHandler) {
print('CORRECT!');
print(ast);
}
var exceptionsList = exceptionHandler.exceptions;
if (exceptionsList.isEmpty) {
print('CORRECT!');
print(ast);
} else {
var visitor =constHumanizingTemplateAstVisitor();
var fixed = ast.map((t) => t.accept(visitor)).join();
print('ORGNL: $input');
print('FIXED: $fixed');
print('\n\nERRORS:');
for (var e in exceptionHandler.exceptions) {
var context = input.substring(e.offset!, e.offset!+ e.length!);
print('${e.errorCode.message} :: $context at ${e.offset}');
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Any rules/restrictions on code style?
For example,
ngast\test\ast_cli_tester.dart
:I would rewrite like this:
My default
analysis_options.yaml
config:Beta Was this translation helpful? Give feedback.
All reactions