About text in method body

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

About text in method body

stephane ducasse
HI guys

I was wondering if it would not make sense to only use String to store code.
Then I was wondering if how we could decouple Text* from the RunnArray implementation
Because RunArray>>scanFrom: basically links all the Text to RunArray

I was thinking to simply use a RunArray subclass and specialze its scanFrom:
It may also means that RunArray should not be packaged in CollectionArrayed but with Collection-Text.


scanFrom: strm
        "Read the style section of a fileOut or sources file.  nextChunk has already been done.  We need to return a RunArray of TextAttributes of various kinds.  These are written by the implementors of writeScanOn:"
        | rr vv aa this |
        (strm peekFor: $( ) ifFalse: [^ nil].
        rr := OrderedCollection new.
        [strm skipSeparators.
         strm peekFor: $)] whileFalse:
                [rr add: (Number readFrom: strm)].
        vv := OrderedCollection new. "Value array"
        aa := OrderedCollection new. "Attributes list"
        [(this := strm next) == nil] whileFalse: [
                this == $, ifTrue: [vv add: aa asArray.  aa := OrderedCollection new].
                this == $a ifTrue: [aa add:
                        (TextAlignment new alignment: (Integer readFrom: strm ifFail: [0]))].
                this == $f ifTrue: [aa add:
                        (TextFontChange new fontNumber: (Integer readFrom: strm ifFail: [0]))].
                this == $F ifTrue: [aa add: (TextFontReference toFont:
                        (Smalltalk at: #StrikeFont ifPresent: [:sf | sf familyName: (strm upTo: $#) size: (Integer readFrom: strm ifFail: [0])]))].
                this == $b ifTrue: [aa add: (TextEmphasis bold)].
                this == $i ifTrue: [aa add: (TextEmphasis italic)].
                this == $u ifTrue: [aa add: (TextEmphasis underlined)].
                this == $= ifTrue: [aa add: (TextEmphasis struckOut)].
                this == $n ifTrue: [aa add: (TextEmphasis normal)].
                this == $- ifTrue: [aa add: (TextKern kern: -1)].
                this == $+ ifTrue: [aa add: (TextKern kern: 1)].
                this == $c ifTrue: [aa add: (TextColor scanFrom: strm)]. "color"
                this == $L ifTrue: [aa add: (TextLink scanFrom: strm)]. "L not look like 1"
                this == $R ifTrue: [aa add: (TextURL scanFrom: strm)].
                                "R capitalized so it can follow a number"
                this == $P ifTrue: [aa add: (TextPrintIt scanFrom: strm)].
                this == $d ifTrue: [aa add: (TextDoIt scanFrom: strm)].
                "space, cr do nothing"
                ].
        aa size > 0 ifTrue: [vv add: aa asArray].
        ^ self runs: rr asArray values: vv asArray
"
RunArray scanFrom: (ReadStream on: '(14 50 312)f1,f1b,f1LInteger +;i')
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        "


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About text in method body

Alexandre Bergel
> Because RunArray>>scanFrom: basically links all the Text to RunArray

Indeed. Actually, RunArray class>>scanFrom: seems to be used as an utility method. It can perfectly be moved into a different package (as soon as the caller are updated).

Alexandre


>
> I was thinking to simply use a RunArray subclass and specialze its scanFrom:
> It may also means that RunArray should not be packaged in CollectionArrayed but with Collection-Text.
>
>
> scanFrom: strm
> "Read the style section of a fileOut or sources file.  nextChunk has already been done.  We need to return a RunArray of TextAttributes of various kinds.  These are written by the implementors of writeScanOn:"
> | rr vv aa this |
> (strm peekFor: $( ) ifFalse: [^ nil].
> rr := OrderedCollection new.
> [strm skipSeparators.
> strm peekFor: $)] whileFalse:
> [rr add: (Number readFrom: strm)].
> vv := OrderedCollection new. "Value array"
> aa := OrderedCollection new. "Attributes list"
> [(this := strm next) == nil] whileFalse: [
> this == $, ifTrue: [vv add: aa asArray.  aa := OrderedCollection new].
> this == $a ifTrue: [aa add:
> (TextAlignment new alignment: (Integer readFrom: strm ifFail: [0]))].
> this == $f ifTrue: [aa add:
> (TextFontChange new fontNumber: (Integer readFrom: strm ifFail: [0]))].
> this == $F ifTrue: [aa add: (TextFontReference toFont:
> (Smalltalk at: #StrikeFont ifPresent: [:sf | sf familyName: (strm upTo: $#) size: (Integer readFrom: strm ifFail: [0])]))].
> this == $b ifTrue: [aa add: (TextEmphasis bold)].
> this == $i ifTrue: [aa add: (TextEmphasis italic)].
> this == $u ifTrue: [aa add: (TextEmphasis underlined)].
> this == $= ifTrue: [aa add: (TextEmphasis struckOut)].
> this == $n ifTrue: [aa add: (TextEmphasis normal)].
> this == $- ifTrue: [aa add: (TextKern kern: -1)].
> this == $+ ifTrue: [aa add: (TextKern kern: 1)].
> this == $c ifTrue: [aa add: (TextColor scanFrom: strm)]. "color"
> this == $L ifTrue: [aa add: (TextLink scanFrom: strm)]. "L not look like 1"
> this == $R ifTrue: [aa add: (TextURL scanFrom: strm)].
> "R capitalized so it can follow a number"
> this == $P ifTrue: [aa add: (TextPrintIt scanFrom: strm)].
> this == $d ifTrue: [aa add: (TextDoIt scanFrom: strm)].
> "space, cr do nothing"
> ].
> aa size > 0 ifTrue: [vv add: aa asArray].
> ^ self runs: rr asArray values: vv asArray
> "
> RunArray scanFrom: (ReadStream on: '(14 50 312)f1,f1b,f1LInteger +;i')
> "
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.






_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About text in method body

Stéphane Ducasse
probably.
I should check.

On Jul 21, 2010, at 4:08 PM, Alexandre Bergel wrote:

>> Because RunArray>>scanFrom: basically links all the Text to RunArray
>
> Indeed. Actually, RunArray class>>scanFrom: seems to be used as an utility method. It can perfectly be moved into a different package (as soon as the caller are updated).
>
> Alexandre
>
>
>>
>> I was thinking to simply use a RunArray subclass and specialze its scanFrom:
>> It may also means that RunArray should not be packaged in CollectionArrayed but with Collection-Text.
>>
>>
>> scanFrom: strm
>> "Read the style section of a fileOut or sources file.  nextChunk has already been done.  We need to return a RunArray of TextAttributes of various kinds.  These are written by the implementors of writeScanOn:"
>> | rr vv aa this |
>> (strm peekFor: $( ) ifFalse: [^ nil].
>> rr := OrderedCollection new.
>> [strm skipSeparators.
>> strm peekFor: $)] whileFalse:
>> [rr add: (Number readFrom: strm)].
>> vv := OrderedCollection new. "Value array"
>> aa := OrderedCollection new. "Attributes list"
>> [(this := strm next) == nil] whileFalse: [
>> this == $, ifTrue: [vv add: aa asArray.  aa := OrderedCollection new].
>> this == $a ifTrue: [aa add:
>> (TextAlignment new alignment: (Integer readFrom: strm ifFail: [0]))].
>> this == $f ifTrue: [aa add:
>> (TextFontChange new fontNumber: (Integer readFrom: strm ifFail: [0]))].
>> this == $F ifTrue: [aa add: (TextFontReference toFont:
>> (Smalltalk at: #StrikeFont ifPresent: [:sf | sf familyName: (strm upTo: $#) size: (Integer readFrom: strm ifFail: [0])]))].
>> this == $b ifTrue: [aa add: (TextEmphasis bold)].
>> this == $i ifTrue: [aa add: (TextEmphasis italic)].
>> this == $u ifTrue: [aa add: (TextEmphasis underlined)].
>> this == $= ifTrue: [aa add: (TextEmphasis struckOut)].
>> this == $n ifTrue: [aa add: (TextEmphasis normal)].
>> this == $- ifTrue: [aa add: (TextKern kern: -1)].
>> this == $+ ifTrue: [aa add: (TextKern kern: 1)].
>> this == $c ifTrue: [aa add: (TextColor scanFrom: strm)]. "color"
>> this == $L ifTrue: [aa add: (TextLink scanFrom: strm)]. "L not look like 1"
>> this == $R ifTrue: [aa add: (TextURL scanFrom: strm)].
>> "R capitalized so it can follow a number"
>> this == $P ifTrue: [aa add: (TextPrintIt scanFrom: strm)].
>> this == $d ifTrue: [aa add: (TextDoIt scanFrom: strm)].
>> "space, cr do nothing"
>> ].
>> aa size > 0 ifTrue: [vv add: aa asArray].
>> ^ self runs: rr asArray values: vv asArray
>> "
>> RunArray scanFrom: (ReadStream on: '(14 50 312)f1,f1b,f1LInteger +;i')
>> "
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
> --
> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
> Alexandre Bergel  http://www.bergel.eu
> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>
>
>
>
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project