SmallSense__SmalltalkParseNodeFinder.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 08 Apr 2014 15:03:38 +0200
changeset 191 49c0c66eb21a
parent 184 0da7032dfd5a
child 240 e2277fd8f082
permissions -rw-r--r--
Fix for Smalltalk node finder. Now, comments array contain offsets of start and end of a comment (not start and length, as it used to contain).

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

SmalltalkParseNodeVisitor subclass:#SmalltalkParseNodeFinder
	instanceVariableNames:'position match previous'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Smalltalk'
!


!SmalltalkParseNodeFinder methodsFor:'finding'!

findNodeIn: source tree: tree comments: comments line: line column: col

    | sourceS |
    sourceS := source readStream.
    line - 1 timesRepeat:[
        (sourceS nextLine) isNil ifTrue:[
            "No such line"                                
            ^nil
        ].        
    ].
    ^self findNodeIn: source tree: tree comments: comments position: sourceS position + col

    "Created: / 29-01-2014 / 10:20:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

findNodeIn:source tree:tree comments:comments position:pos 
    | i s e |

    position := pos - 1.
    i := 1.
    [
        i < comments size and:[ (s := comments at:i) notNil ]
    ] whileTrue:[
        e := "s + "(comments at:i + 1) - 1.
        (pos between:s and:e) ifTrue:[
            ^ nil -> pos.
        ].
        i := i + 2.
    ].
    (s notNil and:[ source size == e ]) ifTrue:[ 
        ^ nil -> pos.     
    ].
    self visit:tree.
    ^ (match ? previous) -> pos.

    "Created: / 29-01-2014 / 10:20:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-04-2014 / 14:26:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!SmalltalkParseNodeFinder methodsFor:'visiting'!

visit:anObject 

    anObject isNil ifTrue:[^self].

    (anObject endPosition notNil and:[position > anObject endPosition]) ifTrue:[
        previous := anObject.
        anObject acceptVisitor: self.
        ^self.
    ].

    (anObject startPosition notNil 
        and:[anObject endPosition notNil 
        and:[position between: anObject startPosition and: anObject endPosition]]) ifTrue:[
        match := anObject.
    ].
    anObject acceptVisitor: self.

    "Created: / 26-11-2011 / 15:40:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 19-09-2013 / 11:15:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

visitStatementNode:anObject 

    self visit: anObject expression.
    self visit: anObject nextStatement.

    "Modified: / 25-07-2011 / 22:34:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 26-11-2011 / 15:40:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!SmalltalkParseNodeFinder class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id: SmallSense__SmalltalkParseNodeFinder.st,v 1.2 2014/02/12 14:49:29 sr Exp $'
! !