about summary refs log blame commit diff stats
path: root/html/repl.mu.html
blob: 4a0f2c21a283c761ae33881d1c10f0e1bf5a34f8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                                          

                                                                                                 
                        
                               


                              
                            
                                  
                              
                             













                                                        
                                                                                                                                                                   
              

                                                                                                                                                                
                                                                                                                                                                                                                                      

                                                                                                                                                                                                                                                                      


                                                    
                                                                                                                                                                   
                                                                                                  
                                                                                                 
                                  
                                                                                                                                                     
                                                                            
                                                
                                       
                                  
                                                                                                                

 
                                                                       

                                                                                                              

                                                      
                               
   
       
                                                                                                                 









                                                                                                           
                                                                  


                                                                        



                                                                               

 
                                                                                                         



                                                                                                         
                                                                                                                                                                   


                                                                                                                                                                     


                                                                                                           
                                                                                                              



                                                                                                                        
                                                                                                           
                                                                      
                                                                                                                                                                                                  

                                                                                  
                                                                                                                                    
                                          
                                                                                                          

                                                                                            
                                                                                                     
                                                                                                                                                 

 
                                                                                                     

                                                                                     

                                                                                                                                                                   

                                                                                                  
                                                                                                        

                                                                                                           
                                                       
                                  
                                                 



                                                                                                             
                                                 


                                                                                                                 
                                                                          

                                        

                                                                            
                                                                                                                              
                                                                 

                                                                            
                                                                                                                 
                                                                                                                                                             


                                                                                                                      
                                                               
                                                                                                               
                                                                                                                                                             



                                                                                                                          
                                                                  
                                                                                               
                                                                                                               
                                                                                                                                                                                           
                                                                                                                           
                                                                                             



                                                                                                                                 
                                                                 
                                                                                               
                                                                                                               
                                                                                                                                                                                             
                                                                                             
                                    


                                                                                                                              
                                                                 
                                                                                              

                                                                                                               
                                                                                                                                                                                              
                                                                                             
                                    
                                        
                                                                                             

                                                                                                             


                                                                          

                                                                        


                                                                            
                                                                                                                                
                                                                    


                                                                            

                                                                                                                                              


                                                                              

                                                                                                                                            


                                                                              
                                                                                                                                           


                                                                              
                                                                                                                                             
                                      
                                                                                             
                                    


                                                                          



                                                                                                                                       

                                                         


                                                                                               
                                                                                                    
                                                                                                                                           
                                                                    

 
                                                                                                       



                                                                                                      

                                                                                                                                                                   

                                                                                                  
                                                                                                        



                                                                                                                                                                                                 
                                                 
                                                 

                                                                                                                 


                                                                                                                              
                                                                 
                                                                                                      
                                                                                                                                                             


                                                                                                                      
                                                               
                                                                                                    
                                                                                                                                                             

                                        
                                                                                             




                                                                                                                                
                                                                    


                                                                                                                                                  
                                                                        
                                                                                                                                
                                                                                                                                             
                                      
                                                                                             




                                                                                                                                       

                                                         
                                  
                                                                                                                                           
                                                                    

 
                                                                                                         






                                                                                                           

                                                                                                                                                                   

                                                                                                  

                                                                                                         



                                                                                                                                                                                                 
                                                 
                                                 

                                                                                                                 


                                                                                                                              
                                                                 
                                                                                                     
                                                                                                                                                                                                      


                                                                                                                      
                                                               
                                                                                                   
                                                                                                                                                                                                      



                                                                                                                                 
                                                                 
                                                                                                                                  
                                                                                               

                                                                                                               
                                                                                                                                                                                                                                                       

                                                                                                                                                                                                         
                                                                                             

                                        
                                                                                             




                                                                                                                                
                                                                    


                                                                                                                                                  
                                                                        
                                                                                                                               
                                                                                                                                                                                                           
                                      
                                                                                             




                                                                                                                                       

                                                         

                                  
                                                                      
                                                                             
                                                                                                                          


                                                                                                                                                     
                                                                                                                                                                                                  

                                                                                                                                  
                                                                                         

 
                                                       

                                                                                                                                                                   

                                                                                                  
                                                                                                        
                                  
                                                 
                                                 

                                                                                                                 


                                                                                                                              
                                                                 
                                                                                                         
                                                                                                                                                             


                                                                                                                      
                                                               
                                                                                                       
                                                                                                                                                             

                                        
                                                                                            





                                                                                                                                
                                                                    
                                                                                                                       
                                                                                                                                                                


                                                                                                                                    
                                                                                                                                                                                                  

                                                                                                                                          
                                                                                         

 

                                                                                                              


                                                  
       
                                                    












                                                                                                              




                                                                                                                                                                                                                                                        
       
                                                    












                                                                                                              




                                                                                                                                                                                                                                                        
       
                                                    












                                                                                                              




                                                                                                                                                                                                                                                        
       
                                                    










                                                                                 

                                                                                                              




                                                                                
       
                                                    







                                                                                   


                                                                                                              


                                                     
       
                                                    
















                                                                                                              



                                                  
       
                                                    



















                                                                                                              


                                                                                             
       
                                                    




















                                                                                                              


                                                                     
       
                                                    




















                                                                                                              


                                                                     
       
                                                    




















                                                                                                              


                                                                    

                                                             
                                                    


















                                                                                                              






                                                                                                                                                                                                                                                               
       




                                                                                                                 












                                                                                                              








                                                                                                                                                                                                                                                                 
       
                                                    












                                                                                                              




                                                                                                                                                                                                                                                        
       
                                                    




                                                                     
                                                         














                                                                                                            


                                                                                                              


                                               
       
                                                    
















                                                                                                              


                                                  
       
                                                    
















                                                                                                              




                                                                                                                                                                                                                                                        
       
                                                    
















                                                                                                              





                                                                                                                                                                                                                                                        
       
                                                    
















                                                                                                              




                                                                                                                                                                                                                                                        
       
                                                    














                                                                                 



                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - repl.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.muScenario { color: #00af00; }
.Delimiter { color: #a04060; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.muControl { color: #c0a020; }
.muRecipe { color: #ff8700; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># interactive prompt for mu</span>

<span class="muRecipe">recipe</span> main [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  open-console
  msg:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[ready! type in an instruction, then hit enter. ctrl-d exits.</span>
<span class="Constant">]</span>
  <span class="Constant">0:literal/real-screen</span><span class="Special"> &lt;- </span>print-string <span class="Constant">0:literal/real-screen</span>, msg:address:array:character, <span class="Constant">245:literal/grey</span>
  <span class="Constant">0:literal/real-console</span>, <span class="Constant">0:literal/real-screen</span><span class="Special"> &lt;- </span>color-session <span class="Constant">0:literal/real-console</span>, <span class="Constant">0:literal/real-screen</span>
  close-console
]

<span class="muRecipe">recipe</span> color-session [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  console:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    inst:address:array:character, console:address, screen:address<span class="Special"> &lt;- </span>read-instruction console:address, screen:address
    <span class="muControl">break-unless</span> inst:address:array:character
    run-interactive inst:address:array:character
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  <span class="muControl">reply</span> console:address/same-as-ingredient:0, screen:address/same-as-ingredient:1
]

<span class="Comment"># basic console input; just text and enter</span>
<span class="muScenario">scenario</span> read-instruction1 [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[x &lt;- copy y</span>
<span class="Constant">]</span>
  ]
  run [
    1:address:array:character<span class="Special"> &lt;- </span>read-instruction console:address, screen:address
    2:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[=&gt; ]</span>
    print-string screen:address, 2:address:array:character
    print-string screen:address, 1:address:array:character
  ]
  screen-should-contain [
   <span class="Constant"> .x &lt;- copy y                   .</span>
   <span class="Constant"> .=&gt; x &lt;- copy y                .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .x    copy y                   .</span>
   <span class="Constant"> .=&gt; x &lt;- copy y                .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [
   <span class="Constant"> .  &lt;-                          .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="Comment"># Read characters as they're typed at the console, print them to the screen,</span>
<span class="Comment"># accumulate them in a string, return the string at the end.</span>
<span class="Comment"># Most of the complexity is for the printing to screen, to highlight strings</span>
<span class="Comment"># and comments specially. Especially in the presence of backspacing.</span>
<span class="muRecipe">recipe</span> read-instruction [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">60:literal</span>
  console:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  result:address:buffer<span class="Special"> &lt;- </span>new-buffer <span class="Constant">10:literal</span>  <span class="Comment"># string to maybe add to</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[read-instruction]</span>
  <span class="Comment"># start state machine by calling slurp-regular-characters, which will return</span>
  <span class="Comment"># by calling the complete continuation</span>
  complete:continuation<span class="Special"> &lt;- </span><span class="muControl">current-continuation</span>
  <span class="Comment"># If result is not empty, we've run slurp-regular-characters below, called</span>
  <span class="Comment"># the continuation and so bounced back here. We're done.</span>
  len:number<span class="Special"> &lt;- </span>get result:address:buffer/deref, length:offset
  completed?:boolean<span class="Special"> &lt;- </span>greater-than len:number, <span class="Constant">0:literal</span>
  <span class="muControl">jump-if</span> completed?:boolean, <span class="Constant">+completed:label</span>
  <span class="Comment"># Otherwise we're just getting started.</span>
  result:address:buffer, console:address, screen:address<span class="Special"> &lt;- </span>slurp-regular-characters result:address:buffer, console:address, screen:address, complete:continuation
<span class="CommentedCode">#?   $print [aaa: ], result:address:buffer #? 1</span>
<span class="CommentedCode">#?   move-cursor-down-on-display #? 1</span>
  trace <span class="Constant">[error]</span>, <span class="Constant">[slurp-regular-characters should never return normally]</span>
<span class="Constant">  +completed</span>
  result2:address:array:character<span class="Special"> &lt;- </span>buffer-to-array result:address:buffer
<span class="CommentedCode">#?   $print [bbb: ], result2:address:array:character #? 1</span>
<span class="CommentedCode">#?   move-cursor-down-on-display #? 1</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[exiting read-instruction]</span>
  <span class="muControl">reply</span> result2:address:array:character, console:address/same-as-ingredient:0, screen:address/same-as-ingredient:1
]

<span class="Comment"># read characters from the console, print them to the screen in *white*.</span>
<span class="Comment"># Transition to other routines for comments and strings.</span>
<span class="muRecipe">recipe</span> slurp-regular-characters [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  result:address:buffer<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  console:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  complete:continuation<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-regular-characters]</span>
  characters-slurped:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
<span class="CommentedCode">#?   $run-depth #? 1</span>
  <span class="Delimiter">{</span>
<span class="Constant">    +next-character</span>
    trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-regular-characters: next]</span>
<span class="CommentedCode">#?     $print [a0 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?     move-cursor-down-on-display #? 1</span>
    <span class="Comment"># read character</span>
    c:character, console:address found?:boolean<span class="Special"> &lt;- </span>read-key console:address
    <span class="muControl">loop-unless</span> found?:boolean <span class="Constant">+next-character:label</span>
<span class="CommentedCode">#?     print-character screen:address, c:character #? 1</span>
<span class="CommentedCode">#?     move-cursor-down-on-display #? 1</span>
    <span class="Comment"># quit?</span>
    <span class="Delimiter">{</span>
<span class="CommentedCode">#?       $print [aaa] #? 1</span>
<span class="CommentedCode">#?       move-cursor-down-on-display #? 1</span>
      ctrl-d?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">4:literal/ctrl-d/eof</span>
      <span class="muControl">break-unless</span> ctrl-d?:boolean
<span class="CommentedCode">#?       $print [ctrl-d] #? 1</span>
<span class="CommentedCode">#?       move-cursor-down-on-display #? 1</span>
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-regular-characters: ctrl-d]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Delimiter">{</span>
      null?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">0:literal/null</span>
      <span class="muControl">break-unless</span> null?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-regular-characters: null]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Comment"># comment?</span>
    <span class="Delimiter">{</span>
      comment?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">35:literal/hash</span>
      <span class="muControl">break-unless</span> comment?:boolean
      print-character screen:address, c:character, <span class="Constant">4:literal/blue</span>
      result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
      result:address:buffer, console:address, screen:address<span class="Special"> &lt;- </span>slurp-comment result:address:buffer, console:address, screen:address, complete:continuation
      <span class="Comment"># continue appending to this instruction, whether comment ended or was backspaced out of</span>
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># string</span>
    <span class="Delimiter">{</span>
      string?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">91:literal/open-bracket</span>
      <span class="muControl">break-unless</span> string?:boolean
      print-character screen:address, c:character, <span class="Constant">6:literal/cyan</span>
      result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
      result:address:buffer, _, console:address, screen:address<span class="Special"> &lt;- </span>slurp-string result:address:buffer, console:address, screen:address, complete:continuation
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># assignment</span>
    <span class="Delimiter">{</span>
      assign?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">60:literal/less-than</span>
      <span class="muControl">break-unless</span> assign?:boolean
      print-character screen:address, c:character, <span class="Constant">1:literal/red</span>
      trace <span class="Constant">[app]</span>, <span class="Constant">[start of assignment: &lt;]</span>
      result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
      result:address:buffer, console:address, screen:address<span class="Special"> &lt;- </span>slurp-assignment result:address:buffer, console:address, screen:address, complete:continuation
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># print</span>
    print-character screen:address, c:character  <span class="Comment"># default color</span>
    <span class="Comment"># append</span>
    result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
<span class="CommentedCode">#?     $print [a1 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?     move-cursor-down-on-display #? 1</span>
    <span class="Comment"># backspace? decrement and maybe return</span>
    <span class="Delimiter">{</span>
<span class="CommentedCode">#?       $print [a2 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?       move-cursor-down-on-display #? 1</span>
      backspace?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">8:literal/backspace</span>
      <span class="muControl">break-unless</span> backspace?:boolean
<span class="CommentedCode">#?       $print [a3 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?       move-cursor-down-on-display #? 1</span>
      characters-slurped:number<span class="Special"> &lt;- </span>subtract characters-slurped:number, <span class="Constant">1:literal</span>
      <span class="Delimiter">{</span>
<span class="CommentedCode">#?         $print [a4 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?         move-cursor-down-on-display #? 1</span>
        done?:boolean<span class="Special"> &lt;- </span>lesser-or-equal characters-slurped:number, <span class="Constant">-1:literal</span>
        <span class="muControl">break-unless</span> done?:boolean
<span class="CommentedCode">#?         $print [a5 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?         move-cursor-down-on-display #? 1</span>
        trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-regular-characters: too many backspaces; returning]</span>
<span class="CommentedCode">#?         $print [a6 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?         move-cursor-down-on-display #? 1</span>
        <span class="muControl">reply</span> result:address:buffer, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
      <span class="Delimiter">}</span>
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
<span class="CommentedCode">#?     $print [a9 #? 1</span>
<span class="CommentedCode">#? ] #? 1</span>
<span class="CommentedCode">#?     move-cursor-down-on-display #? 1</span>
    <span class="Comment"># otherwise increment</span>
    characters-slurped:number<span class="Special"> &lt;- </span>add characters-slurped:number, <span class="Constant">1:literal</span>
    <span class="Comment"># done with this instruction?</span>
    done?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">10:literal/newline</span>
    <span class="muControl">break-if</span> done?:boolean
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># newline encountered; terminate all recursive calls</span>
<span class="CommentedCode">#?   xx:address:array:character &lt;- new [completing!] #? 1</span>
<span class="CommentedCode">#?   print-string screen:address, xx:address:array:character #? 1</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-regular-characters: newline encountered; unwinding stack]</span>
  <span class="muControl">continue-from</span> complete:continuation
]

<span class="Comment"># read characters from console, print them to screen in the comment color.</span>
<span class="Comment">#</span>
<span class="Comment"># Simpler version of slurp-regular-characters; doesn't handle comments or</span>
<span class="Comment"># strings. Tracks an extra count in case we backspace out of it</span>
<span class="muRecipe">recipe</span> slurp-comment [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  result:address:buffer<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  console:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  complete:continuation<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-comment]</span>
  <span class="Comment"># use this to track when backspace should reset color</span>
  characters-slurped:number<span class="Special"> &lt;- </span>copy <span class="Constant">1:literal</span>  <span class="Comment"># for the initial '#' that's already appended to result</span>
  <span class="Delimiter">{</span>
<span class="Constant">    +next-character</span>
    <span class="Comment"># read character</span>
    c:character, console:address, found?:boolean<span class="Special"> &lt;- </span>read-key console:address
    <span class="muControl">loop-unless</span> found?:boolean <span class="Constant">+next-character:label</span>
    <span class="Comment"># quit?</span>
    <span class="Delimiter">{</span>
      ctrl-d?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">4:literal/ctrl-d/eof</span>
      <span class="muControl">break-unless</span> ctrl-d?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-comment: ctrl-d]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Delimiter">{</span>
      null?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">0:literal/null</span>
      <span class="muControl">break-unless</span> null?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-comment: null]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Comment"># print</span>
    print-character screen:address, c:character, <span class="Constant">4:literal/blue</span>
    <span class="Comment"># append</span>
    result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
    <span class="Comment"># backspace? decrement</span>
    <span class="Delimiter">{</span>
      backspace?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">8:literal/backspace</span>
      <span class="muControl">break-unless</span> backspace?:boolean
      characters-slurped:number<span class="Special"> &lt;- </span>subtract characters-slurped:number, <span class="Constant">1:literal</span>
      <span class="Delimiter">{</span>
        reset-color?:boolean<span class="Special"> &lt;- </span>lesser-or-equal characters-slurped:number, <span class="Constant">0:literal</span>
        <span class="muControl">break-unless</span> reset-color?:boolean
        trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-comment: too many backspaces; returning]</span>
        <span class="muControl">reply</span> result:address:buffer, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
      <span class="Delimiter">}</span>
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># otherwise increment</span>
    characters-slurped:number<span class="Special"> &lt;- </span>add characters-slurped:number, <span class="Constant">1:literal</span>
    <span class="Comment"># done with this instruction?</span>
    done?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">10:literal/newline</span>
    <span class="muControl">break-if</span> done?:boolean
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-regular-characters: newline encountered; unwinding stack]</span>
  <span class="muControl">continue-from</span> complete:continuation
]

<span class="Comment"># read characters from console, print them to screen in the string color and</span>
<span class="Comment"># accumulate them into a buffer.</span>
<span class="Comment">#</span>
<span class="Comment"># Version of slurp-regular-characters that:</span>
<span class="Comment">#   a) doesn't handle comments</span>
<span class="Comment">#   b) handles nested strings using recursive calls to itself. Tracks an extra</span>
<span class="Comment">#   count in case we backspace out of it.</span>
<span class="muRecipe">recipe</span> slurp-string [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  result:address:buffer<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  console:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  complete:continuation<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  nested-string?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-string]</span>
  <span class="Comment"># use this to track when backspace should reset color</span>
  characters-slurped:number<span class="Special"> &lt;- </span>copy <span class="Constant">1:literal</span>  <span class="Comment"># for the initial '[' that's already appended to result</span>
  <span class="Delimiter">{</span>
<span class="Constant">    +next-character</span>
    <span class="Comment"># read character</span>
    c:character, console:address, found?:boolean<span class="Special"> &lt;- </span>read-key console:address
    <span class="muControl">loop-unless</span> found?:boolean <span class="Constant">+next-character:label</span>
    <span class="Comment"># quit?</span>
    <span class="Delimiter">{</span>
      ctrl-d?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">4:literal/ctrl-d/eof</span>
      <span class="muControl">break-unless</span> ctrl-d?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-string: ctrl-d]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Delimiter">{</span>
      null?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">0:literal/null</span>
      <span class="muControl">break-unless</span> null?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-string: null]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Comment"># string</span>
    <span class="Delimiter">{</span>
      string?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">91:literal/open-bracket</span>
      <span class="muControl">break-unless</span> string?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-string: open-bracket encountered; recursing]</span>
      print-character screen:address, c:character, <span class="Constant">6:literal/cyan</span>
      result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
      <span class="Comment"># make a recursive call to handle nested strings</span>
      result:address:buffer, tmp:number, console:address, screen:address<span class="Special"> &lt;- </span>slurp-string result:address:buffer, console:address, screen:address, complete:continuation, <span class="Constant">1:literal/nested?</span>
      <span class="Comment"># but if we backspace over a completed nested string, handle it in the caller</span>
      characters-slurped:number<span class="Special"> &lt;- </span>add characters-slurped:number, tmp:number, <span class="Constant">1:literal</span>  <span class="Comment"># for the leading '['</span>
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># print</span>
    print-character screen:address, c:character, <span class="Constant">6:literal/cyan</span>
    <span class="Comment"># append</span>
    result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
    <span class="Comment"># backspace? decrement</span>
    <span class="Delimiter">{</span>
      backspace?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">8:literal/backspace</span>
      <span class="muControl">break-unless</span> backspace?:boolean
      characters-slurped:number<span class="Special"> &lt;- </span>subtract characters-slurped:number, <span class="Constant">1:literal</span>
      <span class="Delimiter">{</span>
        reset-color?:boolean<span class="Special"> &lt;- </span>lesser-or-equal characters-slurped:number, <span class="Constant">0:literal</span>
        <span class="muControl">break-unless</span> reset-color?:boolean
        trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-string: too many backspaces; returning]</span>
        <span class="muControl">reply</span> result:address:buffer/same-as-ingredient:0, <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
      <span class="Delimiter">}</span>
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># otherwise increment</span>
    characters-slurped:number<span class="Special"> &lt;- </span>add characters-slurped:number, <span class="Constant">1:literal</span>
    <span class="Comment"># done with this instruction?</span>
    done?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">93:literal/close-bracket</span>
    <span class="muControl">break-if</span> done?:boolean
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> nested-string?:boolean
    <span class="Comment"># nested string? return like a normal recipe</span>
    <span class="muControl">reply</span> result:address:buffer, characters-slurped:number, console:address, screen:address
  <span class="Delimiter">}</span>
  <span class="Comment"># top-level string call? recurse</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-string: close-bracket encountered; recursing to regular characters]</span>
  result:address:buffer, console:address, screen:address<span class="Special"> &lt;- </span>slurp-regular-characters result:address:buffer, console:address, screen:address, complete:continuation
  <span class="Comment"># backspaced back into this string</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-string: backspaced back into string; restarting]</span>
  <span class="muControl">jump</span> <span class="Constant">+next-character:label</span>
]

<span class="muRecipe">recipe</span> slurp-assignment [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  result:address:buffer<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  console:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  complete:continuation<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
<span class="Constant">    +next-character</span>
    <span class="Comment"># read character</span>
    c:character, console:address, found?:boolean<span class="Special"> &lt;- </span>read-key console:address
    <span class="muControl">loop-unless</span> found?:boolean <span class="Constant">+next-character:label</span>
    <span class="Comment"># quit?</span>
    <span class="Delimiter">{</span>
      ctrl-d?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">4:literal/ctrl-d/eof</span>
      <span class="muControl">break-unless</span> ctrl-d?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-assignment: ctrl-d]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Delimiter">{</span>
      null?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">0:literal/null</span>
      <span class="muControl">break-unless</span> null?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-assignment: null]</span>
      <span class="muControl">reply</span> <span class="Constant">0:literal</span>, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
    <span class="Comment"># print</span>
    print-character screen:address, c:character, <span class="Constant">1:literal/red</span>
    trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-assignment: saved one character]</span>
    <span class="Comment"># append</span>
    result:address:buffer<span class="Special"> &lt;- </span>buffer-append result:address:buffer, c:character
    <span class="Comment"># backspace? return</span>
    <span class="Delimiter">{</span>
      backspace?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">8:literal/backspace</span>
      <span class="muControl">break-unless</span> backspace?:boolean
      trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-assignment: backspace; returning]</span>
      <span class="muControl">reply</span> result:address:buffer/same-as-ingredient:0, console:address/same-as-ingredient:1, screen:address/same-as-ingredient:2
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-assignment: done, recursing to regular characters]</span>
  result:address:buffer, console:address, screen:address<span class="Special"> &lt;- </span>slurp-regular-characters result:address:buffer, console:address, screen:address, complete:continuation
  <span class="Comment"># backspaced back into this string</span>
  trace <span class="Constant">[app]</span>, <span class="Constant">[slurp-assignment: backspaced back into assignment; restarting]</span>
  <span class="muControl">jump</span> <span class="Constant">+next-character:label</span>
]

<span class="muScenario">scenario</span> read-instruction-color-comment [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[# comment]</span>
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain-in-color <span class="Constant">4:literal/blue</span>, [
   <span class="Constant"> .# comment                     .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-cancel-comment-on-backspace [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[#a««z]</span>
  ]
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain-in-color <span class="Constant">4:literal/blue</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .z                             .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-cancel-comment-on-backspace2 [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[#ab«««z]</span>
  ]
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain-in-color <span class="Constant">4:literal/blue</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .z                             .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-cancel-comment-on-backspace3 [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[#a«z]</span>
  ]
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain-in-color <span class="Constant">4:literal/blue</span>, [
   <span class="Constant"> .#z                            .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-stop-after-comment [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  <span class="Comment"># console contains comment and then a second line</span>
  assume-console [
    type <span class="Constant">[#abc</span>
<span class="Constant">3]</span>
  ]
  run [
    read-instruction console:address, screen:address
  ]
  <span class="Comment"># check that read-instruction reads just the comment</span>
  screen-should-contain [
   <span class="Constant"> .#abc                          .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-color-string [
<span class="CommentedCode">#?   $start-tracing #? 1</span>
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[abc [string]</span>]
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .abc [string]                  .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .    [string]                  .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .abc                           .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-color-string-multiline [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[abc [line1</span>
<span class="Constant">line2]</span>]
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .abc [line1                    .</span>
   <span class="Constant"> .line2]                        .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .    [line1                    .</span>
   <span class="Constant"> .line2]                        .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .abc                           .</span>
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-color-string-and-comment [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[abc [string]</span>  <span class="Comment"># comment]</span>
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .abc [string]  # comment       .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">4:literal/blue</span>, [
   <span class="Constant"> .              # comment       .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .    [string]                  .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .abc                           .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-ignore-comment-inside-string [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[abc [string # not a comment]</span>]
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .abc [string # not a comment]  .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .    [string # not a comment]  .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .abc                           .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">4:literal/blue</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-ignore-string-inside-comment [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[abc # comment [not a string]</span>]
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .abc # comment [not a string]  .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .abc                           .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">4:literal/blue</span>, [
   <span class="Constant"> .    # comment [not a string]  .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-color-string-inside-string [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[abc [string [inner string]</span>]]
  ]
  run [
<span class="CommentedCode">#?     $start-tracing #? 1</span>
    read-instruction console:address, screen:address
<span class="CommentedCode">#?     $stop-tracing #? 1</span>
<span class="CommentedCode">#?     $browse-trace #? 1</span>
  ]
  screen-should-contain [
   <span class="Constant"> .abc [string [inner string]]   .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .    [string [inner string]]   .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .abc                           .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-cancel-string-on-backspace [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[(a««z]</span>  <span class="Comment"># '(' is '[' and '«' is backspace</span>
  ]
  open-bracket:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">91:literal/open-bracket</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">40:literal/open-paren</span>, open-bracket:event
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
<span class="CommentedCode">#?     d:address:array:event &lt;- get console:address/deref, data:offset #? 1</span>
<span class="CommentedCode">#?     $print [a: ], d:address:array:event #? 1</span>
<span class="CommentedCode">#?     x:number &lt;- length d:address:array:event/deref #? 1</span>
<span class="CommentedCode">#?     $print [b: ], x:number #? 1</span>
    read-instruction console:address, screen:address
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .z                             .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-cancel-string-inside-string-on-backspace [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[(a[b]</span>«««b)]  <span class="Comment"># '(' is '[' and '«' is backspace</span>
  ]
  open-bracket:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">91:literal/open-bracket</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">40:literal/open-paren</span>, open-bracket:event
  close-bracket:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">93:literal/close-bracket</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">41:literal/close-paren</span>, close-bracket:event
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .[ab]                          .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-backspace-back-into-string [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[[a]</span>«b]  <span class="Comment"># '«' is backspace</span>
  ]
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .\\\[ab                           .</span>
   <span class="Constant"> .                              .</span>
  ]
<span class="CommentedCode">#?   $print [aaa] #? 1</span>
  screen-should-contain-in-color <span class="Constant">6:literal/cyan</span>, [
   <span class="Constant"> .\\\[ab                           .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .                              .</span>
   <span class="Constant"> .                              .</span>
  ]
  <span class="Comment"># todo: trace sequence of events</span>
  <span class="Comment">#   slurp-regular-characters: [</span>
  <span class="Comment">#   slurp-regular-characters/slurp-string: a</span>
  <span class="Comment">#   slurp-regular-characters/slurp-string: ]</span>
  <span class="Comment">#   slurp-regular-characters/slurp-string/slurp-regular-characters: backspace</span>
  <span class="Comment">#   slurp-regular-characters/slurp-string: b</span>
]

<span class="muScenario">scenario</span> read-instruction-highlight-start-of-assignment [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[a &lt;]</span>
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .a &lt;                           .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [
   <span class="Constant"> .  &lt;                           .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .a                             .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-highlight-assignment [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[a &lt;- b]</span>
  ]
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .a &lt;- b                        .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [
   <span class="Constant"> .  &lt;-                          .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .a    b                        .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-backspace-over-assignment [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[a &lt;-«]</span>  <span class="Comment"># '«' is backspace</span>
  ]
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .a &lt;                           .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [
   <span class="Constant"> .  &lt;                           .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .a                             .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-assignment-continues-after-backspace [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[a &lt;-«-]</span>  <span class="Comment"># '«' is backspace</span>
  ]
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
<span class="CommentedCode">#?   $print [aaa] #? 1</span>
  run [
    read-instruction console:address, screen:address
  ]
  screen-should-contain [
   <span class="Constant"> .a &lt;-                          .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [
   <span class="Constant"> .  &lt;-                          .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .a                             .</span>
   <span class="Constant"> .                              .</span>
  ]
]

<span class="muScenario">scenario</span> read-instruction-assignment-continues-after-backspace2 [
  assume-screen <span class="Constant">30:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    type <span class="Constant">[a &lt;- ««-]</span>  <span class="Comment"># '«' is backspace</span>
  ]
  backspace:event<span class="Special"> &lt;- </span>merge <span class="Constant">0:literal/text</span>, <span class="Constant">8:literal/backspace</span>, <span class="Constant">0:literal/dummy</span>, <span class="Constant">0:literal/dummy</span>
  replace-in-console <span class="Constant">171:literal/«</span>, backspace:event
  run [
    read-instruction console:address, screen:address
<span class="CommentedCode">#?     $browse-trace #? 1</span>
  ]
  screen-should-contain [
   <span class="Constant"> .a &lt;-                          .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1:literal/red</span>, [
   <span class="Constant"> .  &lt;-                          .</span>
   <span class="Constant"> .                              .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7:literal/white</span>, [
   <span class="Constant"> .a                             .</span>
   <span class="Constant"> .                              .</span>
  ]
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->