Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 2 - Writing In Suggestions

    [
    We come here from the main input loop if the player presses space. If no suggestion is up, this should simply return 1 to move the input along the line
    ]

    Include (-

    [ WriteInSuggestion
        input_buffer cur_pos force_complete
        i j
        ;

        ! repair buffer, in case timed input has caused problems
        VM_Tokenise(input_buffer, parse);

        if (suggested_wordnum ~= cursor_word)
        ! we've changed to a different word
            return -1;

        ! TODO: Cope with writing in a suggestion somewhere other than the last word of the line

        !glk_set_window((+main-window+).ref_number);

        if (prompted_word == 0 )
        {
    ! print "No suggestions.^";
            return -1;
        }

        if (DictionaryValue(suggested_wordnum) ~= 0 && ~~force_complete)
        {
            !print "DV of sw = ", DictionaryValue(suggested_wordnum), "..^";
            if ( WordLength(suggested_wordnum) > 1 )
            {
                return -1;
            }
        }

        VM_PrintToBuffer(test_bed , DICT_WORD_SIZE * 2, RetrieveLongerVersionOf(prompted_word));

    !glk_set_window((+main-window+).ref_number);
    !print "wordnum:", suggested_wordnum, "/", CharacterNumber(suggested_wordnum), " of " , WordCount(), "... ";



    !TODO: we want to write in the word over the suggested_wordnum, and then add the rest of the line on the end
        if (suggested_wordnum < WordCount())
        {
            ! copy the old next word, starting at the space in front of it, to the end of the new word
            for (i = CharacterNumber(suggested_wordnum + 1) - 2 , j = (test_bed-->0) + WORDSIZE: i < input_buffer-->0 : i++, j++)
            {
                ! i is the position in the original buffer
                test_bed->j = input_buffer->(i + WORDSIZE);
                (test_bed-->0)++;
            }
        }

        ! now, starting from the first letter of the word to replace, write in the test_bed array
        for (i = WORDSIZE, j = CharacterNumber(suggested_wordnum) - 1:
                i < test_bed-->0 + WORDSIZE : j++, i++)
        {
            
            input_buffer->(j + WORDSIZE) = test_bed->i;
    ! print (char) input_buffer->(j+WORDSIZE);

        }
        
        word_colours->suggested_wordnum = VALID;

        if (input_buffer->(j - 1 + WORDSIZE) ~= ' ')
        {
            input_buffer->(j + WORDSIZE) = ' ';
            j++;
        }
        
        BlankSuggestion();

        input_buffer-->0 = j;

    ! print "^Constructed new string has length = ", j, "^";


        return j;


    ];

    -)