Parser.st
changeset 265 a8617dc49bbf
parent 263 3b21d0991eff
child 273 2758f1723f53
--- a/Parser.st	Thu Apr 25 19:50:04 1996 +0200
+++ b/Parser.st	Sat Apr 27 20:07:21 1996 +0200
@@ -849,7 +849,7 @@
     ^ parser
 
     "Created: 24.4.1996 / 13:13:06 / cg"
-    "Modified: 24.4.1996 / 13:31:41 / cg"
+    "Modified: 27.4.1996 / 16:58:02 / cg"
 !
 
 parseMethodArgAndVarSpecificationSilent:aString
@@ -2432,91 +2432,82 @@
      empty (or comment only) input is accepted and returns nil.
 
      methodBodyOrNil ::= '<' st80Primitive '>'
-			 | '<' st80Primitive '>' methodBodyVarSpec statementList
-			 | <empty>
+                         | '<' st80Primitive '>' methodBodyVarSpec statementList
+                         | <empty>
     "
 
-    |stats pos wmsg|
-
-    ((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[
-	"an ST-80 primitive - parsed but ignored"
-	pos := tokenPosition.
-	self nextToken.
-	primitiveNr := self parseST80Primitive.
-	(primitiveNr == #Error) ifTrue:[^ #Error].
-	primitiveNr < 0 ifTrue:[
-	    WarnST80Directives == true ifTrue:[
-		wmsg := 'ST-80 directive ignored'.
-	    ].
-	    primitiveNr := nil.
-	] ifFalse:[
-	    wmsg := 'ST-80 primitive may not work'
-	].
-	wmsg notNil ifTrue:[self warning:wmsg position:pos]
-    ].
+    |stats|
 
     (self parseMethodBodyVarSpec == #Error) ifTrue:[^ #Error].
 
     (tokenType ~~ #EOF) ifTrue:[
-	stats := self statementList
+        stats := self statementList
     ].
     ^ stats
+
+    "Modified: 27.4.1996 / 16:57:56 / cg"
 !
 
 parseMethodBodyVarSpec
-    "parse a methods local variable specification. 
+    "parse a methods local variable specification, handling
+     possible primitive or resourceSpecs.
+     . 
      Leave spec of locals in methodLocals as a side effect.
      Return #Error or nil.
 
      methodBodyVarSpec ::= '|' { IDENTIFIER } '|'
-			    | <empty>
+                            | <empty>
     "
 
     |var pos msg|
 
+    ((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[
+        self parsePrimitiveOrResourceSpecOrEmpty.
+    ].
+
     (tokenType == $|) ifTrue:[
-	"memorize position for declaration in correction"
-	localVarDefPosition := tokenPosition.
-	self nextToken.
-	pos := tokenPosition.
-	[tokenType == #Identifier] whileTrue:[
-	    var := Variable name:tokenName.
-	    methodVars isNil ifTrue:[
-		methodVars := Array with:var.
-		methodVarNames := Array with:tokenName
-	    ] ifFalse:[
-		(methodVarNames includes:tokenName) ifTrue:[
-		    self parseError:'redefinition of ''' , tokenName , ''' in local variables'
-			   position:tokenPosition to:tokenPosition + tokenName size -1.
-		] ifFalse:[
-		    methodVars := methodVars copyWith:var.
-		    methodVarNames := methodVarNames copyWith:tokenName
-		]
-	    ].
-	    methodArgNames notNil ifTrue:[
-		(methodArgNames includes:tokenName) ifTrue:[
-		    self warning:'local variable ''' , tokenName , ''' hides argument.'
-			position:tokenPosition 
-			      to:(tokenPosition + tokenName size - 1)
-		]
-	    ].
-	    self nextToken.
-	    pos := tokenPosition
-	].
-	(tokenType ~~ $|) ifTrue:[
-	    (#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[
-		msg := 'Reserved keyword in local var declaration' 
-	    ] ifFalse:[
-		msg := 'Identifier or | expected in local var declaration' 
-	    ].
-	    self syntaxError:msg position:tokenPosition to:source position-1.
-	    ^ #Error
-	].
-	self nextToken
+        "memorize position for declaration in correction"
+        localVarDefPosition := tokenPosition.
+        self nextToken.
+        pos := tokenPosition.
+        [tokenType == #Identifier] whileTrue:[
+            var := Variable name:tokenName.
+            methodVars isNil ifTrue:[
+                methodVars := Array with:var.
+                methodVarNames := Array with:tokenName
+            ] ifFalse:[
+                (methodVarNames includes:tokenName) ifTrue:[
+                    self parseError:'redefinition of ''' , tokenName , ''' in local variables'
+                           position:tokenPosition to:tokenPosition + tokenName size -1.
+                ] ifFalse:[
+                    methodVars := methodVars copyWith:var.
+                    methodVarNames := methodVarNames copyWith:tokenName
+                ]
+            ].
+            methodArgNames notNil ifTrue:[
+                (methodArgNames includes:tokenName) ifTrue:[
+                    self warning:'local variable ''' , tokenName , ''' hides argument.'
+                        position:tokenPosition 
+                              to:(tokenPosition + tokenName size - 1)
+                ]
+            ].
+            self nextToken.
+            pos := tokenPosition
+        ].
+        (tokenType ~~ $|) ifTrue:[
+            (#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[
+                msg := 'Reserved keyword in local var declaration' 
+            ] ifFalse:[
+                msg := 'Identifier or | expected in local var declaration' 
+            ].
+            self syntaxError:msg position:tokenPosition to:source position-1.
+            ^ #Error
+        ].
+        self nextToken
     ].
     ^ nil
 
-    "Modified: 18.11.1995 / 16:32:51 / cg"
+    "Modified: 27.4.1996 / 16:58:28 / cg"
 !
 
 parseMethodSpec
@@ -2584,6 +2575,31 @@
     "Modified: 20.4.1996 / 20:05:52 / cg"
 !
 
+parsePrimitiveOrResourceSpecOrEmpty
+    "parse a methods primitive or resource spec"
+
+    |pos wmsg|
+
+    ((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[
+        "an ST-80 primitive - parsed but ignored"
+        pos := tokenPosition.
+        self nextToken.
+        primitiveNr := self parseST80Primitive.
+        (primitiveNr == #Error) ifTrue:[^ #Error].
+        primitiveNr < 0 ifTrue:[
+            WarnST80Directives == true ifTrue:[
+                wmsg := 'ST-80 directive ignored'.
+            ].
+            primitiveNr := nil.
+        ] ifFalse:[
+            wmsg := 'ST-80 primitive may not work'
+        ].
+        wmsg notNil ifTrue:[self warning:wmsg position:pos]
+    ].
+
+    "Created: 27.4.1996 / 16:55:55 / cg"
+!
+
 parseST80Primitive
     "parse an ST-80 type primitive as '< primitive: nr >';
      return primitive number or #Error.
@@ -3451,6 +3467,6 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.77 1996-04-25 17:05:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.78 1996-04-27 18:06:40 cg Exp $'
 ! !
 Parser initialize!