#UI_ENHANCEMENT by cg
authorClaus Gittinger <cg@exept.de>
Thu, 30 May 2019 19:08:40 +0200
changeset 4427 de1012adb310
parent 4426 49123df91ffa
child 4428 a04104250af7
#UI_ENHANCEMENT by cg class: Parser changed: #checkForEndOfInput #primary better error message for unexpected EOF
Parser.st
--- a/Parser.st	Thu May 30 19:07:34 2019 +0200
+++ b/Parser.st	Thu May 30 19:08:40 2019 +0200
@@ -5876,7 +5876,7 @@
             ] ifFalse:[
                 what := tokenType printString allBold.
             ].
-            msg := 'Nothing more expected (i.e. ',what, ' unexpected.'.
+            msg := 'Nothing more expected (i.e. ',what,' unexpected)'.
             endPos := source position.
         ].
         self parseError:msg position:tokenPosition to:endPos.
@@ -5884,6 +5884,7 @@
     ]
 
     "Modified: / 22-08-2006 / 14:22:45 / cg"
+    "Modified: / 30-05-2019 / 14:50:05 / Claus Gittinger"
 !
 
 emptyStatement
@@ -7712,7 +7713,7 @@
     "parse a primary-expression; return a node-tree, nil or #Error.
      This also cares for namespace-access-paths."
 
-    |val pos node eMsg endPos parenStart parenStartLine|
+    |val pos node eMsg endPos startPos parenStart parenStartLine|
 
     (tokenType == #Self) ifTrue:[
         ^ self primary_self.
@@ -7899,7 +7900,7 @@
 
     (tokenType == #Primitive) ifTrue:[
         node := PrimitiveNode code:tokenValue.
-        node startPosition: tokenPosition endPosition: source position + 1.
+        node startPosition: tokenPosition endPosition:(source position + 1).
         self nextToken.
         hasNonOptionalPrimitiveCode := true.
         hasPrimitiveCode := true.
@@ -8008,28 +8009,36 @@
     ].    
     
     (tokenType == #Error) ifTrue:[^ #Error].
-    tokenType isCharacter ifTrue:[
-        eMsg := '"',tokenType printString,'" unexpected in primary.'.
+
+    startPos := tokenPosition.
+    tokenType == #EOF ifTrue:[
+        eMsg := 'unexpected EOF in primary.'.
+        startPos := tokenPosition-1.
         endPos := tokenPosition.
-    ] ifFalse:[
-        (#(BinaryOperator Keyword) includes:tokenType) ifTrue:[
-            eMsg := tokenType printString,' ("' , tokenName , '") ',' unexpected in primary. (missing receiver ?)'
+    ] ifFalse:[    
+        tokenType isCharacter ifTrue:[
+            eMsg := '"',tokenType printString,'" unexpected in primary.'.
+            endPos := tokenPosition.
         ] ifFalse:[
-            (#(Integer Float) includes:tokenType) ifTrue:[
-                eMsg := tokenType printString,' (' , tokenValue , ') ',' unexpected in primary. (missing receiver ?)'
+            (#(BinaryOperator Keyword) includes:tokenType) ifTrue:[
+                eMsg := tokenType printString,' ("' , tokenName , '") ',' unexpected in primary. (missing receiver ?)'
             ] ifFalse:[
-                eMsg := '"',(token ? ''),'" (',tokenType printString,') unexpected in primary.'
-            ]
-        ].
-        endPos :=source position.
-    ].
-    self syntaxError:eMsg position:tokenPosition to:endPos.
+                (#(Integer Float) includes:tokenType) ifTrue:[
+                    eMsg := tokenType printString,' (' , tokenValue , ') ',' unexpected in primary. (missing receiver ?)'
+                ] ifFalse:[
+                    eMsg := '"',(token ? ''),'" (',tokenType printString,') unexpected in primary.'
+                ]
+            ].
+            endPos :=source position.
+        ].
+    ].
+    self syntaxError:eMsg position:startPos to:endPos.
     ^ #Error
 
     "Created: / 13-09-1995 / 12:50:50 / claus"
     "Modified: / 01-08-2011 / 12:04:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 26-07-2012 / 11:35:46 / cg"
-    "Modified: / 22-05-2019 / 20:58:09 / Claus Gittinger"
+    "Modified: / 30-05-2019 / 14:54:56 / Claus Gittinger"
 !
 
 primary_dolphinComputedLiteral