binary selectors ambiguity and space

nicolas cellier ncellier at ifrance.com
Mon May 15 20:27:33 UTC 2006


Le Lundi 15 Mai 2006 20:42, Stephan Rudlof a écrit :
> On 15.05.2006 20:25, I wrote:
> >...
> >
> > On 13.05.2006 02:10, nicolas cellier wrote:
> > nc>...
> > nc> Funny, in current 3.9 spaces are ignored:
> > nc> i have '1 +-   2' interpreted as (1) + (-2)
> >
> > At least, if there should be a change in the semantics - for e.g.
> > allowing selector #+- in the case above -, it would be *much* better to
> > fail loading a package instead of loading it silently: otherwise the
> > code would just break at runtime!
>
> After sending this comment I've seen, that this example is far from the
>   x+-1
> case: so for such a semantic change there should be
> - an announcement,
> - a code snippet for scanning the code for cases, where the semantics is
> announced to be changed.
>
> Since after changing the semantics this way, the above would not have
> any ambiguity, and therefore it would be loaded smoothly...
>
>
> Regards,
> Stephan

Notification subclass: #PrefixUnarySelectorNotification
   instanceVariableNames: ''
   classVariableNames: ''
   poolDictionaries: ''
   category: 'Exceptions-Kernel'

Scanner>>primaryExpression 
   hereType == #word 
      ifTrue: 
         [parseNode := self variable.
         (parseNode isUndefTemp and: [self interactive])
            ifTrue: [self queryUndefined].
         parseNode nowHasRef.
         ^ true].
   hereType == #leftBracket
      ifTrue: 
         [self advance.
         self blockExpression.
         ^true].
   hereType == #leftBrace
      ifTrue: 
         [self braceExpression.
         ^true].
   hereType == #leftParenthesis
      ifTrue: 
         [self advance.
         self expression ifFalse: [^self expected: 'expression'].
         (self match: #rightParenthesis)
            ifFalse: [^self expected: 'right parenthesis'].
         ^true].
   (hereType == #string or: [hereType == #number or: [hereType == #literal]])
      ifTrue: 
         [parseNode := encoder encodeLiteral: self advance.
         ^true].
   (here == #- and: [tokenType == #number])
      ifTrue: 
         [self advance.
         "not very clean hack to check for space.
         beside, hereMark/prevMark are broken at end of stream"
         hereMark > (prevMark+1) ifTrue: [PrefixUnarySelectorNotification
               signal: '- is used as unary prefixed selector'].
         parseNode := encoder encodeLiteral: self advance negated.
         ^true].
   ^false


| report |
report := (String new: 128) writeStream.
Smalltalk keysAndValuesDo: [:name :cls |
   (cls isKindOf: Behavior)
      ifTrue: [(Array with: cls with: cls class)
         do: [:class | class selectorsDo: [:selector |
            [class compilerClass new
               parse: (class sourceCodeAt: selector)
               in: class notifying: nil]
            on: PrefixUnarySelectorNotification
            do: [:exc |
               report
                  print: class; nextPutAll: #'>>';
                  nextPutAll: selector; cr]]]]].
report contents inspect.

It was not that easy, because handling is done lately, with two tokens of 
advance...
I didn't find anything in 3.9a7029... So, this must be quite unusual.
Would be funny to scan a Monticello repository or SqueakMap...
(above my skills).

Nicolas




More information about the Squeak-dev mailing list