'From Squeak3.1alpha of 5 February 2001 [latest update: #4134] on 5 June 2001 at 11:58:05 am'! "Change Set: preCodeComments Date: 5 June 2001 Author: Bob Arning Some aids for Scott's documentation efforts: (1) Have the spell-checker, when adding new temporary variables, insert the temps declaration *after* any initial precode comment the method may have. (2) Make #firstPrecodeCommentFor: return the first comment found in the method before the actual code begins, whether that comment precedes or follow the temps declaration. "! !Behavior methodsFor: 'accessing method dictionary' stamp: 'RAA 6/5/2001 11:02'! firstPrecodeCommentFor: selector | parser source tree | "If there is a comment in the source code at the given selector that preceeds the body of the method, return it here, else return nil" "Behavior firstPrecodeCommentFor: #firstPrecodeCommentFor:" source _ self sourceCodeAt: selector. parser _ self parserClass new. tree _ parser parse: (ReadStream on: source) class: self noPattern: false context: nil notifying: nil ifFail: [^ nil]. ^(tree comment ifNil: [^nil]) first ! ! !Parser methodsFor: 'expression types' stamp: 'RAA 6/5/2001 11:46'! temporaries " [ '|' (variable)* '|' ]" | vars theActualText | (self match: #verticalBar) ifFalse: ["no temps" doitFlag ifTrue: [ requestor ifNil: [ tempsMark _ 1 ] ifNotNil: [ tempsMark _ requestor selectionInterval first ]. ^ #() ]. tempsMark _ hereMark "formerly --> prevMark + prevToken". tempsMark > 0 ifTrue: [theActualText _ source contents. [tempsMark < theActualText size and: [(theActualText at: tempsMark) isSeparator]] whileTrue: [tempsMark _ tempsMark + 1]]. ^ #() ]. vars _ OrderedCollection new. [hereType == #word] whileTrue: [vars addLast: (encoder bindTemp: self advance)]. (self match: #verticalBar) ifTrue: [tempsMark _ prevMark. ^ vars]. ^ self expected: 'Vertical bar'! ! !Parser methodsFor: 'error correction' stamp: 'RAA 6/5/2001 11:57'! declareTempAndPaste: name | insertion delta theTextString characterBeforeMark | theTextString _ requestor text string. characterBeforeMark _ theTextString at: tempsMark-1 ifAbsent: [$ ]. (theTextString at: tempsMark) = $| ifTrue: [ "Paste it before the second vertical bar" insertion _ name, ' '. characterBeforeMark isSeparator ifFalse: [ insertion _ ' ', insertion]. delta _ 0. ] ifFalse: [ "No bars - insert some with CR, tab" insertion _ '| ' , name , ' |',String cr. delta _ 2. "the bar and CR" characterBeforeMark = Character tab ifTrue: [ insertion _ insertion , String tab. delta _ delta + 1. "the tab" ]. ]. tempsMark _ tempsMark + (self substituteWord: insertion wordInterval: (tempsMark to: tempsMark-1) offset: 0) - delta. ^ encoder bindAndJuggle: name! !