SmallSense__SmalltalkParseNodeFinder.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 24 Sep 2013 02:14:28 +0100
changeset 101 a300290bf8fc
parent 98 SmallSense__Finder.st@c21c3e61a377
child 104 3b05b2d777dd
permissions -rw-r--r--
Classes renamed to better express theit purpose.

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

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


!SmalltalkParseNodeFinder methodsFor:'finding'!

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

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

    "Created: / 26-11-2011 / 15:33:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

findNodeIn: source tree: tree position: pos

    position := pos - 1.
    self visit: tree.
    ^Position node: match ? previous position: pos.

    "Created: / 26-11-2011 / 15:37:16 / 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: SmallSenseFinder.st 7823 2011-11-26 16:55:59Z vranyj1 $'
! !