ReadEvalPrintLoop.st
changeset 20774 a29ae1f5f429
parent 20771 bc02f6854efa
child 20833 58ae6ff92df5
equal deleted inserted replaced
20773:c9d6f5d209d9 20774:a29ae1f5f429
   445 
   445 
   446     "the core of the interpreter loop; extracted and parametrized, so it can be called recursive
   446     "the core of the interpreter loop; extracted and parametrized, so it can be called recursive
   447      for included scripts.
   447      for included scripts.
   448      If chunkFormat is true, chunks are read.
   448      If chunkFormat is true, chunks are read.
   449      Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read.
   449      Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read.
   450      A '#' character appearing in the first column of the first line turns off chunkmode."
   450      A '#' character appearing in the first column of the first line turns off chunkmode,
       
   451      which allows for convenient shell scripts containing a #/bin/stx as the first line."
   451 
   452 
   452     [
   453     [
   453         |lines chunk|
   454         |lines chunk|
   454 
   455 
   455         prompt notNil ifTrue:[
   456         prompt notNil ifTrue:[
   572      switches to chunkmode."
   573      switches to chunkmode."
   573 
   574 
   574     exitAction := [^ self].
   575     exitAction := [^ self].
   575 
   576 
   576     ControlInterrupt handle:[:ex |
   577     ControlInterrupt handle:[:ex |
   577 	self errorStream nextPutLine:('Caught: ', ex description).
   578         self errorStream nextPutLine:('Caught: ', ex description).
   578 	ex restart.
   579         ex restart.
   579     ] do:[
   580     ] do:[
   580 	|input output error compilerClass|
   581         |input output error compilerClass|
   581 
   582 
   582 	"/ re-evaluate these in the loop, so they can be changed dynamically
   583         "/ re-evaluate these in the loop, so they can be changed dynamically
   583 	input := self inputStream.
   584         input := self inputStream.
   584 	output := self outputStream.
   585         output := self outputStream.
   585 	error := self errorStream.
   586         error := self errorStream.
   586 
   587 
   587 	compilerClass := compiler ? Compiler ? Parser.
   588         compilerClass := compiler ? Compiler ? Parser.
   588 	compilerClass isNil ifTrue:[
   589         compilerClass isNil ifTrue:[
   589 	    self errorStream nextPutLine:('oops - no Compiler class found').
   590             self errorStream nextPutLine:('oops - no Compiler class found').
   590 	    ^ self.
   591             ^ self.
   591 	].
   592         ].
   592 	self
   593         StreamError handle:[:ex |
   593 	    basicReadEvalPrintLoopWithInput:input output:output error:error
   594             (input isOpen not or:[input atEnd]) ifTrue:[
   594 	    compiler:compilerClass prompt:prompt print:(printFlag ? true).
   595                 error nextPutLine:'EOF on input'.
       
   596             ].    
       
   597             (output isOpen not) ifTrue:[
       
   598                 error nextPutLine:'no output'.
       
   599             ].    
       
   600             (error isOpen not) ifTrue:[
       
   601             ].    
       
   602         ] do:[    
       
   603             input signalAtEnd:true.
       
   604             self
       
   605                 basicReadEvalPrintLoopWithInput:input output:output error:error
       
   606                 compiler:compilerClass prompt:prompt print:(printFlag ? true).
       
   607         ]
   595     ]
   608     ]
   596 
   609 
   597     "
   610     "
   598      (ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop
   611      (ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop
   599     "
   612     "