Bug in Comment Parsing
William O. Dargel
wDargel at shoshana.com
Tue Jan 13 22:18:44 UTC 1998
I found that empty comments ("") are not parsed correctly. The second $"
does not terminate the comment, but rather gets included as the first
character of a comment that terminates wherever the next $" appears in
the source.
I happened to uncover this because I have used the idiom
"""code to ignore"""
(three $" characters in a row) as a quick way to comment out some code
while having it be more visible that I had done so. Only with this bug,
the code wasn't being commented out.
The following change fixes the bug.
-------------------------------------------
'From Squeak 1.23 of October 4, 1997 on 13 January 1998 at 4:00:06 pm'!
!Scanner methodsFor: 'multi-character scans' stamp: 'wod 1/10/98 00:43'!
xDoubleQuote
"Collect a comment."
"wod 1/10/98: Allow 'empty' comments by testing the first character
for $"" rather than blindly adding it to the comment being collected."
| aStream stopChar |
stopChar _ 30 asCharacter.
aStream _ WriteStream on: (String new: 200).
self step.
[hereChar == $"]
whileFalse:
[(hereChar == stopChar and: [source atEnd])
ifTrue: [^self offEnd: 'Unmatched comment quote'].
aStream nextPut: self step.].
self step.
currentComment == nil
ifTrue: [currentComment _ OrderedCollection with: aStream
contents]
ifFalse: [currentComment add: aStream contents].
self scanToken! !
-------------------------------------------
Bill Dargel wdargel at shoshana.com
Shoshana Technologies
100 West Joy Road, Ann Arbor, MI 48105 USA
More information about the Squeak-dev
mailing list
|