added #parseExpression:onError: protocol.
authorClaus Gittinger <cg@exept.de>
Fri, 13 Oct 2000 20:25:47 +0200
changeset 1096 d1d897aba4d5
parent 1095 8963fe0f984f
child 1097 65771cba5456
added #parseExpression:onError: protocol.
Parser.st
--- a/Parser.st	Fri Oct 13 14:41:36 2000 +0200
+++ b/Parser.st	Fri Oct 13 20:25:47 2000 +0200
@@ -1151,14 +1151,19 @@
      Error and warning messages are suppressed."
 
     ^ self 
-	withSelf:nil 
-	parseExpression:aString 
-	notifying:nil 
-	ignoreErrors:true       "silence on Transcript"
-	ignoreWarnings:true
-	inNameSpace:nil
-
-    "Modified: 24.6.1997 / 16:44:00 / cg"
+        withSelf:nil 
+        parseExpression:aString 
+        onError:#Error
+        notifying:nil 
+        ignoreErrors:true       "silence on Transcript"
+        ignoreWarnings:true
+        inNameSpace:nil
+
+    "
+     Parser parseExpression:'self foo'
+     Parser parseExpression:'self:123'
+     Parser parseExpression:'self:123' onError:nil
+    "
 !
 
 parseExpression:aString inNameSpace:aNameSpaceOrNil
@@ -1168,17 +1173,55 @@
      Error and warning messages are suppressed."
 
     ^ self 
-	withSelf:nil 
-	parseExpression:aString 
-	notifying:nil 
-	ignoreErrors:true       "silence on Transcript"
-	ignoreWarnings:true
-	inNameSpace:aNameSpaceOrNil
+        withSelf:nil 
+        parseExpression:aString 
+        onError:#Error
+        notifying:nil 
+        ignoreErrors:true       "silence on Transcript"
+        ignoreWarnings:true
+        inNameSpace:aNameSpaceOrNil
 
     "Modified: 24.6.1997 / 16:44:00 / cg"
     "Created: 24.6.1997 / 16:44:26 / cg"
 !
 
+parseExpression:aString inNameSpace:aNameSpaceOrNil onError:errorValue
+    "parse aString as an expression; 
+     Return the parseTree (if ok), nil (for an empty string 
+     or comment only) or errorValue (syntactic error).
+     Error and warning messages are suppressed."
+
+    ^ self 
+        withSelf:nil 
+        parseExpression:aString 
+        onError:errorValue
+        notifying:nil 
+        ignoreErrors:true       "silence on Transcript"
+        ignoreWarnings:true
+        inNameSpace:aNameSpaceOrNil
+
+    "Modified: 24.6.1997 / 16:44:00 / cg"
+    "Created: 24.6.1997 / 16:44:26 / cg"
+!
+
+parseExpression:aString onError:errorValue
+    "parse aString as an expression; 
+     Return the parseTree (if ok), nil (for an empty string 
+     or comment only) or errorValue (syntactic error).
+     Error and warning messages are suppressed."
+
+    ^ self 
+        withSelf:nil 
+        parseExpression:aString 
+        onError:errorValue
+        notifying:nil 
+        ignoreErrors:true       "silence on Transcript"
+        ignoreWarnings:true
+        inNameSpace:nil
+
+    "Modified: 24.6.1997 / 16:44:00 / cg"
+!
+
 parseMethod:aString
     "parse a method.
      Return a parser (if ok), nil (empty) or #Error (syntax).
@@ -1551,12 +1594,13 @@
      codeView) which can highlight it and show a popup box."
 
     ^ self 
-	withSelf:anObject 
-	parseExpression:aString 
-	notifying:someOne 
-	ignoreErrors:false 
-	ignoreWarnings:false 
-	inNameSpace:nil
+        withSelf:anObject 
+        parseExpression:aString 
+        onError:#Error
+        notifying:someOne 
+        ignoreErrors:false 
+        ignoreWarnings:false 
+        inNameSpace:nil
 
     "Modified: 24.6.1997 / 16:43:37 / cg"
 !
@@ -1570,12 +1614,13 @@
      codeView) which can highlight it and show a popup box."
 
     ^ self 
-	withSelf:anObject
-	parseExpression:aString 
-	notifying:someOne 
-	ignoreErrors:ignore 
-	ignoreWarnings:ignore 
-	inNameSpace:nil
+        withSelf:anObject
+        parseExpression:aString 
+        onError:#Error
+        notifying:someOne 
+        ignoreErrors:ignore 
+        ignoreWarnings:ignore 
+        inNameSpace:nil
 
     "Modified: 24.6.1997 / 16:43:26 / cg"
 !
@@ -1590,12 +1635,13 @@
      iff ignoreErrors/ignoreWarnings is true respectively."
 
     ^ self
-	withSelf:anObject 
-	parseExpression:aString 
-	notifying:someOne 
-	ignoreErrors:ignoreErrors 
-	ignoreWarnings:ignoreWarnings 
-	inNameSpace:nil
+        withSelf:anObject 
+        parseExpression:aString
+        onError:#Error
+        notifying:someOne 
+        ignoreErrors:ignoreErrors 
+        ignoreWarnings:ignoreWarnings 
+        inNameSpace:nil
 
     "Modified: 24.6.1997 / 16:43:12 / cg"
 !
@@ -1609,17 +1655,40 @@
      codeView) which can highlight it and show a popup box,
      iff ignoreErrors/ignoreWarnings is true respectively."
 
-    |parser|
+    ^ self
+        withSelf:anObject 
+        parseExpression:aString 
+        onError:#Error 
+        notifying:someOne 
+        ignoreErrors:ignoreErrors 
+        ignoreWarnings:ignoreWarnings 
+        inNameSpace:aNameSpaceOrNil
+!
+
+withSelf:anObject parseExpression:aString onError:errorValue notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings inNameSpace:aNameSpaceOrNil
+    "parse aString as an expression with self set to anObject;
+     Return the parseTree (if ok), nil (for an empty string 
+     or comment only ) or errorValue (syntactic error).
+
+     Errors and warnings are forwarded to someOne (usually some
+     codeView) which can highlight it and show a popup box,
+     iff ignoreErrors/ignoreWarnings is true respectively."
+
+    |parser tree|
 
     aString isNil ifTrue:[^ nil].
 
     parser := self for:(ReadStream on:aString).
-    ^ parser 
+    tree := parser 
         parseExpressionWithSelf:anObject 
         notifying:someOne 
         ignoreErrors:ignoreErrors 
         ignoreWarnings:ignoreWarnings 
         inNameSpace:aNameSpaceOrNil.
+    tree == #Error ifTrue:[
+        ^ errorValue value
+    ].
+    ^ tree
 
     "Modified: / 14.12.1999 / 15:12:16 / cg"
 ! !
@@ -5622,6 +5691,6 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.266 2000-09-26 13:44:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.267 2000-10-13 18:25:47 cg Exp $'
 ! !
 Parser initialize!