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: add dollar as valid identifier char #29

Closed
wants to merge 4 commits into from

Conversation

moisespsena
Copy link

This PR will allow the use of the dollar in identifiers, such as JavaScript.

My intention is to create a template language with UGO, and define the dollar prefixed variables will make it more intuitive.

docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
docs/tutorial.md Show resolved Hide resolved
docs/tutorial.md Outdated Show resolved Hide resolved
@codeclimate
Copy link

codeclimate bot commented Aug 10, 2023

Code Climate has analyzed commit e467851 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Style 1

View more on Code Climate.

@ozanh
Copy link
Owner

ozanh commented Aug 19, 2023

Hi @moisespsena, thank you for the PR.
I haven't considered anything about using uGO as a template language.
I can give it a try under the following conditions and questions.

  • As this will be an experimental feature, this should be an optional feature and enabled with a build tag.
  • I cannot maintain a template library (this is not addressed in this PR), so you should be responsible for the maintenance.
  • $ sign was abused by some JS libraries. Is that what we really want? I think Go's template library preferred to use $ for template variables to reduce parser complexity.
  • Do you have a plan to create a template parser?

uGO is used in production a lot, and we cannot introduce anything easily, especially syntax changes.

So making it optional until it is fully implemented and production-ready is the only choice for now.

If you want to go ahead, please create an "exp" package in the project workspace and define a constant like const ExperimentalDollar bool which should be true with tag ugo_exp_dollar. Then you should use if statements in scanner and parser to handle $ conditionally using this constant. It is important to make it constant to let the Go compiler trim unused code if tag is not provided.

Additional requirements about the PR:

  • Please remove the code added in docs/tutorial. You don't need to show the implementation detail when we can write it as a readable sentence.
  • $ sign is supposed to be used less, so while checking each character it should be the last condition.

@ozanh
Copy link
Owner

ozanh commented Sep 3, 2023

Please open a new PR if you'd like to continue.

@ozanh ozanh closed this Sep 3, 2023
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