1
0

REPL.st 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Object subclass: #Repl
  2. instanceVariableNames: 'readline interface util'
  3. category: 'REPL'!
  4. !Repl methodsFor: 'accessing'!
  5. prompt
  6. ^'amber >> '
  7. ! !
  8. !Repl methodsFor: 'actions'!
  9. createInterface
  10. "No completion for now"
  11. interface := readline createInterface: process stdin stdout: process stdout.
  12. interface on: 'line' do: [:buffer | self eval: buffer].
  13. interface on: 'close' do: [self close].
  14. self setPrompt.
  15. interface prompt
  16. !
  17. setPrompt
  18. interface setPrompt: self prompt
  19. !
  20. close
  21. process stdin destroy
  22. !
  23. eval: buffer
  24. | result |
  25. buffer isEmpty ifFalse: [
  26. self try: [
  27. result := Compiler new loadExpression: buffer.
  28. Transcript show: result]
  29. catch: [:e |
  30. e isSmalltalkError
  31. ifTrue: [ErrorHandler new handleError: e]
  32. ifFalse: [process stdout write: e jsStack]]].
  33. interface prompt
  34. ! !
  35. !Repl methodsFor: 'initialization'!
  36. initialize
  37. super initialize.
  38. readline := require value: 'readline'.
  39. util := require value: 'util'
  40. ! !
  41. !Repl class methodsFor: 'not yet classified'!
  42. main
  43. self new createInterface
  44. ! !