SyntaxElement.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 21 Jun 2013 19:05:40 +0100
branchjv
changeset 13173 e9da2324940d
parent 12431 9f0c59c742d5
parent 12909 7fdc1ff6720c
child 13178 c9bf900fe729
permissions -rw-r--r--
Merged 06656434532b and 71cb8ce508f0 (branch default - CVS HEAD)

"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libtool' }"

Magnitude subclass:#SyntaxElement
	instanceVariableNames:'start stop type value next prev'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-CodeView-Syntax'
!

!SyntaxElement class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
! !

!SyntaxElement class methodsFor:'instance creation'!

from: start to: stop

    ^self new
        start: start;
        stop: stop.

    "Created: / 14-02-2010 / 13:13:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

from: start to: stop type: type

    ^self new
        start: start;
        stop: stop;
        type: type

    "Created: / 14-02-2010 / 14:09:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

from: start to: stop type: type value: value

    ^self new
        start: start;
        stop: stop;
        type: type;
        value: value

    "Created: / 14-02-2010 / 17:41:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

from: start to: stop type: type value: value assigned:assigned

    ^self new
        start: start;
        stop: stop;
        type: type;
        value: value;
        assigned: assigned

    "Created: / 14-02-2010 / 17:41:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!SyntaxElement methodsFor:'accessing'!

firstElementInChain
    |first prev|

    first := self.
    [ (prev := first previousElement) notNil ] whileTrue:[
        first := prev.
    ].
    ^ first

    "Created: / 21-08-2011 / 09:51:35 / cg"
!

lastElementInChain
    |last next|

    last := self.
    [ (next := last nextElement) notNil ] whileTrue:[
        last := next.
    ].
    ^ last
!

next
    ^ next
!

next:aSyntaxElement
    next := aSyntaxElement.
    next prev: self.

    "Modified: / 14-02-2010 / 17:44:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

nextElement
    ^ next

    "Created: / 21-08-2011 / 09:47:11 / cg"
!

nextElement:aSyntaxElement
    next := aSyntaxElement.
    next prev: self.

    "Modified: / 14-02-2010 / 17:44:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 21-08-2011 / 09:47:15 / cg"
!

prev
    ^ prev
!

prev:aSyntaxElement
    prev := aSyntaxElement.
!

previousElement
    ^ prev

    "Created: / 21-08-2011 / 09:47:23 / cg"
!

previousElement:aSyntaxElement
    prev := aSyntaxElement.

    "Created: / 21-08-2011 / 09:47:28 / cg"
!

start
    ^ start
!

start:anInteger
    start := anInteger.
!

stop
    ^ stop
!

stop:anInteger
    stop := anInteger.
!

type
    ^ type
!

type:aSymbol
    type := aSymbol.
!

value
    ^ value
!

value:anObject
    value := anObject.
! !

!SyntaxElement methodsFor:'comparing'!

< anObject
    anObject isNumber ifTrue:[^stop < anObject].
    "/ anObject class == self class ifFalse:[^false].

    ^stop < anObject stop

    "Created: / 14-02-2010 / 13:39:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 27-07-2012 / 21:53:22 / cg"
!

= anObject
    anObject class == self class ifFalse:[^false].

    ^start == (anObject start) and:
        [stop == (anObject stop) and:
            [type == (anObject type)]].

    "Created: / 14-02-2010 / 13:33:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 27-07-2012 / 21:53:24 / cg"
!

hash
    ^start hash bitXor:[stop hash bitXor:[type hash]].

    "Created: / 14-02-2010 / 13:30:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 27-07-2012 / 21:53:28 / cg"
! !

!SyntaxElement methodsFor:'double dispatching'!

lessFromInteger:anInteger
    ^stop < anInteger

    "Created: / 14-02-2010 / 13:49:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 27-07-2012 / 21:53:33 / cg"
! !

!SyntaxElement methodsFor:'printing & storing'!

printOn:aStream
    "append a printed representation if the receiver to the argument, aStream"

    super printOn:aStream.
    aStream nextPutAll:'('.
    type printOn: aStream.
    aStream nextPutAll:' -> '.    
    value printOn:aStream.
    aStream nextPut:$[.
    start printOn:aStream.
    aStream nextPutAll:' .. '.    
    stop printOn:aStream.
    aStream nextPut:$].
    aStream nextPut:$).

    "Modified: / 25-06-2010 / 13:20:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 21-08-2011 / 09:33:51 / cg"
! !

!SyntaxElement methodsFor:'queries'!

isSelector
    ^ type == #selector

    "Created: / 21-08-2011 / 09:09:19 / cg"
!

isSelf
    ^ type == #self

    "Created: / 21-08-2011 / 09:31:20 / cg"
!

isVariable
    ^ false
!

isVariableOrSelf
    ^ self isVariable or:[self isSelf]

    "Created: / 21-08-2011 / 09:31:33 / cg"
! !

!SyntaxElement class methodsFor:'documentation'!

version
    ^ '$Id: SyntaxElement.st 8048 2012-09-07 17:28:09Z vranyj1 $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/SyntaxElement.st,v 1.6 2013-06-14 14:30:48 cg Exp $'
!

version_HG

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

version_SVN
    ^ '$Id: SyntaxElement.st,v 1.6 2013-06-14 14:30:48 cg Exp $'
! !