-
-
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
Remove column 1 restriction for labels with colons #635
Conversation
Note: update RGBASM(5) to mention that the restriction is relaxed for all labels, not just non-local ones, and for macro defs. Maybe also mention that the colon must stick directly to the label name? This is actually not the case for non-local labels, but mentioning that in the documentation may make it a bit too confusing. |
For the sake of alternatives: you could deprecate |
|
I think that removing |
This still requires some lookahead within the lexer, which is a bad idea for performance and cleanness, and also a maintenance penalty due to having to check specifically for such keywords. Then again, invoking macros with such a token as its first argument becomes impossible, which is merely problem whack-a-mole. I agree it might be less disruptive, but I don't believe it's a good option. I do not like the latter two options I listed, I only wrote them in case someone had an idea how to resolve their shortcomings. I also realize that option 1 is quite problematic, since for example hardware.inc would have to be rewritten... but the fundamental problem is the grammar. |
This check:
was requiring labels to be at the start of a line, and macro usages to be indented. The modified check:
allows labels to be indented or not, but still requires macro usages to be indented, and can't handle How about:
This should return
That goes along with disallowing colon-less labels, but should not require reordering |
I refuse to make the behavior dependent on whether a symbol has been defined or not, or its type. It requires more context to understand how a given piece of code works, and I would get rid of SYM equs STRRPL("\1", "this", "that")
SYM equ 42
purge SYM First natural reaction is certainly a "what!?". If |
Fair enough. That sort of Regarding the other solutions:
Overall I'd rather keep the column 1 restriction, until maybe a 0.5.0 major version update when more severe changes might be acceptable. |
I think that the best solution is the |
|
I don't look forward to updating all those definition lines, but if it's a major update that comes along with user-defined functions (which would replace some of our
|
Should be regex-able. Further, this is the kind of deprecation that I would make last a couple versions, given the size of the change. Alternatively, the behavior could be toggled via a CLI option? |
If definition syntax is going to be changing anyway, and no longer resembling older assemblers so much, how about changing macro syntax? |
So, the verbosity of |
Should this merged as-is? (After rebasing to |
@ISSOtm You said in the #716 discussion that this isn't ready to merge. I'm not sure why, or at least, I think something mergeable could be made out of this if it doesn't do what I think. These case ought to be distinguishable, regardless of leading whitespace:
The ambiguous case is this:
There Anyway, even if macro invocations and definitions still have to depend on their starting column, I think allowing indented labels would be useful. For one thing, it would make indented multi-line inline fragments from #716 less awkward to write. |
Partial fix for gbdev#457
Unless CI fails, this should be merge-able. It doesn't solve the most wanted part of the issue, though. As a temporary hack, we could allow indenting specifically for |
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 test case could also verify that indented mac: MACRO
defines a macro.
Partial fix for #457
What would be left to fully resolve that issue is doing the same for variable definitions (
RB
,EQU
, etc.), which I tried implementing. There was one fundamental (correctness) problem, and a cleanness problem.Implementation
After reading a (non-local) identifier that wasn't a keyword, the lexer discarded all leading whitespace. Then, without shifting (= using
peek
with a non-0 argument), it tries to match a symbol-declaring token (keyword or=
), and returnsT_LABEL
if it does.Correctness problem
If a macro invocation's arguments begins with such a token, which has valid use cases, it would be considered as a label. This is problematic especially for
set
andrl
, which are valid tokens outside of assignments as well.Cleanness problem
Using
peek
with an argument larger than 0 is not a good thing. This may expand arguments too early (in some particularly evil code withshift
, I believe), and is less performance-efficient than if we had onlypeek(0)
. (I want to remove those in the long term).An alternative would be to perform an exploratory lex, and cache the resulting token for the following lexer call... except that macro args may be lex-able properly, and the lexer reports errors as soon as possible. (I don't think adding a way to suppress errors for such an exploratory lex would be a good idea, either.)
Solutions
name EQU value
→EQU name value
). Keep in mind that the root cause of this issue is that an identifier at the beginning of a line, if a macro name, must cause a lexer switch immediately after being lexed, so that macro args can be lexed properly.set
, since=
is a synonym; this would solve the correctness problem, but not the cleanness one. Further, it wouldn't solve therl
issue. (The reason whyrl
is currently not a problem is that the lexer never returns the token that the parser expects for that rule.){space}
withspace EQUS " "
was a workaround to prevent the exploratory lex from detecting the token while preserving the output argument; however, it's a hack (additionally introducing a leading space in the argument, which might cause problems), and Allow {symbol} interpolation outside of strings #634 would break it by expanding{}
pre-peek