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

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

Issue 180843004: Revert revision 33053 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library generator; 1 library generator;
2 2
3 import 'package:angular/core/module.dart'; 3 import 'package:angular/core/module.dart';
4 import 'package:angular/core/parser/parser.dart'; 4 import 'package:angular/core/parser/parser.dart';
5 import 'package:angular/tools/parser_generator/dart_code_gen.dart'; 5 import 'package:angular/tools/parser_generator/dart_code_gen.dart';
6 6
7 class NullFilterMap implements FilterMap { 7 class NullFilterMap implements FilterMap {
8 call(name) => null; 8 call(name) => null;
9 Type operator[](annotation) => null; 9 Type operator[](annotation) => null;
10 forEach(fn) { } 10 forEach(fn) { }
(...skipping 10 matching lines...) Expand all
21 final Parser _parser; 21 final Parser _parser;
22 final DartCodeGen _codegen; 22 final DartCodeGen _codegen;
23 final SourcePrinter _printer; 23 final SourcePrinter _printer;
24 ParserGenerator(this._parser, this._codegen, this._printer); 24 ParserGenerator(this._parser, this._codegen, this._printer);
25 25
26 void print(object) { 26 void print(object) {
27 _printer.printSrc('$object'); 27 _printer.printSrc('$object');
28 } 28 }
29 29
30 generateParser(Iterable<String> expressions) { 30 generateParser(Iterable<String> expressions) {
31 print("StaticParserFunctions functions()"); 31 print("StaticParserFunctions functions(FilterLookup filters)");
32 print(" => new StaticParserFunctions("); 32 print(" => new StaticParserFunctions(");
33 print(" buildEval(), buildAssign());"); 33 print(" buildEval(filters), buildAssign(filters));");
34 print(""); 34 print("");
35 35
36 // Compute the function maps. 36 // Compute the function maps.
37 Map eval = {}; 37 Map eval = {};
38 Map assign = {}; 38 Map assign = {};
39 expressions.forEach((exp) { 39 expressions.forEach((exp) {
40 generateCode(exp, eval, assign); 40 generateCode(exp, eval, assign);
41 }); 41 });
42 42
43 // Generate the code. 43 // Generate the code.
44 generateBuildFunction('buildEval', eval); 44 generateBuildFunction('buildEval', eval);
45 generateBuildFunction('buildAssign', assign); 45 generateBuildFunction('buildAssign', assign);
46 _codegen.getters.helpers.values.forEach(print); 46 _codegen.getters.helpers.values.forEach(print);
47 _codegen.holders.helpers.values.forEach(print); 47 _codegen.holders.helpers.values.forEach(print);
48 _codegen.setters.helpers.values.forEach(print); 48 _codegen.setters.helpers.values.forEach(print);
49 } 49 }
50 50
51 void generateBuildFunction(String name, Map map) { 51 void generateBuildFunction(String name, Map map) {
52 String mapLiteral = map.keys.map((e) => ' "$e": ${map[e]}').join(',\n'); 52 String mapLiteral = map.keys.map((e) => ' "$e": ${map[e]}').join(',\n');
53 print("Map<String, Function> $name() {"); 53 print("Map<String, Function> $name(FilterLookup filters) {");
54 print(" return {\n$mapLiteral\n };"); 54 print(" return {\n$mapLiteral\n };");
55 print("}"); 55 print("}");
56 print(""); 56 print("");
57 } 57 }
58 58
59 void generateCode(String exp, Map eval, Map assign) { 59 void generateCode(String exp, Map eval, Map assign) {
60 String escaped = escape(exp); 60 String escaped = escape(exp);
61 try { 61 try {
62 Expression e = _parser(exp); 62 Expression e = _parser(exp);
63 if (e.isAssignable) assign[escaped] = getCode(e, true); 63 if (e.isAssignable) assign[escaped] = getCode(e, true);
64 eval[escaped] = getCode(e, false); 64 eval[escaped] = getCode(e, false);
65 } catch (e) { 65 } catch (e) {
66 if ("$e".contains('Parser Error') || 66 if ("$e".contains('Parser Error') ||
67 "$e".contains('Lexer Error') || 67 "$e".contains('Lexer Error') ||
68 "$e".contains('Unexpected end of expression')) { 68 "$e".contains('Unexpected end of expression')) {
69 eval[escaped] = '"${escape(e.toString())}"'; 69 eval[escaped] = '"${escape(e.toString())}"';
70 } else { 70 } else {
71 rethrow; 71 rethrow;
72 } 72 }
73 } 73 }
74 } 74 }
75 75
76 String getCode(Expression e, bool assign) { 76 String getCode(Expression e, bool assign) {
77 String args = assign ? "scope, value" : "scope, filters"; 77 String args = assign ? "scope, value" : "scope";
78 String code = _codegen.generate(e, assign); 78 String code = _codegen.generate(e, assign);
79 if (e.isChain) { 79 if (e.isChain) {
80 code = code.replaceAll('\n', '\n '); 80 code = code.replaceAll('\n', '\n ');
81 return "($args) {\n $code\n }"; 81 return "($args) {\n $code\n }";
82 } else { 82 } else {
83 return "($args) => $code"; 83 return "($args) => $code";
84 } 84 }
85 } 85 }
86 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698