Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - Early exit conditions for loops

    Include (-

    [ CheckForExitCondition k;

        
    ! glk_set_window((+main-window+).ref_number);
    ! print "(Keycheck).^";

        k = CheckForCharacter(); ! second true indicates "short timer" mode
        if (k ~= 0)
        {

    ! glk_set_window((+main-window+).ref_number);
    ! print "Keypress interrupted handling : ", (char) k, ".^";
                
    ! store up the k and pass it back to the next grab character call...
            interrupt_keypress = k;

            rtrue;
        }

        rfalse;
    ];

    [ CheckForCharacter
        done key
        ;

        glk_request_timer_events(1);

        done = false;
        while(~~done)
        {
            CorrectlyPositionCursor();
            glk_select(gg_event);
            switch(gg_event-->0)
            {
                evtype_Timer:
                    key = 0;
                    done = true;
                    
                evtype_CharInput:
                    key = gg_event-->2;
                    done = true;
                    
                    glk_request_char_event((+key-window+).ref_number);
            
            }
        }

        glk_request_timer_events(0);
        return key;
    ];

    -).