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

Add a source generator for a Maths language to the samples #690

Closed
wants to merge 4 commits into from
Closed

Add a source generator for a Maths language to the samples #690

wants to merge 4 commits into from

Conversation

lucabol
Copy link
Contributor

@lucabol lucabol commented Dec 31, 2020

The scenario is that a financial/gas/whatever-scientific company wants their mathematicians to write their formulas with a syntax familiar to them and without the risk of introducing bugs. But they also need to run as fast as compiled code (i.e. inline), because that is what their business relies on.

Enter source generators. They now can write:

AreaSquare(l)       = pow(l, 2)
AreaRectangle(w, h) = w * h
AreaCircle(r)       = pi * r * r
Quadratic(a, b, c)  = {-b + sqrt(pow(b,2) - 4 * a * c)} / (2 * a)

PointDist(x', x'', y', y'')     = sqrt(pow([x'-x''],2) + pow([y'-y''], 2))

I needed to build a lexer / parser for the language instead of simple regex substitution to avoid the possibility of an injection attack by a disgruntled employee. I built it in the simplest possible way for the sake of example.

The language supports:

  1. Using prime char in identifiers
  2. Using differents parenthesis
  3. Calling functions in the Math class lowercase and functions defined before in the file (no other functions allowed)
  4. Simpler syntax than C# code (i.e. no types etc...)

This is not completed yet, but done a pull request for the sake of review.

@lucabol lucabol requested a review from a team as a code owner December 31, 2020 14:47
@jmarolf
Copy link
Contributor

jmarolf commented Jan 14, 2021

@lucabol can you pull in the latest changes from master? SourceGeneratorContext no longer exists in the public API and all of our samples where updated here: #625

@lucabol
Copy link
Contributor Author

lucabol commented Jan 14, 2021

I am closing this PR as it was created from an old fork. #695 represents the new one we are merging.

@lucabol lucabol closed this Jan 14, 2021
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