-
Notifications
You must be signed in to change notification settings - Fork 161
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
Quit evaluator if first symbol had syntax error #1015
Quit evaluator if first symbol had syntax error #1015
Conversation
Current coverage is 54.54% (diff: 100%)@@ master #1015 diff @@
==========================================
Files 432 432
Lines 224765 224767 +2
Methods 3431 3431
Messages 0 0
Branches 0 0
==========================================
+ Hits 122572 122595 +23
+ Misses 102193 102172 -21
Partials 0 0
|
Not sure I want to know why the test coverage changed so dramatically, but I'll investigate... |
This seems to be breaking the break loop in a bad way. |
SyntaxError("Missing single quote in character constant"); | ||
if ( *TLS(In) == '\n' ) { | ||
SyntaxError("Character literal must not include <newline>"); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has the description "Refactor GetChar()", but for me "refactor" suggests that there is no functional difference to the previous code. But that does not seem to be the case for this refactoring. For example, old and new code differ on how they handle a newline (both give a syntax error, but a different one). So at the very least, I find the commit message misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this doesn't work as is, I'll have to re-do this PR anyway.
Changing the error message was really an afterthought, to make it line up with the error message for strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
/* put normal chars into 'TLS(Value)' */ | ||
TLS(Value)[0] = *TLS(In); | ||
} | ||
TLS(Symbol) = S_CHAR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code sets Symbol
to S_CHAR
before invoking GET_CHAR
. And in particular, before checking for the "missing single quote character" error. Does that have any significance? (I am not familiar with this code, not saying it is wrong, just wondering).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GET_CHAR
(essentially...) advances the pointer into the input stream buffer; here we are looking to get the closing '
.
This refactor is an attempt at making the function less obscure, but maybe I am not very successful at it yet.
The TLS(Symbol) = S_CHAR
should probably happen at the end of the function, because only then can we be sure that we (successfully) parsed a character literal.
97d0d3b
to
9b4fe40
Compare
I am not quite sure yet that this is the correct fix, but it fixes the crashes and other problems. |
So is this still "Do not merge"? Or is it open for review? |
Have a look at it. I am not sure this is the correct solution to the problem: the evaluator actually keeps running in an inconsistent state, hence prints the In the string case one gets:
i.e. the parse is not abandoned, but all you can do is leave the parse there anyway I think. This change just abandons the parse if the first symbol cannot be correctly parsed, I don't think there's a point in a continuation prompt, but maybe there are arguments to the contrary. |
Hmm, yeah, the continuation prompt doesn't really make sense here. But I am afraid I don't know much about that code, so can't help. Perhaps @stevelinton or @ChrisJefferson have an idea? |
Actually one thing one could do is to ignore the |
I'll look into the continuation code, and see what's going on. |
I think the real thing that wants fixing here is
The problem is we only switch on the partial prompt after reading the first symbol. This prompt changing code should perhaps be somewhere else -- perhaps |
Well, that's exactly what 9b4fe40 does: It aborts ReadEvalCommand if there's been a syntax error in the first symbol. I'll also have a vaguely related poke at this again because I want to be able to interpret exactly one statement from an input stream, but keep that stream intact; at the moment the stream is munched using all kinds of |
I wonder if a better option, for both string an character, would be to treat the newline as end of string / character, and just bail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my take on this thing (without having tried to run the code in here myself, though I trust @markuspf and Travis that it does not break things like crazy): This PR fixes an existing problem. Perhaps there is a hypothetcal "better" fix out there, and perhaps (or rather: most likely...) the whole way we deal with input should be revised... but all these "ifs" should not stop this existing PR from being merged right away. After all, it is quite minimal, and so I don't think it'll make any of those hypothetical "better" solutions any harder to implemnt :-).
I have one minor complaint: This PR supposedly fixes a issue #995. But looking at the three commit messages in this PR, it does not become clear which of them (or rather, that any of them) fixes this bug. For people reading through the commit log in the future, this bit of information would be quite helpful. (I suspect it it the first commit which contains the fix; but it only talks about continuaton prompts, while #995 does not involve a continuation prompt) |
Having looked a this, I've decided that it's a good fix. I had another idea, but this is fine. I'll let @markuspf comment in @fingolfin 's comment about the changelog. |
Still waiting for a reply by @markuspf |
* If the user pressed enter after entering ' to start a character literal, GetChar would try getting more characters from the input, which lead to printing of a (continuation) prompt. * This is also trying to make GetChar slightly easier to follow
If the first Match in ReadEvalCommand leads to an error just return. This fixes issue gap-system#995.
9b4fe40
to
f99a514
Compare
Fixes a mild regression introduce by PR gap-system#1015, which in turn attempted to fix parts of issue gap-system#995. With GAP 4.8 and also with this fix: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ In GAP 4.9: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ 3
Fixes a mild regression introduce by PR gap-system#1015, which in turn attempted to fix parts of issue gap-system#995. With GAP 4.8 and also with this fix: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ In GAP 4.9: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ 3
Fixes a mild regression introduce by PR gap-system#1015, which in turn attempted to fix parts of issue gap-system#995. With GAP 4.8 and also with this fix: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ In GAP 4.9: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ 3
Fixes a mild regression introduce by PR gap-system#1015, which in turn attempted to fix parts of issue gap-system#995. With GAP 4.8 and also with this fix: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ In GAP 4.9: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ 3
Please make sure that this pull request:
Tick all what applies to this pull request
Write below the description of changes (for the release notes)
This PR addresses #995.
If the parser encountered a syntax error in the first symbol it read, it did not abandon the expression it was trying to parse early enough. This lead to inconsistent state with the prompt
gap>
being printed, even though the interpreter is still waiting for the expression to finish parsing.