Pārlūkot izejas kodu

Actually catch compiler errors.

Herbert Vojčík 7 gadi atpakaļ
vecāks
revīzija
5bbb6a85d4
2 mainītis faili ar 60 papildinājumiem un 33 dzēšanām
  1. 51 24
      src/IDE.js
  2. 9 9
      src/IDE.st

+ 51 - 24
src/IDE.js

@@ -3253,7 +3253,7 @@ var compiler,package_,method,compiledSource,source,node;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$5,$4,$3,$6,$8,$7,$receiver;
+var $1,$2,$4,$3,$8,$7,$6,$5,$receiver;
 var $early={};
 try {
 source=$recv(self["@sourceArea"])._val();
@@ -3269,46 +3269,73 @@ compiler=$recv($globals.Compiler)._new();
 $ctx1.sendIdx["new"]=1;
 //>>excludeEnd("ctx");
 $recv(compiler)._source_(source);
+$recv((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
 node=$recv(compiler)._parse_(source);
-$2=$recv(node)._isParseFailure();
-if($core.assert($2)){
-$5="PARSE ERROR: ".__comma($recv(node)._reason());
+return node;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx[","]=3;
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
 //>>excludeEnd("ctx");
-$4=$recv($5).__comma(", position: ");
+}))._on_do_($globals.ParseError,(function(e){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx[","]=2;
+return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$3=$recv($4).__comma($recv($recv(node)._position())._asString());
+$2="PARSE ERROR: ".__comma($recv(e)._messageText());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx[","]=1;
+$ctx2.sendIdx[","]=1;
+//>>excludeEnd("ctx");
+throw $early=[$recv($globals.Terminal)._alert_($2)];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1,3)});
+//>>excludeEnd("ctx");
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["on:do:"]=1;
 //>>excludeEnd("ctx");
-return $recv($globals.Terminal)._alert_($3);
-}
 package_=$recv(aClass)._packageOfProtocol_(self["@selectedProtocol"]);
+$recv((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
 compiledSource=$recv(compiler)._compileNode_forClass_package_(node,aClass,package_);
-method=$recv(compiler)._eval_forPackage_(compiledSource,package_);
-$recv($recv(compiler)._unknownVariables())._do_((function(each){
+return compiledSource;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,4)});
+//>>excludeEnd("ctx");
+}))._on_do_($globals.UnknownVariableError,(function(e){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$6=$recv($globals.Smalltalk)._existsJsGlobal_(each);
-if(!$core.assert($6)){
-$8=$recv("Declare '".__comma(each)).__comma("' as instance variable?");
+$4=$recv(e)._variableName();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx[","]=4;
+$ctx2.sendIdx["variableName"]=1;
 //>>excludeEnd("ctx");
-$7=$recv($globals.Terminal)._confirm_($8);
-if($core.assert($7)){
-self._addInstanceVariableNamed_toClass_(each,aClass);
+$3=$recv($globals.Smalltalk)._existsJsGlobal_($4);
+if(!$core.assert($3)){
+$8=$recv(e)._variableName();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["variableName"]=2;
+//>>excludeEnd("ctx");
+$7="Declare '".__comma($8);
+$6=$recv($7).__comma("' as instance variable?");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx[","]=2;
+//>>excludeEnd("ctx");
+$5=$recv($globals.Terminal)._confirm_($6);
+if($core.assert($5)){
+self._addInstanceVariableNamed_toClass_($recv(e)._variableName(),aClass);
 throw $early=[self._compileMethodDefinitionFor_(aClass)];
+} else {
+throw $early=[nil];
 }
 }
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,3)});
+}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1,5)});
 //>>excludeEnd("ctx");
 }));
+method=$recv(compiler)._eval_forPackage_(compiledSource,package_);
 $recv($recv($globals.ClassBuilder)._new())._installMethod_forClass_protocol_(method,aClass,self["@selectedProtocol"]);
 self._updateMethodsList();
 self._selectMethod_(method);
@@ -3321,10 +3348,10 @@ catch(e) {if(e===$early)return e[0]; throw e}
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aClass"],
-source: "compileMethodDefinitionFor: aClass\x0a\x09| compiler package method compiledSource source node |\x0a\x09source := sourceArea val.\x0a\x09selectedProtocol ifNil: [ selectedProtocol := selectedMethod protocol ].\x0a\x09compiler := Compiler new.\x0a\x09compiler source: source.\x0a\x09node := compiler parse: source.\x0a\x09node isParseFailure ifTrue: [\x0a\x09^ Terminal alert: 'PARSE ERROR: ', node reason, ', position: ', node position asString ].\x0a\x09package := aClass packageOfProtocol: selectedProtocol.\x0a\x09compiledSource := compiler compileNode: node forClass: aClass package: package.\x0a\x09method := compiler eval: compiledSource forPackage: package.\x0a\x09compiler unknownVariables do: [ :each |\x0a\x09\x09\x22Do not try to redeclare javascript's objects\x22\x0a\x09\x09(Smalltalk existsJsGlobal: each) ifFalse: [\x0a\x09\x09(Terminal confirm: 'Declare ''', each, ''' as instance variable?') ifTrue: [\x0a\x09\x09\x09self addInstanceVariableNamed: each toClass: aClass.\x0a\x09\x09\x09^ self compileMethodDefinitionFor: aClass ]] ].\x0a\x09ClassBuilder new installMethod: method forClass: aClass protocol: selectedProtocol.\x0a\x09self updateMethodsList.\x0a\x09self selectMethod: method",
-referencedClasses: ["Compiler", "Terminal", "Smalltalk", "ClassBuilder"],
+source: "compileMethodDefinitionFor: aClass\x0a\x09| compiler package method compiledSource source node |\x0a\x09source := sourceArea val.\x0a\x09selectedProtocol ifNil: [ selectedProtocol := selectedMethod protocol ].\x0a\x09compiler := Compiler new.\x0a\x09compiler source: source.\x0a\x09[ node := compiler parse: source ]\x0a\x09on: ParseError do: [ :e |\x0a\x09^ Terminal alert: 'PARSE ERROR: ', e messageText ].\x0a\x09package := aClass packageOfProtocol: selectedProtocol.\x0a\x09[ compiledSource := compiler compileNode: node forClass: aClass package: package ]\x0a\x09on: UnknownVariableError do: [ :e |\x0a\x09\x09\x22Do not try to redeclare javascript's objects\x22\x0a\x09\x09(Smalltalk existsJsGlobal: e variableName) ifFalse: [\x0a\x09\x09(Terminal confirm: 'Declare ''', e variableName, ''' as instance variable?') ifFalse: [ ^ nil ] ifTrue: [\x0a\x09\x09\x09self addInstanceVariableNamed: e variableName toClass: aClass.\x0a\x09\x09\x09^ self compileMethodDefinitionFor: aClass ]] ].\x0a\x09method := compiler eval: compiledSource forPackage: package.\x0a\x09ClassBuilder new installMethod: method forClass: aClass protocol: selectedProtocol.\x0a\x09self updateMethodsList.\x0a\x09self selectMethod: method",
+referencedClasses: ["Compiler", "ParseError", "Terminal", "UnknownVariableError", "Smalltalk", "ClassBuilder"],
 //>>excludeEnd("ide");
-messageSends: ["val", "ifNil:", "protocol", "new", "source:", "parse:", "ifTrue:", "isParseFailure", "alert:", ",", "reason", "asString", "position", "packageOfProtocol:", "compileNode:forClass:package:", "eval:forPackage:", "do:", "unknownVariables", "ifFalse:", "existsJsGlobal:", "confirm:", "addInstanceVariableNamed:toClass:", "compileMethodDefinitionFor:", "installMethod:forClass:protocol:", "updateMethodsList", "selectMethod:"]
+messageSends: ["val", "ifNil:", "protocol", "new", "source:", "on:do:", "parse:", "alert:", ",", "messageText", "packageOfProtocol:", "compileNode:forClass:package:", "ifFalse:", "existsJsGlobal:", "variableName", "ifFalse:ifTrue:", "confirm:", "addInstanceVariableNamed:toClass:", "compileMethodDefinitionFor:", "eval:forPackage:", "installMethod:forClass:protocol:", "updateMethodsList", "selectMethod:"]
 }),
 $globals.Browser);
 

+ 9 - 9
src/IDE.st

@@ -827,18 +827,18 @@ compileMethodDefinitionFor: aClass
 	selectedProtocol ifNil: [ selectedProtocol := selectedMethod protocol ].
 	compiler := Compiler new.
 	compiler source: source.
-	node := compiler parse: source.
-	node isParseFailure ifTrue: [
-	^ Terminal alert: 'PARSE ERROR: ', node reason, ', position: ', node position asString ].
+	[ node := compiler parse: source ]
+	on: ParseError do: [ :e |
+	^ Terminal alert: 'PARSE ERROR: ', e messageText ].
 	package := aClass packageOfProtocol: selectedProtocol.
-	compiledSource := compiler compileNode: node forClass: aClass package: package.
-	method := compiler eval: compiledSource forPackage: package.
-	compiler unknownVariables do: [ :each |
+	[ compiledSource := compiler compileNode: node forClass: aClass package: package ]
+	on: UnknownVariableError do: [ :e |
 		"Do not try to redeclare javascript's objects"
-		(Smalltalk existsJsGlobal: each) ifFalse: [
-		(Terminal confirm: 'Declare ''', each, ''' as instance variable?') ifTrue: [
-			self addInstanceVariableNamed: each toClass: aClass.
+		(Smalltalk existsJsGlobal: e variableName) ifFalse: [
+		(Terminal confirm: 'Declare ''', e variableName, ''' as instance variable?') ifFalse: [ ^ nil ] ifTrue: [
+			self addInstanceVariableNamed: e variableName toClass: aClass.
 			^ self compileMethodDefinitionFor: aClass ]] ].
+	method := compiler eval: compiledSource forPackage: package.
 	ClassBuilder new installMethod: method forClass: aClass protocol: selectedProtocol.
 	self updateMethodsList.
 	self selectMethod: method