Nicolas Cellier uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-nice.96.mcz ==================== Summary ==================== Name: Compiler-nice.96 Author: nice Time: 27 October 2009, 3:25:48 am UUID: bfe3f3dc-3f22-c04f-974e-90cb4725b53e Ancestors: Compiler-nice.95 Test and minimal change to isLiteralSymbol: to make the test pass. This is related to http://bugs.squeak.org/view.php?id=7211 I did not apply change proposed above, though it might be a good idea to restrict unquoted notation to explicitely documented valid Smalltalk literals. There are pending decisions about wide characters and binary selectors to be resolved first. =============== Diff against Compiler-nice.95 =============== Item was changed: ----- Method: Scanner class>>isLiteralSymbol: (in category 'testing') ----- isLiteralSymbol: aSymbol "Test whether a symbol can be stored as # followed by its characters. Symbols created internally with asSymbol may not have this property, e.g. '3' asSymbol." + | i ascii type next | - | i ascii type | i := aSymbol size. i = 0 ifTrue: [^ false]. + i = 1 ifTrue: [^('$''"()#0123456789_' includes: (aSymbol at: 1)) not + and: ["should be (TypeTable at: (aSymbol at: 1) charCode ifAbsent: [#xLetter]) ~~ #xDelimiter" + (aSymbol at: 1) isSeparator not]]. - i = 1 ifTrue: [^('$''"()#0123456789_' includes: (aSymbol at: 1)) not]. ascii := (aSymbol at: 1) charCode. "TypeTable should have been origined at 0 rather than 1 ..." ascii = 0 ifTrue: [^ false]. type := TypeTable at: ascii ifAbsent: [#xLetter]. (type == #xColon or: [type == #verticalBar or: [type == #xBinary]]) ifTrue: [^i = 1]. type == #xLetter ifTrue: + [next := nil. + [i > 1] whileTrue: - [[i > 1] whileTrue: [ascii := (aSymbol at: i) charCode. ascii = 0 ifTrue: [^false]. type := TypeTable at: ascii ifAbsent: [#xLetter]. (type == #xLetter or: [type == #xDigit or: [type == #xColon]]) ifFalse: [^false]. + (next == #xDigit and: [type == #xColon]) ifTrue: [^false]. + next := type. i := i - 1]. ^true]. ^false! Item was added: + TestCase subclass: #ScannerTest + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: '' + category: 'Compiler-Tests'! Item was added: + ----- Method: ScannerTest>>testLiteralSymbols (in category 'testing') ----- + testLiteralSymbols + + self assert: ('*+-/\~=<>&@%,|' allSatisfy: [:char | Scanner isLiteralSymbol: (Symbol with: char)]) + description: 'single letter binary symbols can be printed without string quotes'. + + self assert: (#('x' 'x:' 'x:y:' 'from:to:by:' 'yourself') allSatisfy: [:str | Scanner isLiteralSymbol: str asSymbol]) + description: 'valid ascii selector symbols can be printed without string quotes'. + + ((32 to: 126) collect: [:ascii | Character value: ascii]) , + #(':x:yourself' '::' 'x:yourself' '123' 'x0:1:2:' 'x.y.z' '1abc' 'a1b0c2' ' x' 'x ' '+x-y' '||' '--' '++' '+-' '+/-' '-/+' '<|>' '#x' '()' '[]' '{}' '') + do: [:str | + self assert: (Compiler evaluate: str asSymbol printString) = str asSymbol + description: 'in all case, a Symbol must be printed in an interpretable fashion']! |
Free forum by Nabble | Edit this page |