--- a/Scanner.st Mon Oct 14 18:18:35 2002 +0200
+++ b/Scanner.st Tue Oct 15 21:52:59 2002 +0200
@@ -1351,6 +1351,86 @@
"Created: / 17.2.1998 / 14:48:49 / cg"
!
+escapeCharacterFor:aCharacter
+ "only if AllowExtendedSTXSyntax is true
+ For now: do not use, since stc does not support it.
+
+ much like character escapes in C-literals;
+ expands:
+ `n newLine
+ `r return
+ `t tab
+ `b backspace
+ `f formfeed
+ `g bell
+
+ `` backTick
+ ` ...` ignored
+ `xNN hexCharacter
+ `xNN hexCharacter
+ "
+
+ |ascii nextChar|
+
+ aCharacter == $n ifTrue:[^ Character nl].
+ aCharacter == $r ifTrue:[^ Character return].
+ aCharacter == $t ifTrue:[^ Character tab].
+ aCharacter == $b ifTrue:[^ Character backspace].
+ aCharacter == $f ifTrue:[^ Character ff].
+ aCharacter == $g ifTrue:[^ Character bell].
+ aCharacter == $` ifTrue:[^ aCharacter].
+ aCharacter isSeparator ifTrue:[
+ nextChar := source next.
+ [nextChar notNil and:[nextChar ~~ $`]] whileTrue:[
+ (nextChar == Character cr) ifTrue:[
+ lineNr := lineNr + 1
+ ].
+ nextChar := source next.
+ ].
+ ^ nil
+ ].
+
+ aCharacter == $x ifTrue:[
+ ascii := 0.
+ nextChar := source next.
+ (nextChar notNil and:[nextChar isDigitRadix:16]) ifTrue:[
+ ascii := nextChar digitValue.
+ nextChar := source next.
+ (nextChar notNil and:[nextChar isDigitRadix:16]) ifTrue:[
+ ascii := (ascii bitShift:4) bitOr:nextChar digitValue.
+ ]
+ ].
+ ^ Character value:ascii.
+ ].
+ aCharacter == $0 ifTrue:[
+ ascii := 0.
+ nextChar := source next.
+ (nextChar notNil and:[nextChar isDigitRadix:8]) ifTrue:[
+ ascii := nextChar digitValue.
+ nextChar := source next.
+ (nextChar notNil and:[nextChar isDigitRadix:8]) ifTrue:[
+ ascii := (ascii bitShift:3) bitOr:nextChar digitValue.
+ nextChar := source next.
+ (nextChar notNil and:[nextChar isDigitRadix:8]) ifTrue:[
+ ascii := (ascii bitShift:3) bitOr:nextChar digitValue.
+ ]
+ ]
+ ].
+ ^ Character value:ascii.
+ ].
+ ^ aCharacter
+
+ "
+ AllowExtendedSTXSyntax := true
+ "
+ "
+ 'hello`nworld'
+ 'hello`x08world'
+ 'hello`
+ `world'
+ "
+!
+
ignoreErrors
"turn off notification of errors"
@@ -2039,7 +2119,7 @@
|nextChar string pos
index "{ Class: SmallInteger }"
len "{ Class: SmallInteger }"
- inString|
+ inString peekChar|
string := String basicNew:20.
len := 20.
@@ -2060,21 +2140,34 @@
].
(nextChar == Character cr) ifTrue:[
lineNr := lineNr + 1
- ].
- (nextChar == Character quote) ifTrue:[
- (source peekOrNil == Character quote) ifTrue:[
- source next
+ ] ifFalse:[
+ (nextChar == Character quote) ifTrue:[
+ (source peekOrNil == Character quote) ifTrue:[
+ source next
+ ] ifFalse:[
+ inString := false
+ ]
] ifFalse:[
- inString := false
- ]
+ AllowExtendedSTXSyntax == true ifTrue:[
+ (nextChar == $`) ifTrue:[
+ peekChar := source peekOrNil.
+ peekChar notNil ifTrue:[
+ source next.
+ nextChar := self escapeCharacterFor:peekChar.
+ ]
+ ]
+ ]
+ ].
].
inString ifTrue:[
- string at:index put:nextChar.
- (index == len) ifTrue:[
- string := string , (String new:len).
- len := len * 2
+ nextChar notNil ifTrue:[
+ string at:index put:nextChar.
+ (index == len) ifTrue:[
+ string := string , (String new:len).
+ len := len * 2
+ ].
+ index := index + 1.
].
- index := index + 1.
nextChar := source next
]
].
@@ -2351,6 +2444,7 @@
!Scanner class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.152 2002-08-13 16:39:33 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.153 2002-10-15 19:52:59 cg Exp $'
! !
+
Scanner initialize!