The Trunk: Kernel-mt.1239.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Kernel-mt.1239.mcz

commits-2
Marcel Taeumel uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-mt.1239.mcz

==================== Summary ====================

Name: Kernel-mt.1239
Author: mt
Time: 31 May 2019, 11:49:05.536936 am
UUID: c1b1ed0f-6055-e543-a389-510fea993ddb
Ancestors: Kernel-cmm.1238, Kernel-cmfcmf.1216

Merge cmfcmf.1216

=============== Diff against Kernel-cmm.1238 ===============

Item was changed:
  ----- Method: Random>>diceToken: (in category 'die rolling') -----
  diceToken: stream
  "Private. Mini scanner, see #roll:"
 
  stream atEnd ifTrue: [^ nil].
+ stream peek isDigit ifTrue: [^ Integer readFrom: stream].
- stream peek isDigit ifTrue: [^ Number readFrom: stream].
  ^ stream next asLowercase!

Item was changed:
  ----- Method: Random>>roll: (in category 'die rolling') -----
  roll: diceString
  "Roll some dice, DnD-style, according to this mini-grammar:
+ dice := epxr {pm dice}
- dice := epxr {pm expr}
  pm := '+' | '-'
  expr := num | num dD | dD numP | num dD numP
  dD := 'd' | 'D'
  num := digit+
  numP := num | '%'"
 
  | stream op result |
  stream := diceString readStream.
  result := 0.
  op := #+.
  [ | res range dice token |
  token := self diceToken: stream.
  token isNumber
  ifTrue: [dice := token.
+ res := token.
  token := self diceToken: stream]
  ifFalse: [token == $d
  ifTrue: [dice := 1]
+ ifFalse: [self error: 'unknown token' , token]].
- ifFalse: [res := 0]].
  token == $d
  ifTrue: [token := self diceToken: stream.
  token isNumber
  ifTrue: [range := token.
  token := self diceToken: stream]
  ifFalse: [token == $%
  ifTrue: [range := 100.
  token := self diceToken: stream]
  ifFalse: [range := 6]].
  res := 0.
  dice timesRepeat: [res := res + (self nextInt: range)]].
  result := result perform: op with: res.
  token ifNil: [^ result].
  (token == $+ or: [token == $-])
  ifFalse: [self error: 'unknown token ' , token].
  op := token asSymbol] repeat!