'From Squeak3.1alpha of 5 February 2001 [latest update: #3621] on 16 February 2001 at 7:41:51 pm'! "Change Set: suntax3 Date: 16 February 2001 Author: Bob Arning adds some variants to universal tiles. browse the method SyntaxMorph>>wordyTestMethod and get a tile scriptor for it to see an example of how behind-the-scenes source becomes pretty tiles."! !Object methodsFor: 'scripting' stamp: 'RAA 2/16/2001 19:37'! selfWrittenAsIll ^self! ! !Object methodsFor: 'scripting' stamp: 'RAA 2/16/2001 19:38'! selfWrittenAsIm ^self! ! !Object methodsFor: 'scripting' stamp: 'RAA 2/16/2001 19:37'! selfWrittenAsMe ^self! ! !Object methodsFor: 'scripting' stamp: 'RAA 2/16/2001 19:37'! selfWrittenAsMy ^self! ! !Object methodsFor: 'scripting' stamp: 'RAA 2/16/2001 19:38'! selfWrittenAsThis ^self! ! !SyntaxMorph methodsFor: 'printing' stamp: 'RAA 2/16/2001 18:13'! printOn: strm indent: level | lev nodeClass parens cnt | "Tree walk and produce text of the code. #ST80. Just do it in one big ugly method." lev _ level. (nodeClass _ parseNode class) == BlockNode ifTrue: [ owner isSyntaxMorph ifTrue: [ owner isMethodNode ifFalse: [strm nextPut: $[. lev _ lev+1]]]. "normal block has []" nodeClass == VariableNode ifTrue: ["nil out any old association" parseNode key class == Association ifTrue: [ parseNode name: (parseNode name) key: nil code: (parseNode code)]]. (nodeClass == MessageNode or: [nodeClass == CascadeNode]) ifTrue: [ parseNode receiver ifNotNil: [parens _ true. strm nextPut: $( ]]. "has a receiver" nodeClass == MethodTempsNode ifTrue: [strm nextPut: $|; space]. cnt _ 0. submorphs do: [:sub | sub isSyntaxMorph ifTrue: [cnt _ cnt + 1. (nodeClass == CascadeNode "and: [sub isCascadePart]") ifTrue: [cnt > 2 ifTrue: [strm nextPutAll: '; ']]. nodeClass == BlockArgsNode ifTrue: [strm nextPut: $:]. sub printOn: strm indent: lev. "<<<<### install the subnode" (nodeClass == BlockNode) & (sub parseNode class == BlockArgsNode) not & (sub parseNode class == ReturnNode) not ifTrue: [strm nextPut: $.]. (nodeClass == BlockNode) & (sub parseNode class == BlockArgsNode) not ifTrue: [strm crtab: lev] ifFalse: [self isMethodNode ifTrue: [strm crtab: lev] ifFalse: [strm space]]. ]. (sub isKindOf: StringMorph) ifTrue: [ self printSimpleStringMorph: sub on: strm ]. "return indent for ifTrue: ifFalse:"]. parens == true ifTrue: [strm nextPut: $) ]. "has a receiver" nodeClass == BlockNode ifTrue: [ owner isSyntaxMorph ifTrue: [ owner isMethodNode ifFalse: [strm nextPut: $] ]]]. "normal block has []" nodeClass == BlockArgsNode ifTrue: [strm nextPut: $|; crtab: lev]. nodeClass == MethodTempsNode ifTrue: [strm nextPut: $|; crtab: lev]. nodeClass == MethodNode ifTrue: [ strm contents last "ugh!!" == $. ifTrue: [strm skip: -1]]. "erase last period"! ! !SyntaxMorph methodsFor: 'printing' stamp: 'RAA 2/16/2001 18:16'! printSimpleStringMorph: aMorph on: strm | trialContents | (aMorph hasProperty: #wordyVariantOfSelf) ifTrue: [ strm nextPutAll: 'self '. strm nextPutAll: ((self translateToWordySelfVariant: aMorph contents) ifNil: [^self]). ^self ]. (aMorph hasProperty: #noiseWord) ifFalse: [ trialContents _ self cleanUpString: aMorph. strm nextPutAll: trialContents ]. ! ! !SyntaxMorph methodsFor: 'node to morph' stamp: 'RAA 2/16/2001 17:49'! constructSelfVariant: receiver and: key | wordy | (receiver isKindOf: VariableNode) ifFalse: [^nil]. receiver name = 'self' ifFalse: [^nil]. (wordy _ self translateFromWordySelfVariant: key) ifNil: [^nil]. ^wordy ! ! !SyntaxMorph methodsFor: 'node to morph' stamp: 'RAA 2/16/2001 19:35'! messageNode: aNode receiver: receiver selector: selector keywords: key arguments: args | keywords column row receiverMorph firstArgMorph receiverWidth messageWidth onlyOne nodeWithNilReceiver isAConditional testAndReceiver anotherSelf wordyMorph | isAConditional _ #(ifTrue: ifFalse: ifTrue:ifFalse: ifFalse:ifTrue:) includes: key. receiver ifNotNil: ["i.e. not a cascade" anotherSelf _ self constructSelfVariant: receiver and: key. anotherSelf ifNotNil: [ wordyMorph _ self addString: anotherSelf. wordyMorph setProperty: #wordyVariantOfSelf toValue: true. self addMorph: wordyMorph. self layoutInset: 1. ^self ]. testAndReceiver _ self. self specialBlockFormatting ifTrue: [ isAConditional ifTrue: [ testAndReceiver _ self addRow: #keyword1 on: nil. self specialColor: (Color r: 1.0 g: 0.935 b: 0.774) andBorder: (Color r: 0.581 g: 0.774 b: 0.903). self useRoundedCorners. self layoutInset: 6. self setProperty: #variableInsetSize toValue: 6. testAndReceiver addNoiseString: 'Test' ]. ]. receiverMorph _ receiver asMorphicSyntaxIn: testAndReceiver. self specialBlockFormatting ifTrue: [ isAConditional ifTrue: [self setConditionalPartStyle: receiverMorph]. ]. ]. keywords _ key keywords. args size = 0 ifTrue: [ row _ (self addSingleKeywordRow: key) layoutInset: 1. ^ row parseNode: selector ]. receiverWidth _ receiver ifNil: [0] ifNotNil: [receiverMorph fullBounds width]. onlyOne _ args size = 1. (receiverWidth <= 80 and: [onlyOne]) ifTrue: [ row _ (self addSingleKeywordRow: keywords first) layoutInset: 1. row parseNode: selector. firstArgMorph _ args first asMorphicSyntaxIn: self. receiver ifNil: [^ self]. (firstArgMorph fullBounds height > 100 or: [firstArgMorph fullBounds width > 250]) ifTrue: [self foldMessageOneArg]. ^ self ]. nodeWithNilReceiver _ aNode copy receiver: nil. isAConditional & self specialBlockFormatting ifTrue: [ self listDirection: #topToBottom. ]. column _ self addColumn: #keyword1 on: nodeWithNilReceiver. messageWidth _ 0. keywords with: (args copyFrom: 1 to: keywords size) do: [:kwd :arg | isAConditional ifTrue: [ column addMorphBack: (column transparentSpacerOfSize: 3@3). ]. (row _ column addRow: #keyword2 on: nodeWithNilReceiver) borderWidth: 1; parseNode: (nodeWithNilReceiver as: (onlyOne ifTrue: [MessageNode] ifFalse: [MessagePartNode])); borderColor: row stdBorderColor. isAConditional ifTrue: [row addMorphBack: (row transparentSpacerOfSize: 20@6)]. row addToken: kwd type: #keyword2 on: (onlyOne ifTrue: [SelectorNode new key: kwd code: nil "fill this in?"] ifFalse: [KeyWordNode new]). arg asMorphicSyntaxIn: row. messageWidth _ messageWidth + row fullBounds width]. receiverMorph ifNil: [^self]. self alansTest1 ifTrue: [^self]. receiverWidth + messageWidth < 350 ifTrue: [ isAConditional ifFalse: [self unfoldMessage]. ^self ]. ((receiverWidth > 200 or: [receiverWidth > 80 and: [column fullBounds height > 20]]) or: [receiverMorph fullBounds width > 30 and: [column fullBounds height > 100 or: [column fullBounds width > 250]]]) ifTrue: [^ self foldMessage]! ! !SyntaxMorph methodsFor: 'node to morph' stamp: 'RAA 2/16/2001 17:48'! translateFromWordySelfVariant: key #selfWrittenAsMe == key ifTrue: [^'me']. #selfWrittenAsMy == key ifTrue: [^'my']. #selfWrittenAsIll == key ifTrue: [^'I''ll']. #selfWrittenAsIm == key ifTrue: [^'I''m']. #selfWrittenAsThis == key ifTrue: [^'this']. ^nil ! ! !SyntaxMorph methodsFor: 'node to morph' stamp: 'RAA 2/16/2001 18:06'! translateToWordySelfVariant: aString | lc | lc _ aString asLowercase. lc = 'me' ifTrue: [^#selfWrittenAsMe]. lc = 'my' ifTrue: [^#selfWrittenAsMy]. lc = 'i''ll' ifTrue: [^#selfWrittenAsIll]. lc = 'i''m' ifTrue: [^#selfWrittenAsIm]. lc = 'this' ifTrue: [^#selfWrittenAsThis]. ^nil ! ! !SyntaxMorph methodsFor: 'node to morph' stamp: 'RAA 2/16/2001 19:32'! wordyTestMethod self selfWrittenAsMe = 1 ifTrue: [ self selfWrittenAsMy size. self selfWrittenAsIll stop. self selfWrittenAsIm large. self selfWrittenAsThis helps. ]. ! !