The Trunk: Compiler-ar.137.mcz

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

The Trunk: Compiler-ar.137.mcz

commits-2
Andreas Raab uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-ar.137.mcz

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

Name: Compiler-ar.137
Author: ar
Time: 24 March 2010, 1:25:23.067 am
UUID: 090fc365-fe3c-6741-a731-3222d6ab6afa
Ancestors: Compiler-nice.136

Underscore assignments and underscore selector preferences and implementation. The defaults are set to be compatible with past usage, i.e., allowUnderscoreAssignment is true and allowUnderscoreSelectors is false. Might consider changing this after 4.1.

=============== Diff against Compiler-nice.136 ===============

Item was added:
+ ----- Method: Scanner>>allowUnderscoreSelectors (in category 'private') -----
+ allowUnderscoreSelectors
+ "Query preference"
+ ^self class prefAllowUnderscoreSelectors!

Item was changed:
  ----- Method: Scanner class>>initialize (in category 'initialization') -----
  initialize
  | newTable |
  newTable := Array new: 256 withAll: #xBinary. "default"
  newTable atAll: #(9 10 12 13 32 ) put: #xDelimiter. "tab lf ff cr space"
  newTable atAll: ($0 asciiValue to: $9 asciiValue) put: #xDigit.
 
  1 to: 255
  do: [:index |
  (Character value: index) isLetter
  ifTrue: [newTable at: index put: #xLetter]].
 
  newTable at: 30 put: #doIt.
  newTable at: $" asciiValue put: #xDoubleQuote.
  newTable at: $# asciiValue put: #xLitQuote.
  newTable at: $$ asciiValue put: #xDollar.
  newTable at: $' asciiValue put: #xSingleQuote.
  newTable at: $: asciiValue put: #xColon.
  newTable at: $( asciiValue put: #leftParenthesis.
  newTable at: $) asciiValue put: #rightParenthesis.
  newTable at: $. asciiValue put: #period.
  newTable at: $; asciiValue put: #semicolon.
  newTable at: $[ asciiValue put: #leftBracket.
  newTable at: $] asciiValue put: #rightBracket.
  newTable at: ${ asciiValue put: #leftBrace.
  newTable at: $} asciiValue put: #rightBrace.
  newTable at: $^ asciiValue put: #upArrow.
+ newTable at: $_ asciiValue put: #xUnderscore.
- newTable at: $_ asciiValue put: #leftArrow.
  newTable at: $| asciiValue put: #verticalBar.
  TypeTable := newTable "bon voyage!!"
 
  "Scanner initialize"!

Item was added:
+ ----- Method: Parser>>allowUnderscoreAssignments (in category 'private') -----
+ allowUnderscoreAssignments
+ "Query class + preference"
+ ^encoder classEncoding allowUnderscoreAssignments
+ ifNil:[super allowUnderscoreAssignments]!

Item was added:
+ ----- Method: Scanner>>allowUnderscoreAssignments (in category 'private') -----
+ allowUnderscoreAssignments
+ "Query preference"
+ ^self class prefAllowUnderscoreAssignments!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreAssignments: (in category 'preferences') -----
+ prefAllowUnderscoreAssignments: aBool
+ "Accessor for the system-wide preference"
+ AllowUnderscoreAssignments := aBool!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreAssignments (in category 'preferences') -----
+ prefAllowUnderscoreAssignments
+ "Accessor for the system-wide preference"
+ <preference: 'Allow underscore assignments'
+ category: 'Compiler'
+ description: 'When true, underscore can be used as assignment operator'
+ type: #Boolean>
+ ^AllowUnderscoreAssignments ifNil:[true]!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreSelectors: (in category 'preferences') -----
+ prefAllowUnderscoreSelectors: aBool
+ "Accessor for the system-wide preference"
+ AllowUnderscoreSelectors := aBool!

Item was changed:
  ----- Method: Scanner>>xUnderscore (in category 'multi-character scans') -----
  xUnderscore
+ self allowUnderscoreAssignments ifTrue:[ | type |
+ "Figure out if x _foo (no space between _ and foo)
+ should be a selector or assignment"
+ (((type := self typeTableAt: aheadChar) == #xLetter
+ or:[type == #xDigit or:[type == #xUnderscore]])
+ and:[self allowUnderscoreSelectors]) ifFalse:[
+ self step.
+ tokenType := #leftArrow.
+ ^token := #':='
+ ].
+ ].
+ self allowUnderscoreSelectors ifTrue:[^self xLetter].
+ ^self xIllegal
+ !
- Preferences allowUnderscoreAssignment ifFalse:[^self xIllegal].
- self step.
- tokenType := #leftArrow.
- ^token := #':='!

Item was changed:
  ----- Method: Scanner>>xLetter (in category 'multi-character scans') -----
  xLetter
  "Form a word or keyword."
 
  | type |
  buffer reset.
+ [(type := self typeTableAt: hereChar) == #xLetter
+ or: [type == #xDigit
+ or: [type == #xUnderscore and:[self allowUnderscoreSelectors]]]] whileTrue:
- [(type := self typeTableAt: hereChar) == #xLetter or: [type == #xDigit]]
- whileTrue:
  ["open code step for speed"
  buffer nextPut: hereChar.
  hereChar := aheadChar.
  aheadChar := source atEnd
  ifTrue: [30 asCharacter "doit"]
  ifFalse: [source next]].
  tokenType := (type == #colon or: [type == #xColon and: [aheadChar ~~ $=]])
  ifTrue:
  [buffer nextPut: self step.
  "Allow any number of embedded colons in literal symbols"
  [(self typeTableAt: hereChar) == #xColon] whileTrue:
  [buffer nextPut: self step].
  #keyword]
  ifFalse:
  [type == #leftParenthesis
  ifTrue:
  [buffer nextPut: self step; nextPut: $).
  #positionalMessage]
  ifFalse:[#word]].
  token := buffer contents!

Item was changed:
  Object subclass: #Scanner
  instanceVariableNames: 'source mark hereChar aheadChar token tokenType currentComment buffer typeTable'
+ classVariableNames: 'AllowUnderscoreAssignments AllowUnderscoreSelectors TypeTable'
- classVariableNames: 'TypeTable'
  poolDictionaries: ''
  category: 'Compiler-Kernel'!
 
  !Scanner commentStamp: '<historical>' prior: 0!
  I scan a string or text, picking out Smalltalk syntactic tokens. I look one character ahead. I put each token found into the instance variable, token, and its type (a Symbol) into the variable, tokenType. At the end of the input stream, I pretend to see an endless sequence of special characters called doits.!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreSelectors (in category 'preferences') -----
+ prefAllowUnderscoreSelectors
+ "Accessor for the system-wide preference"
+ <preference: 'Allow underscore selectors'
+ category: 'Compiler'
+ description: 'When true, underscore can be used in selectors and varibable names'
+ type: #Boolean>
+ ^AllowUnderscoreSelectors ifNil:[false]!

Item was added:
+ ----- Method: Parser>>allowUnderscoreSelectors (in category 'private') -----
+ allowUnderscoreSelectors
+ "Query class + preference"
+ ^encoder classEncoding allowUnderscoreSelectors
+ ifNil:[super allowUnderscoreSelectors]!


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Compiler-ar.137.mcz

laza
There is (still?) an allowUnderscoreAssignment preference setting in the compiler (lowercase) category from Parser>>initialize?

Alex

On Wed, Mar 24, 2010 at 09:25, <[hidden email]> wrote:
Andreas Raab uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-ar.137.mcz

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

Name: Compiler-ar.137
Author: ar
Time: 24 March 2010, 1:25:23.067 am
UUID: 090fc365-fe3c-6741-a731-3222d6ab6afa
Ancestors: Compiler-nice.136

Underscore assignments and underscore selector preferences and implementation. The defaults are set to be compatible with past usage, i.e., allowUnderscoreAssignment is true and allowUnderscoreSelectors is false. Might consider changing this after 4.1.

=============== Diff against Compiler-nice.136 ===============

Item was added:
+ ----- Method: Scanner>>allowUnderscoreSelectors (in category 'private') -----
+ allowUnderscoreSelectors
+       "Query preference"
+       ^self class prefAllowUnderscoreSelectors!

Item was changed:
 ----- Method: Scanner class>>initialize (in category 'initialization') -----
 initialize
       | newTable |
       newTable := Array new: 256 withAll: #xBinary. "default"
       newTable atAll: #(9 10 12 13 32 ) put: #xDelimiter. "tab lf ff cr space"
       newTable atAll: ($0 asciiValue to: $9 asciiValue) put: #xDigit.

       1 to: 255
               do: [:index |
                       (Character value: index) isLetter
                               ifTrue: [newTable at: index put: #xLetter]].

       newTable at: 30 put: #doIt.
       newTable at: $" asciiValue put: #xDoubleQuote.
       newTable at: $# asciiValue put: #xLitQuote.
       newTable at: $$ asciiValue put: #xDollar.
       newTable at: $' asciiValue put: #xSingleQuote.
       newTable at: $: asciiValue put: #xColon.
       newTable at: $( asciiValue put: #leftParenthesis.
       newTable at: $) asciiValue put: #rightParenthesis.
       newTable at: $. asciiValue put: #period.
       newTable at: $; asciiValue put: #semicolon.
       newTable at: $[ asciiValue put: #leftBracket.
       newTable at: $] asciiValue put: #rightBracket.
       newTable at: ${ asciiValue put: #leftBrace.
       newTable at: $} asciiValue put: #rightBrace.
       newTable at: $^ asciiValue put: #upArrow.
+       newTable at: $_ asciiValue put: #xUnderscore.
-       newTable at: $_ asciiValue put: #leftArrow.
       newTable at: $| asciiValue put: #verticalBar.
       TypeTable := newTable "bon voyage!!"

       "Scanner initialize"!

Item was added:
+ ----- Method: Parser>>allowUnderscoreAssignments (in category 'private') -----
+ allowUnderscoreAssignments
+       "Query class + preference"
+       ^encoder classEncoding allowUnderscoreAssignments
+               ifNil:[super allowUnderscoreAssignments]!

Item was added:
+ ----- Method: Scanner>>allowUnderscoreAssignments (in category 'private') -----
+ allowUnderscoreAssignments
+       "Query preference"
+       ^self class prefAllowUnderscoreAssignments!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreAssignments: (in category 'preferences') -----
+ prefAllowUnderscoreAssignments: aBool
+       "Accessor for the system-wide preference"
+       AllowUnderscoreAssignments := aBool!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreAssignments (in category 'preferences') -----
+ prefAllowUnderscoreAssignments
+       "Accessor for the system-wide preference"
+       <preference: 'Allow underscore assignments'
+               category: 'Compiler'
+               description: 'When true, underscore can be used as assignment operator'
+               type: #Boolean>
+       ^AllowUnderscoreAssignments ifNil:[true]!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreSelectors: (in category 'preferences') -----
+ prefAllowUnderscoreSelectors: aBool
+       "Accessor for the system-wide preference"
+       AllowUnderscoreSelectors := aBool!

Item was changed:
 ----- Method: Scanner>>xUnderscore (in category 'multi-character scans') -----
 xUnderscore
+       self allowUnderscoreAssignments ifTrue:[ | type |
+               "Figure out if x _foo (no space between _ and foo)
+               should be a selector or assignment"
+               (((type := self typeTableAt: aheadChar) == #xLetter
+                       or:[type == #xDigit or:[type == #xUnderscore]])
+                       and:[self allowUnderscoreSelectors]) ifFalse:[
+                               self step.
+                               tokenType := #leftArrow.
+                               ^token := #':='
+               ].
+       ].
+       self allowUnderscoreSelectors ifTrue:[^self xLetter].
+       ^self xIllegal
+ !
-       Preferences allowUnderscoreAssignment ifFalse:[^self xIllegal].
-       self step.
-       tokenType := #leftArrow.
-       ^token := #':='!

Item was changed:
 ----- Method: Scanner>>xLetter (in category 'multi-character scans') -----
 xLetter
       "Form a word or keyword."

       | type |
       buffer reset.
+       [(type := self typeTableAt: hereChar) == #xLetter
+               or: [type == #xDigit
+               or: [type == #xUnderscore and:[self allowUnderscoreSelectors]]]] whileTrue:
-       [(type := self typeTableAt: hereChar) == #xLetter or: [type == #xDigit]]
-               whileTrue:
                       ["open code step for speed"
                       buffer nextPut: hereChar.
                       hereChar := aheadChar.
                       aheadChar := source atEnd
                                                       ifTrue: [30 asCharacter "doit"]
                                                       ifFalse: [source next]].
       tokenType := (type == #colon or: [type == #xColon and: [aheadChar ~~ $=]])
                                       ifTrue:
                                               [buffer nextPut: self step.
                                               "Allow any number of embedded colons in literal symbols"
                                               [(self typeTableAt: hereChar) == #xColon] whileTrue:
                                                       [buffer nextPut: self step].
                                               #keyword]
                                       ifFalse:
                                               [type == #leftParenthesis
                                                       ifTrue:
                                                               [buffer nextPut: self step; nextPut: $).
                                                                #positionalMessage]
                                                       ifFalse:[#word]].
       token := buffer contents!

Item was changed:
 Object subclass: #Scanner
       instanceVariableNames: 'source mark hereChar aheadChar token tokenType currentComment buffer typeTable'
+       classVariableNames: 'AllowUnderscoreAssignments AllowUnderscoreSelectors TypeTable'
-       classVariableNames: 'TypeTable'
       poolDictionaries: ''
       category: 'Compiler-Kernel'!

 !Scanner commentStamp: '<historical>' prior: 0!
 I scan a string or text, picking out Smalltalk syntactic tokens. I look one character ahead. I put each token found into the instance variable, token, and its type (a Symbol) into the variable, tokenType. At the end of the input stream, I pretend to see an endless sequence of special characters called doits.!

Item was added:
+ ----- Method: Scanner class>>prefAllowUnderscoreSelectors (in category 'preferences') -----
+ prefAllowUnderscoreSelectors
+       "Accessor for the system-wide preference"
+       <preference: 'Allow underscore selectors'
+               category: 'Compiler'
+               description: 'When true, underscore can be used in selectors and varibable names'
+               type: #Boolean>
+       ^AllowUnderscoreSelectors ifNil:[false]!

Item was added:
+ ----- Method: Parser>>allowUnderscoreSelectors (in category 'private') -----
+ allowUnderscoreSelectors
+       "Query class + preference"
+       ^encoder classEncoding allowUnderscoreSelectors
+               ifNil:[super allowUnderscoreSelectors]!