[squeak-dev] The Inbox: Tools-ct.1130.mcz

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Fri Feb 25 15:15:33 UTC 2022

Hi Nicolas,

thank you for the details. Could you also say something about the Ocompletion question? Can I merge this? =D



Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>
Gesendet: Montag, 14. Februar 2022 09:31:45
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] The Inbox: Tools-ct.1130.mcz

Hi Christoph,

Le lun. 14 févr. 2022 à 01:02, <commits at source.squeak.org<mailto:commits at source.squeak.org>> a écrit :
A new version of Tools was added to project The Inbox:

==================== Summary ====================

Name: Tools-ct.1130
Author: ct
Time: 14 February 2022, 1:02:43.784188 am
UUID: e802d5d5-1c10-1146-9570-47e16bfc1f44
Ancestors: Tools-mt.1129

Fixes selection in SelectorBrowser aka Method Finder when the receiver is a brace array such as in:

        {1. 2. 3}. 1

Also simplies the reparsing logic of the example string slightly.

Inbox because of two open questions:

1) Does this break the selection of "external search results" (see #searchResult:)? It has zero senders in the Trunk and in Ocompletion.

2) Is it a bug that "Scanner new scanTokens: '{1. 2. 3}'" does not answer a single item? If yes, shall we merge this patch anyway as a general refactoring?

IMO it is not a bug.
The scanner only scans for lexical atoms (tokens).
A brace array shall not be parsed at lexical stage because it can contain arbitrarily complex grammatical expressions.
The job of assembling tokens in grammatical expressions belongs to Parser, and Parser does not output a stream of tokens,
it outputs an abstract syntax tree.
The fact that composed literals (literal arrays) can be scanned as atomic tokens could eventually be questioned, since the limit between lexical and grammatical scope is always somehow arbitrary, but it's rather a convenient split of responsibility.


=============== Diff against Tools-mt.1129 ===============

Item was changed:
  ----- Method: SelectorBrowser>>markMatchingClasses (in category 'message list') -----
        "If an example is used, mark classes matching the example instance with an asterisk."

        | unmarkedClassList firstPartOfSelector receiverString receiver |

        self flag: #mref.       "allows for old-fashioned style"

        "Only 'example' queries can be marked."
        (contents asString includes: $.) ifFalse: [^ self].

        unmarkedClassList := classList copy.

        "Get the receiver object of the selected statement in the message list."
+       firstPartOfSelector := self selectedMessageName keywords first.
-       firstPartOfSelector := (Scanner new scanTokens: (selectorList at: selectorIndex)) second.
        receiverString := (ReadStream on: (selectorList at: selectorIndex))
                                                upToAll: firstPartOfSelector.
        receiver := Compiler evaluate: receiverString.

        unmarkedClassList do: [ :classAndMethod | | class |
                (classAndMethod isKindOf: MethodReference) ifTrue: [
                        (receiver isKindOf: classAndMethod actualClass) ifTrue: [
                                classAndMethod stringVersion: '*', classAndMethod stringVersionDefault.
                ] ifFalse: [
                        class := Compiler evaluate:
                                        ((ReadStream on: classAndMethod) upToAll: firstPartOfSelector).
                        (receiver isKindOf: class) ifTrue: [
                                classList add: '*', classAndMethod.
                                classList remove: classAndMethod

Item was changed:
  ----- Method: SelectorBrowser>>quickList (in category 'selector finding') -----
        "Compute the selectors for the single example of receiver and args, in the very top pane"

        | data result resultArray dataStrings mf dataObjects aa statements |
        data := contents asString withBlanksTrimmed.
        mf := MethodFinder new.
        data := mf cleanInputs: data.   "remove common mistakes"
        dataObjects := Compiler evaluate: '{', data, '}'. "#( data1 data2 result )"
        statements := (Compiler new parse: 'zort ' , data in: Object notifying: nil)
                                body statements select: [:each | (each isKindOf: ReturnNode) not].
        dataStrings := statements collect:
                                [:node | String streamContents:
                                        [:strm | (node isMessage) ifTrue: [strm nextPut: $(].
                                        node shortPrintOn: strm.
                                        (node isMessage) ifTrue: [strm nextPut: $)].]].
        dataObjects size < 2 ifTrue: [self inform: 'If you are giving an example of receiver, \args, and result, please put periods between the parts.\Otherwise just type one selector fragment' withCRs. ^#()].
        dataObjects := Array with: dataObjects allButLast with: dataObjects last. "#( (data1
    data2) result )"
        result := mf load: dataObjects; findMessage.
        (result first beginsWith: 'no single method') ifFalse: [
                aa := self testObjects: dataObjects strings: dataStrings.
                dataObjects := aa second.  dataStrings := aa third].
        resultArray := self listFromResult: result.
        resultArray isEmpty ifTrue: [self inform: result first].

        dataStrings size = (dataObjects first size + 1) ifTrue:
                [resultArray := resultArray collect: [:expression | | newExp |
                newExp := expression.
                dataObjects first withIndexDo: [:lit :i |
                        newExp := newExp copyReplaceAll: 'data', i printString
                                                        with: (dataStrings at: i)].
+               newExp, self resultSeparator, dataStrings last]].
-               newExp, ' --> ', dataStrings last]].

        ^ resultArray!

Item was added:
+ ----- Method: SelectorBrowser>>resultSeparator (in category 'private') -----
+ resultSeparator
+       ^ ' --> '!

Item was changed:
  ----- Method: SelectorBrowser>>selectedMessageName (in category 'accessing') -----
        "Answer the name of the currently selected message or nil if not a known Symbol."

+       | example expression |
-       | example tokens |
        selectorIndex = 0 ifTrue: [^nil].
        example := selectorList at: selectorIndex.
+       example isSymbol ifTrue: [^ example].
+       expression := example first: (example findLastOccurrenceOfString: self resultSeparator startingAt: 1) - 1.
+       ^ expression findSelector!
-       tokens := Scanner new scanTokens: example.
-       tokens size = 1 ifTrue: [^ tokens first].
-       tokens first == #'^' ifTrue: [^ nil].
-       (tokens second includes: $:) ifTrue: [^ example findSelector].
-       ^Symbol lookup: tokens second!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220225/fc7c2f84/attachment.html>

More information about the Squeak-dev mailing list