comparison tpc.js @ 44:9dd370530f69

Fix escape codes in string literals. Don't print out the return value of main method. Fixup fib example to use print: method. Cleanup error handling in compiler slightly
author Mike Pavone <pavone@retrodev.com>
date Thu, 12 Jul 2012 22:49:08 -0700
parents 27a2167663dd
children 2a9c6eed0c70
comparison
equal deleted inserted replaced
43:27a2167663dd 44:9dd370530f69
18 load('cbackend.js'); 18 load('cbackend.js');
19 try { 19 try {
20 var parsed = parser.parse(text); 20 var parsed = parser.parse(text);
21 var c = parsed.toCModule(); 21 var c = parsed.toCModule();
22 print(c); 22 print(c);
23 } catch(error) { 23 } catch(error if error.name == 'SyntaxError') {
24 if (error.name == 'SyntaxError') { 24 print('SyntaxError on at', error.line, ',', error.column, ':', error.message);
25 print('SyntaxError on at', error.line, ',', error.column, ':', error.message); 25 var lines = text.split('\n');
26 var lines = text.split('\n'); 26 print(lines[error.line-1]);
27 print(lines[error.line-1]); 27 var spacer = '';
28 var spacer = ''; 28 for (var i = 1; i < error.column; i++) {
29 for (var i = 1; i < error.column; i++) { 29 if (lines[error.line-1].charAt(i-1) == '\t') {
30 if (lines[error.line-1].charAt(i-1) == '\t') { 30 spacer += ' ';
31 spacer += ' '; 31 } else {
32 } else { 32 spacer += ' ';
33 spacer += ' ';
34 }
35 }
36 print(spacer + '^');
37 } else {
38 print("Exception:");
39 var keys = Object.keys(error);
40 for (var i = 0; i < keys.length; ++i) {
41 print('\t', keys[i], error[keys[i]]);
42 } 33 }
43 } 34 }
35 print(spacer + '^');
36
44 } 37 }
45 } 38 }