Skip to content
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

Closed
Wheatwizard opened this issue Jul 26, 2016 · 8 comments
Closed

Debug flags at the end of a program throw an error #28

Wheatwizard opened this issue Jul 26, 2016 · 8 comments
Labels

Comments

@Wheatwizard
Copy link
Collaborator

Wheatwizard commented Jul 26, 2016

Programs with debug flags at the end of a program (with no braces after) cause the error:

Error at character <last brace +1>: Invalid character '
.'

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

(())#dc

Output

With debug

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

Without Debug

$ ruby brain_flak.rb code.txt
Error at character 5: Invalid character '
.'
@Wheatwizard
Copy link
Collaborator Author

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 ' .'

Wheatwizard pushed a commit that referenced this issue Jul 27, 2016
@Wheatwizard
Copy link
Collaborator Author

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.

@1000000000
Copy link
Collaborator

1000000000 commented Jul 28, 2016

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.

@1000000000
Copy link
Collaborator

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

@1000000000
Copy link
Collaborator

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.

1000000000 added a commit that referenced this issue Jul 28, 2016
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
@1000000000
Copy link
Collaborator

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

@Wheatwizard Wheatwizard mentioned this issue Jul 28, 2016
@Wheatwizard
Copy link
Collaborator Author

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?

@1000000000
Copy link
Collaborator

1000000000 commented Jul 28, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants