Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#####() now does not parse anymore #17431

Open
wants to merge 2 commits into
base: Pharo13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/AST-Core-Tests/ASTScannerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,14 @@ ASTScannerTest >> testNextLiteralCanContainDigits [
self assert: token value equals: #alpha123beta456
]

{ #category : 'tests - Literal' }
{ #category : 'tests - Literal multiple hash' }
ASTScannerTest >> testNextLiteralCanHaveMultipleHashtag [
| scanner token |
scanner := self buildScannerForText: '########literal'.
token := scanner next.
self assert: token isLiteralToken
self deny: token isLiteralToken.
self assert: token isError.
self assert: token cause equals: 'Multiple # sequence is forbidden'
]

{ #category : 'tests - Literal' }
Expand Down Expand Up @@ -963,7 +965,7 @@ ASTScannerTest >> testNextLiteralCharacterWithAMissingCharacter [
{ #category : 'tests - Start' }
ASTScannerTest >> testNextLiteralStartAtFirstLetter [
| scanner token |
scanner := self buildScannerForText: '########literal'.
scanner := self buildScannerForText: '#literal'.
token := scanner next.
self assert: token isLiteralToken.
self assert: token start equals: 1
Expand All @@ -972,18 +974,19 @@ ASTScannerTest >> testNextLiteralStartAtFirstLetter [
{ #category : 'tests - Stop' }
ASTScannerTest >> testNextLiteralStopAtLastLetter [
| scanner token |
scanner := self buildScannerForText: '########literal'.
scanner := self buildScannerForText: '#literal'.
token := scanner next.
self assert: token isLiteralToken.
self assert: token stop equals: 15
self assert: token stop equals: 8
]

{ #category : 'tests - Literal' }
{ #category : 'tests - Literal multiple hash' }
ASTScannerTest >> testNextLiteralWithMultipleHashtagTrimThem [
| scanner token |
scanner := self buildScannerForText: '########literal'.
token := scanner next.
self assert: token value equals: 'literal'
self assert: token isError.
self assert: token value equals: '##'
]

{ #category : 'tests - Keyword' }
Expand Down
13 changes: 10 additions & 3 deletions src/AST-Core/RBScanner.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Class {
'classificationTable',
'comments',
'nextToken',
'state'
'state',
'alreadySeenHash'
],
#classVars : [
'CascadePatternCharacter',
Expand Down Expand Up @@ -295,7 +296,8 @@ RBScanner >> on: aStream [
buffer := (String new: 60) writeStream.
stream := aStream.
classificationTable := self class classificationTable.
comments := OrderedCollection new
comments := OrderedCollection new.
alreadySeenHash := false
]

{ #category : 'private' }
Expand Down Expand Up @@ -412,6 +414,7 @@ RBScanner >> scanLiteral [
"Do not allow number literals after the #"

"This scan accepts keywords as well as binaries and Identifiers."

self step.
characterType = #alphabetic
ifTrue: [ ^ self scanSymbol ].
Expand All @@ -422,8 +425,12 @@ RBScanner >> scanLiteral [
(currentCharacter = $( or: [ currentCharacter = $[ ])
ifTrue: [ ^ self scanLiteralArrayToken ].
"Accept multiple #."
(currentCharacter = $# and: [ alreadySeenHash ifNotNil: [ :s | s ] ])
ifTrue: [ ^ self scanError: 'Multiple # sequence is forbidden' ].
currentCharacter = $#
ifTrue: [ ^ self scanLiteral ].
ifTrue: [
alreadySeenHash := true.
^ self scanLiteral ].
^ self scanError: 'Literal expected'
]

Expand Down