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 support for currency #10

Merged
merged 2 commits into from
Jan 12, 2024
Merged

feat: add support for currency #10

merged 2 commits into from
Jan 12, 2024

Conversation

danvk
Copy link
Owner

@danvk danvk commented Jan 11, 2024

This is off track from the book, but I thought it would be a fun extension to support expressions like $12.34 + $13.78.

Any mix of units is allowed for now, though I might want to tweak this in the future. For example 2 * $12.34 makes sense but 2 + $12.34 probably doesn't.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

PR Compliance Checks

Thank you for your Pull Request! We have run several checks on this pull request in order to make sure it's suitable for merging into this project. The results are listed in the following section.

Issue Reference

In order to be considered for merging, the pull request description must refer to a specific issue number. This is described in our Contributing Guide. We are closing this pull request for now but you can update the pull request description and reopen the pull request.
The check is looking for a phrase similar to: "Fixes #XYZ" or "Resolves #XYZ" where XYZ is the issue number that this PR is meant to address.

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f13b9c8) 86.76% compared to head (6002efb) 87.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
+ Coverage   86.76%   87.00%   +0.23%     
==========================================
  Files           8        8              
  Lines         544      554      +10     
  Branches       68       71       +3     
==========================================
+ Hits          472      482      +10     
  Misses         71       71              
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danvk danvk merged commit d6db125 into main Jan 12, 2024
15 checks passed
@danvk danvk deleted the add-currency branch January 12, 2024 13:49
danvk added a commit that referenced this pull request Jan 20, 2024
Implementation of [Chapter 10] of _Crafting Interpreters_.

I wondered back in #10 whether I'd be shooting myself in the foot by
supporting `,` as a number separator (`1,234`). This is where it
happened. The comma becomes quite ambiguous in the arguments list of a
function call. For exmaple:

```
f(1,234,567);
```

Is that a call to `f` with a single argument, `1,234,567` or a call to
`f` with three arguments, `1`, `234` and `567`? The grammar is
ambiguous.

My solution is to make spaces significant while scanning:

```
f(1,234,567);  // one argument
f(1, 234, 567);  // three arguments
```

We'll see how this holds up!

[Chapter 10]: https://craftinginterpreters.com/functions.html
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.

1 participant