Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: third_party/pkg/angular/lib/tools/parser_generator/generator.dart

Issue 148453003: Updating Angular version (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/tools/parser_generator/generator.dart
diff --git a/third_party/pkg/angular/lib/tools/parser_generator/generator.dart b/third_party/pkg/angular/lib/tools/parser_generator/generator.dart
index 1522ac89dc6dfe94054c005af2a053248a01130f..60d1be0771e4d77b1093bfbdbb85271f3b425d4d 100644
--- a/third_party/pkg/angular/lib/tools/parser_generator/generator.dart
+++ b/third_party/pkg/angular/lib/tools/parser_generator/generator.dart
@@ -1,8 +1,15 @@
library generator;
-import 'dart_code_gen.dart';
-import '../../core/parser/parser_library.dart';
-import 'source.dart';
+import 'package:angular/core/module.dart';
+import 'package:angular/core/parser/parser.dart';
+import 'package:angular/tools/parser_generator/dart_code_gen.dart';
+
+class NullFilterMap implements FilterMap {
+ call(name) => null;
+ Type operator[](annotation) => null;
+ forEach(fn) { }
+ annotationsFor(type) => null;
+}
class SourcePrinter {
printSrc(src) {
@@ -11,50 +18,69 @@ class SourcePrinter {
}
class ParserGenerator {
- DynamicParser _parser;
- Map<String, bool> _printedFunctions = {};
- GetterSetterGenerator _getters;
- SourceBuilder _ = new SourceBuilder();
- SourcePrinter _prt;
+ final Parser _parser;
+ final DartCodeGen _codegen;
+ final SourcePrinter _printer;
+ ParserGenerator(this._parser, this._codegen, this._printer);
- ParserGenerator(this._parser, this._getters, this._prt);
+ void print(object) {
+ _printer.printSrc('$object');
+ }
generateParser(Iterable<String> expressions) {
- _prt..printSrc("genEvalError(msg) { throw msg; }")
- ..printSrc("functions(FilterLookup filters) => "
- "new StaticParserFunctions(buildExpressions(filters));")
- ..printSrc('var evalError = (text, [s]) => text;')
- ..printSrc("");
- BodySource body = new BodySource();
- MapSource map = new MapSource();
-
- // deterimine the order.
+ print("StaticParserFunctions functions(FilterLookup filters)");
+ print(" => new StaticParserFunctions(");
+ print(" buildEval(filters), buildAssign(filters));");
+ print("");
+
+ // Compute the function maps.
+ Map eval = {};
+ Map assign = {};
expressions.forEach((exp) {
- var code = safeCode(exp);
- map('${_.str(exp)}: ${_.ref(code)}');
- });
- // now do it in actual order
- _.codeRefs.forEach((code) {
- body(_.stmt('Expression ${_.ref(code)} = ', code.toSource(_)));
+ generateCode(exp, eval, assign);
});
- body(_.stmt('return ', map));
- _prt..printSrc("Map<String, Expression> buildExpressions(FilterLookup filters) ${body}")
- ..printSrc("\n")
- ..printSrc(_getters.functions);
+
+ // Generate the code.
+ generateBuildFunction('buildEval', eval);
+ generateBuildFunction('buildAssign', assign);
+ _codegen.getters.helpers.values.forEach(print);
+ _codegen.holders.helpers.values.forEach(print);
+ _codegen.setters.helpers.values.forEach(print);
+ }
+
+ void generateBuildFunction(String name, Map map) {
+ String mapLiteral = map.keys.map((e) => ' "$e": ${map[e]}').join(',\n');
+ print("Map<String, Function> $name(FilterLookup filters) {");
+ print(" return {\n$mapLiteral\n };");
+ print("}");
+ print("");
}
- Code safeCode(String exp) {
+ void generateCode(String exp, Map eval, Map assign) {
+ String escaped = escape(exp);
try {
- return _parser(exp);
+ Expression e = _parser(exp);
+ if (e.isAssignable) assign[escaped] = getCode(e, true);
+ eval[escaped] = getCode(e, false);
} catch (e) {
if ("$e".contains('Parser Error') ||
- "$e".contains('Lexer Error') ||
- "$e".contains('Unexpected end of expression')) {
- return new ThrowCode("'${escape(e.toString())}';");
+ "$e".contains('Lexer Error') ||
+ "$e".contains('Unexpected end of expression')) {
+ eval[escaped] = '"${escape(e.toString())}"';
} else {
rethrow;
}
}
}
+ String getCode(Expression e, bool assign) {
+ String args = assign ? "scope, value" : "scope";
+ String code = _codegen.generate(e, assign);
+ if (e.isChain) {
+ code = code.replaceAll('\n', '\n ');
+ return "($args) {\n $code\n }";
+ } else {
+ return "($args) => $code";
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698