Skip to content

Commit

Permalink
Allow to notate TypedSlot using term ∷ type notation
Browse files Browse the repository at this point in the history
This together with `TypingJudgement >> asSlot` allows to use `term ∷ type`
notation when defining typed instance variables and elements of future
class `Record`.
  • Loading branch information
janvrany authored and shingarov committed Jun 29, 2024
1 parent 31fe0a4 commit 2bb6a78
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Collections-Homogeneous/TypingJudgement.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : #TypingJudgement }

{ #category : #'*Collections-Homogeneous' }
TypingJudgement >> asSlot [
term isString ifFalse:[
self error:'term must be a string or symbol'.
^nil.
].
^TypedSlot named: term asSymbol type: type
]
25 changes: 25 additions & 0 deletions src/MathNotation/TypedSlot.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Extension { #name : #TypedSlot }

{ #category : #'*MathNotation' }
TypedSlot >> definitionString [
| scanner typeString |

"Try to put parenthesis around term and type
when needed.
"
scanner := RBScanner new initializeClassificationTable.

^String streamContents: [ :aStream|
name storeOn: aStream.
aStream nextPutAll: ''.

typeString := type printString.
(typeString anySatisfy:[:char | | charCls | (charCls := scanner classify: char) ~~ #alphabetic and:[ charCls ~~ #digit ]]) ifTrue:[
aStream nextPut:$(.
type printOn: aStream.
aStream nextPut:$).
] ifFalse:[
type printOn: aStream
].
]
]

0 comments on commit 2bb6a78

Please sign in to comment.