-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug flags at the end of a program throw an error #28
Comments
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. ExampleCode
Without Debug$ ruby brain_flak.rb code.txt
With Debug$ ruby brain_flak.rb code.txt
|
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. |
Hmmm... your whitespace fix has the problem where the |
I got a fix, the regex at the start of the initializer of |
This reverts commit 3aa842b. The reverted commit introduced a new bug where text separated from the end of a debug flag by whitespace was being included in the debug flag text when the program was parsing debug flags
Pull request #29 should do the trick, but if anyone wants to do more extensive testing that would definitely be a good idea |
Tangentially related to this issue: Should |
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
If whitespace were allowed to be part of debug flags then it would not recognize that |
Programs with debug flags at the end of a program (with no braces after) cause the error:
It does not mater what debug flag it is, if the file ends in a newline or even if it is a valid debug flag, it always prints a newline and a period as the "Invalid character". If we put other non brain-flak characters such in between the end of the program and the start of the debug flag it marks the first one as the invalid character. However this is because those characters get scrubbed from the program.
Interestingly enough the error occurs regardless of the command line flags used. It occurs in both debug and non-debug mode.
The program still runs and all the flags are executed but it errors at conclusion.
While this bug is being fixed, adding a
(<()>){}
to the end of your Brain-Flak prevents the error without changing the program's function.Example:
Code
Output
With debug
Without Debug
The text was updated successfully, but these errors were encountered: