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

Fixes several bugs with string macros, implements all pronoun/article ones #777

Merged
merged 14 commits into from
Oct 11, 2022

Conversation

Altoids1
Copy link
Contributor

@Altoids1 Altoids1 commented Aug 23, 2022

image

Summary

This is a big fat redesign of how we handle string formatting.

Previously, we used to do formatting by sending two UTF16 characters, a 0x00FF and then another one to indicate the use of the interpolated value.

This has been refactored and replaced with StringFormatEncoder and its various helper procs and enums. We now (in parity with DM, at least for the first byte) emit 0xFFxx, with the bottom byte denoting the use of the format byte.

Doing this allowed me to implement \the, \The, \A, \an, \himself, and a bunch of other articles and pronouns.

Changelog

  • All of the article and pronoun text macros (\He, \the, \himself, etc. ) are now implemented.
  • The Compiler now correctly throws if text macros are missing an interpolated value to depend on.
  • The Compiler now gives a descriptive error if the user attempts to use the (ambiguous) \her or \Her text macros.
  • The Compiler now is lenient in some cases towards accidental capitalization of lowercase text macros.
  • Added explicit unimplemented warning for \th and \s text macros.
  • Fixed, probably, several bugs with string formatting.

@Altoids1 Altoids1 marked this pull request as ready for review August 24, 2022 20:17
@Altoids1 Altoids1 force-pushed the welcome-to-PRONOUN-school branch from efd72a2 to 2dbc7e5 Compare August 24, 2022 20:32
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

DMParser.cs is >2300 lines long before this change, and implementing pronouns is going to make it even longer, so I figure its time to put the helper file to some use.

Marked as a separate commit so you have better diffs to look at during review :^)
A dangling \hers or \The now causes a parsing error, as it should.
We now, like BYOND, give a descriptive error message when user tries to use \her (a macro that can't exist).

While I was here, I decided to be even sweeter and add some leniency with unnecessarily-capitalized macros. 😊
Storing all of our formatting bytes as 0x00FF 0x00-whatever was both breaking parity and wasting bytes, so that's been completely changed in favour of a static class that handles encoding and decoding from formatting bytes, stored passive-aggressively into a not-as-important Unicode codeblock. Various other changes were made to prepare for a wider implementation of text macros.

This compiled and ran OK, so I'm committing here before I start implementing novel functionality.
I had a really strange bug recently and this helped me with debugging, so might as well commit it to master.
This gets the general pattern going for formatted strings.

At first, I thought that I was going to have to do two passes on the string to actually parse it correctly (to harvest the locations of all the interp values, so I know who owns what macro). Realized that I could just push another operand to the opcode proc and save a lot of that time, so that's what's here.
Previously, they would actually cause a compiletime error were they to appear. Now the compiler treats them as it should.
I need a better place to toss all these helpers.
EDIT: Accidentally left debug logging in there, whoops
@Altoids1 Altoids1 force-pushed the welcome-to-PRONOUN-school branch from 91929df to 83601ed Compare October 1, 2022 23:52
…ct#720

I moved this code over into a helper proc so this new stuff has to be re-added here, awkwardly.

EDIT: Also patched for some changes caused by refs becoming semi-implemented.
@Altoids1 Altoids1 force-pushed the welcome-to-PRONOUN-school branch 2 times, most recently from 499446c to a14c7ca Compare October 3, 2022 22:26
@Altoids1 Altoids1 force-pushed the welcome-to-PRONOUN-school branch from a14c7ca to 5c55e6a Compare October 5, 2022 06:27
}
//Suffix macros
case StringFormatEncoder.FormatSuffix.UpperSubjectPronoun:
HandleSuffixPronoun(ref formattedString, interps, prevInterpIndex, new string[] { "He", "She", "They", "Tt" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this new string[] { ... } could be bad for allocations but I don't know the extent to which performance matters here.

@Altoids1 Altoids1 requested a review from wixoaGit October 8, 2022 23:05
@wixoaGit wixoaGit merged commit 3a06b8b into OpenDreamProject:master Oct 11, 2022
@Altoids1 Altoids1 deleted the welcome-to-PRONOUN-school branch October 12, 2022 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants