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

feat: implement multiline support (continued) #58

Merged
merged 7 commits into from
Dec 28, 2024

Conversation

joshuakb2
Copy link
Contributor

I saw #51 and thought it was a good idea, so I thought I'd try to get it over the finish line.

I rebased aurelien-brabant's commits onto main as they had fallen behind. I fixed a typo in his code and changed the RHS index to use std::string::at like you suggested.

what if line.find_last_not_of(MULTILINE_SPACE_CHARSET) returns std::string::npos

This appears to be a non-issue. In that case the code is evaluated as line.substr(0, 0).

I also added another multiline test for configs that contain a whole empty line in the middle, and I fixed a bug where the RHS was assumed to be non-empty.

Let me know if you still have concerns about this feature and I'll see if I can address them.

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

considering multi-line stuff can only happen when parsing a config file, I am in favor of moving them out of the ::parseLine func altogether. This adds needless complexity.

I would instead move it to parseFile and parseRawStream

@joshuakb2
Copy link
Contributor Author

In that case, I'll take another look at this change and see about implementing it the way you're describing. Thanks for the quick feedback!

@joshuakb2 joshuakb2 force-pushed the feat/add-multi-line-support branch from d45287c to 2c50933 Compare December 16, 2024 06:57
@joshuakb2
Copy link
Contributor Author

I implemented a simpler version of multi-line support in parseFile and parseRawStream.

Functional changes from the previous implementation:

  • The \ at the end of the line may not be followed by a comment or whitespace.
  • Lines ending with > are not treated specially at all.

I should also point out that this feature is a breaking change because people may have config lines ending with backslashes where those backslashes are currently treated as normal text. But this was true of the previous implementation as well.

I welcome any feedback, and thanks again for considering this pull request!

@joshuakb2
Copy link
Contributor Author

I consolidated the logic for getting the full next line (taking backslashes into account) into a helper function that returns std::expected like you suggested. What do you think?

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

rest lgtm

@joshuakb2
Copy link
Contributor Author

Cool! I've addressed those changes you asked for. Thanks!

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

rest lgtm

src/config.hpp Outdated
GETNEXTLINEFAILURE_BACKSLASH,
};

static std::expected<std::string, eGetNextLineFailure> getNextLine(std::istream& str, int &rawLineNum, int &lineNum);
Copy link
Member

Choose a reason for hiding this comment

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

this is not used outside of config.cpp, this can be removed altogether

@vaxerski
Copy link
Member

You don't need to define stuff in a header if it's only used in one source file, it only increases the compilation time

@joshuakb2
Copy link
Contributor Author

Alright, I've fixed that now. Thanks for the feedback, I hadn't considered that. I don't write much C++ these days but it's good to get a little practice in.

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

thanks!

@vaxerski vaxerski merged commit 55608ef into hyprwm:main Dec 28, 2024
7 checks passed
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.

2 participants