SmallSense__SmalltalkParser.st
changeset 174 3e08d765d86f
parent 96 12fe1a59dfd1
child 176 df6d3225d1e4
--- a/SmallSense__SmalltalkParser.st	Tue Nov 19 13:02:56 2013 +0000
+++ b/SmallSense__SmalltalkParser.st	Wed Feb 26 19:06:00 2014 +0100
@@ -3,13 +3,19 @@
 "{ NameSpace: SmallSense }"
 
 SyntaxHighlighter subclass:#SmalltalkParser
-	instanceVariableNames:'errorRecovery error'
+	instanceVariableNames:'errorRecovery error commentPositions commentIndex'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SmallSense-Smalltalk'
 !
 
 
+!SmalltalkParser methodsFor:'accessing'!
+
+commentPositions
+    ^ commentPositions
+! !
+
 !SmalltalkParser methodsFor:'error handling'!
 
 parseError:message position:startPos to:endPos
@@ -35,9 +41,13 @@
 
 initialize
     super initialize.
-    errorRecovery := true
+    errorRecovery := true.
+    commentPositions := Array new: 16.
+    commentIndex := -1.
+    saveComments := true.
 
     "Created: / 19-09-2013 / 11:25:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-01-2014 / 10:38:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SmalltalkParser methodsFor:'parsing'!
@@ -152,6 +162,20 @@
     "Created: / 09-07-2011 / 22:23:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+parseMethod:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings
+    "parse a method in a given class.
+     Return a parser (if ok), nil (empty) or #Error (syntax).
+     The parser can be queried for selector, receiver, args, locals,
+     used selectors, modified instvars, referenced classvars etc.
+     The noErrors and noWarnings arguments specify if error and warning
+     messages should be sent to the Transcript or suppressed."
+
+    self sourceText: aString copy asText.
+    ^ super parseMethod:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings
+
+    "Created: / 03-02-2014 / 16:15:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 statement
     "parse a statement; return a node-tree or #Error.
 
@@ -498,10 +522,36 @@
 
 !SmalltalkParser methodsFor:'private'!
 
+beginComment
+    commentIndex := commentIndex + 2.
+    (commentPositions size) < (commentIndex + 1) ifTrue:[ 
+        | newPositions |
+
+        newPositions := Array new: commentPositions size + 16.
+        newPositions replaceFrom: 1 with: commentPositions.
+        commentPositions := newPositions.
+    ].
+    commentPositions at: commentIndex put: source position.
+
+    "Created: / 29-01-2014 / 10:13:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+endComment: comment
+    commentPositions at: commentIndex + 1 put: comment size.
+
+    "Created: / 29-01-2014 / 10:14:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+endComment: comment type: type
+    ^ self endComment: comment
+
+    "Created: / 29-01-2014 / 10:14:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 findNameSpaceWith:varName
     | ns |
 
-    "The super #findNameSpaceWith: checks whether the the gloval named 'varName' exists,
+    "The super #findNameSpaceWith: checks whether the the global named 'varName' exists,
      if not, returns the current namespace which is then prepended to 'varName'.
 
      Here we have to deal with uncomplete global names, so trick the caller by returning
@@ -517,14 +567,15 @@
     ^ super findNameSpaceWith:varName
 
     "Created: / 28-07-2013 / 13:49:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 29-01-2014 / 10:04:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SmalltalkParser methodsFor:'syntax coloring'!
 
 markBracketAt:pos
 
-    sourceText isNil ifTrue:[^self].
-    ^super markBracketAt:pos
+    pos > sourceText size ifTrue:[^self].
+    super markBracketAt:pos
 
     "Created: / 03-04-2011 / 22:39:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
@@ -553,6 +604,6 @@
 !
 
 version_SVN
-    ^ '$Id: SmallSenseParser.st 7922 2012-03-09 07:57:34Z vranyj1 $'
+    ^ '$Id: SmallSense__SmalltalkParser.st,v 1.3 2014/02/26 18:00:07 cg Exp $'
 ! !