Skip to content

Commit

Permalink
Extends variant wrappings covering range to any literal collection fo…
Browse files Browse the repository at this point in the history
…r any literal block
  • Loading branch information
JoeAtHPI committed Jan 4, 2024
1 parent 6582325 commit a5f8198
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
42 changes: 0 additions & 42 deletions packages/Sandblocks-Babylonian/SBStNumber.extension.st

This file was deleted.

41 changes: 41 additions & 0 deletions packages/Sandblocks-Smalltalk/SBStLiteral.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,44 @@ SBStLiteral >> useAsStSymbol [
target: self;
replacer: (SBStSymbol new contents: self contents))
]

{ #category : #actions }
SBStLiteral >> wrapInVariantCoveringRange [
<action>

| rangeString collection |
rangeString := UIManager default
request: 'Enter any collection of literals as alternatives.'
initialAnswer: '1 to: 3, #($a $b $c), {''foo''. ''bar''. ''Squeak''.}...'.
((rangeString isNil) or: [rangeString = '']) ifTrue: [^ self].

collection := [Compiler evaluate: rangeString] on: Error do: [:ex | UIManager inform: 'Not valid code'. ^ self].
collection isCollection ifFalse: [UIManager inform: 'Not a valid Collection'. ^ self].

(collection isInterval and: [collection start > collection stop])
ifTrue: [collection := collection stop to: collection start. collection := collection reversed].

self wrapInVariantGivenCollection: collection
]

{ #category : #actions }
SBStLiteral >> wrapInVariantGivenCollection: aCollection [

| variant |
variant := SBVariant new.
self sandblockEditor do:
(SBWrapCommand new
selectAfter: #block;
outer: variant;
inner: self;
wrap: [:outer :inner | variant
named: aCollection asString
alternatives: (aCollection collect: [:anObject |
SBNamedBlock block: (SBStBlockBody new
statements: {(
anObject isString
ifTrue: [SBStString new contents: anObject]
ifFalse: [anObject asString parseAsSandblock])})
named: anObject asString])
activeIndex: 1])
]

0 comments on commit a5f8198

Please sign in to comment.