ReadEvalPrintLoop.st
changeset 23684 bec66c208be8
parent 23518 a1b76be599ea
child 24106 57fa3fced677
equal deleted inserted replaced
23683:05f38e32876b 23684:bec66c208be8
   705 
   705 
   706 cmd_help:lineStream
   706 cmd_help:lineStream
   707     stderr
   707     stderr
   708         nextPutAll:
   708         nextPutAll:
   709 'Everything entered up to an empty line or a line ending in "." is called a "chunk" and evaluated.
   709 'Everything entered up to an empty line or a line ending in "." is called a "chunk" and evaluated.
       
   710 Lines ending with "\” prevent the above.
   710 Lines starting with "#" (in the first column) are commands to the read-eval-print interpreter.
   711 Lines starting with "#" (in the first column) are commands to the read-eval-print interpreter.
   711 
   712 
   712 Valid commands are:
   713 Valid commands are:
   713 ', (OperatingSystem isOSXlike ifTrue:[
   714 ', (OperatingSystem isOSXlike ifTrue:[
   714 '    #qFix ............... fix locked xQuartz display (hack)
   715 '    #qFix ............... fix locked xQuartz display (hack)
   762 The MiniDebugger (if entered) shows its own help with "?".
   763 The MiniDebugger (if entered) shows its own help with "?".
   763 '
   764 '
   764 
   765 
   765     "Created: / 07-12-2006 / 18:54:20 / cg"
   766     "Created: / 07-12-2006 / 18:54:20 / cg"
   766     "Modified: / 08-11-2016 / 22:53:53 / cg"
   767     "Modified: / 08-11-2016 / 22:53:53 / cg"
   767     "Modified: / 05-11-2018 / 14:35:47 / Claus Gittinger"
   768     "Modified: / 09-02-2019 / 14:34:28 / Claus Gittinger"
   768 !
   769 !
   769 
   770 
   770 cmd_ide:lineStream
   771 cmd_ide:lineStream
   771     "upen up the ide"
   772     "upen up the ide"
   772 
   773 
  1343     "
  1344     "
  1344      (ReadEvalPrintLoop basicNew error:Stderr) showVariables
  1345      (ReadEvalPrintLoop basicNew error:Stderr) showVariables
  1345     "
  1346     "
  1346 ! !
  1347 ! !
  1347 
  1348 
       
  1349 !ReadEvalPrintLoop methodsFor:'doit'!
       
  1350 
       
  1351 doIt ^[123
       
  1352 
       
  1353 +
       
  1354 
       
  1355 234
       
  1356 .] value
       
  1357 ! !
       
  1358 
  1348 !ReadEvalPrintLoop methodsFor:'evaluation'!
  1359 !ReadEvalPrintLoop methodsFor:'evaluation'!
  1349 
  1360 
  1350 basicReadEvalPrintLoopWithInput:input output:output error:error
  1361 basicReadEvalPrintLoopWithInput:input output:output error:error
  1351     compiler:compilerClass prompt:doPrompt print:doPrint
  1362     compiler:compilerClass prompt:doPrompt print:doPrint
  1352 
  1363 
  1353     "{ Pragma: +optSpace }"
  1364     "{ Pragma: +optSpace }"
  1354 
  1365 
  1355     "the core of the interpreter loop; 
  1366     "the core of the interpreter loop; 
  1356      extracted and parametrized, so it can be called recursively for included scripts.
  1367      extracted and parametrized, so it can be called recursively for included scripts.
  1357      If chunkFormat is true, chunks are read.
  1368      If chunkFormat is true, chunks are read.
  1358      Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read.
  1369      Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read,
       
  1370      unless the line ends with '\'.
  1359      A '#' character appearing in the first column of the first line turns off chunkmode,
  1371      A '#' character appearing in the first column of the first line turns off chunkmode,
  1360      which allows for convenient shell scripts containing a #/bin/stx as the first line."
  1372      which allows for convenient shell scripts containing a #/bin/stx as the first line."
  1361 
  1373 
  1362     exitAction := [^ self].
  1374     exitAction := [^ self].
  1363 
  1375 
  1381             input skipSeparators.
  1393             input skipSeparators.
  1382             chunk := input nextChunk.
  1394             chunk := input nextChunk.
  1383         ] ifFalse:[
  1395         ] ifFalse:[
  1384             lines := OrderedCollection new.
  1396             lines := OrderedCollection new.
  1385             [
  1397             [
  1386                 |line|
  1398                 |line stillReading|
  1387 
  1399 
       
  1400                 stillReading := false.
  1388                 line := input nextLine.
  1401                 line := input nextLine.
  1389                 line notEmptyOrNil ifTrue:[
  1402                 line notEmptyOrNil ifTrue:[
  1390                     line = '?' ifTrue:[
  1403                     line = '?' ifTrue:[
  1391                         self cmd_help:nil.
  1404                         self cmd_help:nil.
  1392                         doPrompt notNil ifTrue:[
  1405                         doPrompt notNil ifTrue:[
  1397                             self directive:line.
  1410                             self directive:line.
  1398                             (doPrompt and:[prompt notEmptyOrNil]) ifTrue:[
  1411                             (doPrompt and:[prompt notEmptyOrNil]) ifTrue:[
  1399                                 error show:prompt.
  1412                                 error show:prompt.
  1400                             ].
  1413                             ].
  1401                         ] ifFalse:[
  1414                         ] ifFalse:[
       
  1415                             (line endsWith:'\') ifTrue:[
       
  1416                                 stillReading := true.
       
  1417                                 line := line copyButLast.
       
  1418                             ].    
  1402                             lines add:line.
  1419                             lines add:line.
  1403                         ]
  1420                         ]
  1404                     ]
  1421                     ]
  1405                 ].
  1422                 ].
  1406                 line notEmptyOrNil and:[(line endsWith:$.) not].
  1423                 stillReading ifFalse:[
       
  1424                     stillReading := line notEmptyOrNil and:[(line endsWith:$.) not]
       
  1425                 ].
       
  1426                 stillReading
  1407             ] whileTrue.
  1427             ] whileTrue.
  1408             chunk := lines asStringWith:Character cr.
  1428             chunk := lines asStringWith:Character cr.
  1409         ].
  1429         ].
  1410 
  1430 
  1411         (chunk notEmptyOrNil 
  1431         (chunk notEmptyOrNil 
  1424         prompt:'>') readEvalPrintLoop
  1444         prompt:'>') readEvalPrintLoop
  1425     "
  1445     "
  1426 
  1446 
  1427     "Created: / 07-12-2006 / 17:27:21 / cg"
  1447     "Created: / 07-12-2006 / 17:27:21 / cg"
  1428     "Modified: / 08-11-2016 / 22:41:47 / cg"
  1448     "Modified: / 08-11-2016 / 22:41:47 / cg"
       
  1449     "Modified (comment): / 09-02-2019 / 14:30:50 / Claus Gittinger"
  1429 !
  1450 !
  1430 
  1451 
  1431 compileAndExexute:chunk with:compilerClass doPrompt:doPrompt doPrint:doPrint
  1452 compileAndExexute:chunk with:compilerClass doPrompt:doPrompt doPrint:doPrint
  1432     "abortAll is handled, but not asked for here!!"
  1453     "abortAll is handled, but not asked for here!!"
  1433     AbortAllOperationRequest handle:[:ex |
  1454     AbortAllOperationRequest handle:[:ex |