Giter Club home page Giter Club logo

Comments (8)

Wheatwizard avatar Wheatwizard commented on July 27, 2024

This error also occurs when a whitespace character (tab, space or newline) is placed after a debug flag (valid or invalid). Unlike the debug flags at the end of the program when debug flags are followed by a space the invalid character is labeled as the correct whitespace and a period.

It seems that the whitespace is considered part of a debug flag when the program is being stripped of extra characters but not part of a debug flag when the debug flags are added. This however does not explain why debug flags at the ends of programs result in the same error. Perhaps when the interpreter reads from the file it adds an extra newline to the end of string if none is present.

Example

Code

()#dc ()

Without Debug

$ ruby brain_flak.rb code.txt
Error at character 3: Invalid character ' .'

With Debug

$ ruby brain_flak.rb code.txt
Debug mode... ENGAGED!
#dc (left) []
Error at character 3: Invalid character ' .'

from brain-flak.

Wheatwizard avatar Wheatwizard commented on July 27, 2024

The reason there is always a period quoted with the invalid character is because there was a typo in the error message. The line (138/154 as of 3aa842b):

else raise BrainFlakError.new("Invalid character '%s.'" % current_symbol, @index + 1)

should have been:

else raise BrainFlakError.new("Invalid character '%s'." % current_symbol, @index + 1)

This typo although initially confusing is entirely inconsequential to the bug as a whole. It doesn't deserve its own commit (Especially because this error message only appears if there is a bug in the interpreter). The change should probably be bundled with the final fix for this bug.

from brain-flak.

1000000000 avatar 1000000000 commented on July 27, 2024

I fixed a similar bug while I was finishing up the debug flags (commit a839fbe) but I just went back and checked and it appears to have popped back in when I merged the debug flags branch into master (commit 0e607e1) but my previous fix is still in the code so it must be something else.

from brain-flak.

1000000000 avatar 1000000000 commented on July 27, 2024

Hmmm... your whitespace fix has the problem where the #dv in ()#dv foo is no longer recognized as a debug flag

from brain-flak.

1000000000 avatar 1000000000 commented on July 27, 2024

I got a fix, the regex at the start of the initializer of Interpreter needed to have a + changed to a * so that if it encountered a lone whitespace character it matched it as opposed to passing over it.

from brain-flak.

1000000000 avatar 1000000000 commented on July 27, 2024

Pull request #29 should do the trick, but if anyone wants to do more extensive testing that would definitely be a good idea

from brain-flak.

Wheatwizard avatar Wheatwizard commented on July 27, 2024

Tangentially related to this issue:

Should #dv8 be considered a valid flag? Should we truncate the 8 to make the #dv. If #dv is considered a valid flag and whitespace is considered an invalid character just as 8 is shouldn't both of them behave the same way?

from brain-flak.

1000000000 avatar 1000000000 commented on July 27, 2024

It would be a good idea to hammer out which characters can be considered part of a debug flag. My reason for excluding whitespace from debug flags because I felt it would be confusing to have if, for example, there was a program that had a debug flag followed by a new line like so

()#dv
a comment ()

If whitespace were allowed to be part of debug flags then it would not recognize that #dv as a debug flag. So I decided to have the interpreter exclude whitespace from debug flags, but I did not put any further thought to it.

from brain-flak.

Related Issues (20)

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.