REPL.st 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. process stdout write: e jsStack]].
  31. self setPrompt.
  32. interface prompt
  33. ! !
  34. !Repl methodsFor: 'initialization'!
  35. initialize
  36. super initialize.
  37. readline := require value: 'readline'.
  38. util := require value: 'util'
  39. ! !
  40. !Repl class methodsFor: 'not yet classified'!
  41. main
  42. self new createInterface
  43. ! !