Giter VIP home page Giter VIP logo

Comments (3)

Praxidice avatar Praxidice commented on July 19, 2024

Ok, I think I see the issue. '\n' is being added after input(), but it is never removed during the digit extraction loop. In the next request '\n' is still there in the input buffer, so "if not self._input_buffer" is false and input doesn't get called again, leading to no digits being extracted and the exception. Removing the '\n' and adding a length check to the digit extraction loop seems to fix it... not sure if this affects char reading though.

def _run_input(self, input_op, character):
        if not self._input_buffer:
            try:
                self._input_buffer = input()
            except EOFError:
                if input_op.input_char:
                    self._character_opposite(character).value = -1
                    return
                else:
                    raise Exception('End of file encountered.')

        if input_op.input_number:
            number_input = ''
            while self._input_buffer and self._input_buffer[0].isdigit():
                number_input += self._input_buffer[0]
                self._input_buffer = self._input_buffer[1:]

            if len(number_input) == 0:
                raise Exception('No numeric input was given.')

            self._character_opposite(character).value = int(number_input)
        elif input_op.input_char:
            input_char = ord(self._input_buffer[0])
            self._input_buffer = self._input_buffer[1:]
            self._character_opposite(character).value = input_char

from shakespearelang.

zmbc avatar zmbc commented on July 19, 2024

@Praxidice Thank you for reporting the issue! I'm finally doing a maintenance pass on shakespearelang and I think I've found a good fix for this.

Unfortunately, the numeric input functionality of SPL was not well-defined and the behavior I made up has been somewhat buggy and surprising.

I've revised numeric input in my latest change so that requesting a number will consume all consecutive digits at the start of the input, and an optional line break. If the line break is not present, nothing more is consumed so that the rest of the line can be read as characters.

I'll close this issue when the fix is released.

from shakespearelang.

zmbc avatar zmbc commented on July 19, 2024

A bit late here (it's been out since January) but 1.0.0rc1 fixes this issue -- feel free to test it out!

from shakespearelang.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.