-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
[Feature debate] Remove column constraint on assignments and macro calls #457
Comments
If anything, this would reduce the need for my dedenter script (which was the motivation for #305).
Only if a label shares a name with a macro or mnemonic, correct? Otherwise, a construction analogous to ca65 Would the following decision rules be helpful?
|
I looked into the yacc conflicts, and this would solve one (related to |
I'd go one step further and completely disallow colonless non-locals. You might want to have a compatibility mode for a while, but the benefits of this alleged feature are so minimal and the fix is so trivial that you might as well get rid of it. |
Maybe I wasn't clear enough, but I am in favor of removing colonless non-local label declarations. It might be possible to warn users of colon-less label declarations for a while, but I'm sadly not sure how to implement it on a grammar level. |
Can't you print the warning when you add the label to the list of symbols? |
How so? Isn't the presence of the colon detected at parsing time? |
Isn't the colon saved along with the rest of the string? I have never actually checked. |
I have looked more into this, and it appears that a big chunk of the problem is that the lexer returns a different token depending on the column number. I have tried changing this for a quick try, and even our own test suite fired back—it uses a ton of colon-less labels. |
This is actually impossible to perform with the current grammar, if only as the following proves:
There is an ambiguity in the language itself—not just in the grammar. @aaaaaa123456789 suggested replacing the I implemented this for a shot, and we have a problem: |
As I said before, when you break existing code, it doesn't really matter by how much you break it. Something like |
If we break it, might as well remove |
Agreed. |
After more implementation tweaking and discussion, it looks like this might be a hard barrier for RGBASM. Here is a summary of what transpired: GoalThe reason why this fix is wanted is because column-1 rules create a newbie trap, with obscure error messages (ranging from the infamous terse The problem that invariably arises when attempting to remove this limitation is a bunch of grammar conflicts. But those occur because of ambiguities in the language itself! Consider the following line:
Under current RGBASM, this is without a doubt defining immutable variable Worse still, label declarations themselves become unreliable. Consider this line:
Under current RGBASM, this does call macro Solutions(╯°□°)╯︵-┻━┻Maintain the statu quo. After all, it's not that bad, right? Maybe the error messages can be improved. (Especially the syntax error, but that one has a broader scope) Label reworkA suggested resolution would be to require colons to be stitched to the The two parts I don't like about this are more mucking with the lexer, which I would be okay with if it was a Flex definition, but it's not, it's hand-modified generated C now. ( Macro invocation tokenThe solution to that would be to require all macro calls to be prefixed with a special token (I was thinking of a As with the previous option, there would be a need for changing a lot of locations in the code, but I believe that the bulk could be automated by parsing the warning message output. I would personally prefer this option because it allows more leniency in future extensions to the grammar. Alternatives@pinobatch made ca83, a macro pack for ca65 that allows it to process RGBDS-inspired syntax (still using ca65 features, expression syntax, macro invocations, and so on). There is also HGBASM by @Hawkbat, with very good compatibility. If someone isn't comfortable with RGBDS' limitations it's possible to look for alternatives, without going as far as switching to eg. wla-dx. As for the specific issue we're dealing with, @pinobatch also made a preprocessor that, assuming all label declarations end with a colon, de-indents them to column 1 where RGBASM can process them. Considering alternatives exist, do we want to break compatibility to fix this? |
I actually like this idea. It's really annoying to fix code that doesn't comply with the new syntax, but it can be fixed automatically for the most part, and it gets rid of that inconsistency (I never liked the idea that you can omit the colon from labels).
This is annoying, and not a great solution because many macros try to hide the fact that they are macros. For example, several codebases have macros to emulate Overall I think this is too restrictive. |
I personally heavily disagree with pseudo-op macros, but people should be able to use them if they want to. So then we'd have to fall back to integrating colons in labels (which is something I'm implementing as part of re-doing #437 better), which means editing the lexer and thus this is blocked by #485 at least for me. |
Oh, yeah, I dislike the pseudo-op macros, for sure, but people are going to use them anyway so why not allow them... |
Because a local symbol is necessarily a label, the disambiguation is not necessary. This is a first step towards fixing #457.
To clarify the commit just above: after discussion in #423, it was decided that only labels could be scoped. (If we want to switch to more general, e.g. ca65 scoping, we'll consider this later) Thus, it made the |
Similar happens for |
If this is fixed, some tutorials might have to be changed, like https://eldred.fr/gb-asm-tutorial/syntax.html and maybe https://teamlampoil.se/book/gbasmdev.pdf |
Partial fix for gbdev#457
Partial fix for gbdev#457
The column constraint has been removed on labels, but not on constant definitions or macro calls. Relevant discussion is in #635. |
Taking this as the "new prefix-keyword constant definition syntax" issue: As I said in Discord
Regarding |
This will enable fixing gbdev#457 later once the old definition syntax is removed.
This will enable fixing gbdev#457 later once the old definition syntax is removed.
Actually, |
You once suggested adding a character to indicate a macro call. While I'm strongly against requiring such a character, adding an optional character to signal a macro call would solve all of these problems — just mark the line as a macro call and there's no parsing ambiguity. Since all of the parsing ambiguities like this one are corner cases, that's not really an issue. |
Edit: a workaround could also be encapsulated in its own macro which would serve the same purpose as such a punctuation character.
Edit 2: Then again, there's no use case for character escapes outside of strings, and /* Handle escapes */
case '\\':
c = peek(0);
if (c == ' ' || c == '\r' || c == '\n') {
readLineContinuation();
break;
} else if (c == EOF) {
error("Illegal backslash at end of input\n");
break;
} else {
preventLabel = true;
}
// fallthrough
/* Handle identifiers and escapes... or error out */
default:
if (startsIdentifier(c)) {
...
if (tokenType == T_ID && !preventLabel &&
(lexerState->atLineStart || peek(0) == ':'))
return T_LABEL;
return tokenType;
} Even before removing the column constraint, this would be potentially useful to pass a first argument starting with
|
This will enable fixing gbdev#457 later once the old definition syntax is removed.
This will enable fixing #457 later once the old definition syntax is removed.
Despite that b809384 mentions closing this issue only once the old syntax is removed, it's one of the core components of RGBASM, and thus is scheduled to stay for a while. Thus, I'll be closing this, and we'll open a separate issue to discuss deprecation and/or removal of the old syntax when we get there. As far as I'm concerned, due to how breaking a change it would be to remove that syntax, I would prefer to keep it as long as it doesn't become a significant blocker / maintenance burden. (As it happens now, it's just |
I'm also fine with keeping the old syntax for The only limitation of keeping them around is that it prevents macros from being invoked at column 1, but there's less demand for that than there is for indented definitions anyway. |
Only thing to keep track of is updating the FAQ for 0.5.0, to mention the new syntax for macro definitions, and the fact that they fix the problem. |
Both the old and new syntaxes for defining macros, |
We've all had this before.
Countless users, newbies or not, have been bitten by this before. It would be much better if labels could be declared at not-column-1, and macros called at column 1.
HOWEVER! This is there for a reason: RGBASM allows declaring labels without a colon. This cannot be distinguished from a macro call, so the column is used to decide.
In practice, labels are usually defined using colons, lifting the ambiguity; there is an exception for local labels, but the presence of a dot removes the ambiguity too (see #423). Even if the dot is in the middle of the label, it's still unambiguous.
tl;dr: the column restriction can be removed, potentially saving a lot of headaches, but then it will break code that declares labels without colons. Is this worth it?
PS: I realized that #362 being fixed may remove a use case for the feature in sights., so that's good.
The text was updated successfully, but these errors were encountered: