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

Wrapped utility functions in namespaces #1320

Merged
merged 1 commit into from
Jan 11, 2024
Merged

Wrapped utility functions in namespaces #1320

merged 1 commit into from
Jan 11, 2024

Conversation

spoenemann
Copy link
Contributor

This is a proposal following up on #1260.

  • Wrapped utility functions from ast-util in namespace AstUtils
  • Wrapped utility function from cst-util in namespace CstUtils
  • Wrapped utility functions from grammar-util in namespace GrammarUtils
  • Wrapped utility functions from regexp-util in namespace RegExpUtils
  • Wrapped default value converter functions in namespace ValueConverter
  • Renamed utils files with the suffix utils to be consistent (we already exported UriUtils, so we should follow that)

Using the method described in #1260, this change reduces the number of top-level exported functions from the main export of langium by 67! That number will be further reduced once #1258 is merged.

@spoenemann spoenemann requested a review from msujew December 13, 2023 10:30
@spoenemann
Copy link
Contributor Author

If this is accepted, I can create a public Gist listing all functions contained in each namespace. Then we can attach that to our CHANGELOG to ease the migration to v3.0.0 (we should do the same with the new package exports).

@sailingKieler
Copy link
Contributor

Please also rename the tests in test/utils corresponding to the renamed files in src/utils.

@Lotes
Copy link
Contributor

Lotes commented Dec 22, 2023

I saw a difference in using the namespaces. On one side you are prefixing all olds methods with „XXXUtils.abc“ and one the other side you are deconstructing the namespace with „const { abc } = XXXUtils“. Minor thing, but why is this like that? Having the deconstructor has the advantage that all changes concentrate in the header of each file.

@spoenemann
Copy link
Contributor Author

I saw a difference in using the namespaces. On one side you are prefixing all olds methods with „XXXUtils.abc“ and one the other side you are deconstructing the namespace with „const { abc } = XXXUtils“. Minor thing, but why is this like that? Having the deconstructor has the advantage that all changes concentrate in the header of each file.

These are two options that you can use as a consumer of the library. Both are ok – it depends on how often you use the functions and whether you want to make it explicit where they come from at the usage site.


private isStarting = true;
startRegex: string;
private endRegexStack: string[] = [];
startRegexp: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

These two lines are an inconsistent renaming, I think. In C# we call regular expressions "Regex". In JS we call them "RegExp", but not mix that with C# to "Regexp". See the class name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's why I propose to rename all instances to "RegExp" to be in line with the JavaScript RegExp object.

However, the TerminalRegExpVisitor class is not exported, but is private to the regexp-utils module, so those changes are not relevant for the API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it is private. But I would not argument like that 'because it is private, we do not have to be consistent (it even does not contribute to the API)'. You would also not start to use identifiers like i, j, k for for-loops, just because the code is not so public, like other code.

But I also see that it is just a very minor thing. I can live with this, but my consistency alert is then popping up when I see this again ^^*.

@Lotes
Copy link
Contributor

Lotes commented Jan 3, 2024

Apart from the REGEX(P) renaming, everything else looks good to me.

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

Looks good! I was always a bit unhappy about the distinction of CST and AST related functions that were exported from langium directly. I think this change clears things up nicely and aligns everything with the existing UriUtils.

@spoenemann spoenemann merged commit 728b579 into main Jan 11, 2024
5 checks passed
@spoenemann spoenemann deleted the namespaces branch January 11, 2024 07:37
@msujew msujew added this to the v3.0.0 milestone Feb 14, 2024
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.

4 participants