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

Allow nested brackets #6

Merged
merged 8 commits into from
Nov 26, 2024
Merged

Allow nested brackets #6

merged 8 commits into from
Nov 26, 2024

Conversation

sjd210
Copy link
Contributor

@sjd210 sjd210 commented Nov 12, 2024

Allowing nested brackets is deceptively complicated compared to allowing single brackets (and only applies to the Chemistry side of the checker).

.bracketed is now a number value representing the number of brackets an Element/Compound/Ion is contained within, such that 0 or undefined represents anything unbracketed. (This is set in the pre-processing augmentNode stage, where any child copies the bracketed of its parent, except a Bracket which increments it by one).

bracketAtomCount is now an array of atom-counting Records of length equal to .bracketed for the node (operating like a stack). Elements are added to the top-level bracketAtomCount when encountered, and the top level count is added to the second level, multiplied by the subscript .coeff (then popped off) when a Bracket is closed.

termAtomCount functions similarly to bracketAtomCount but as the designated always-present bottom level of the stack. Unbracketed Elements are added directly to it, and it is multiplied by the Term's leading coefficient and added to atomCount directly when a Term is closed.

atomCount has not changed. It is only ever incremented when a Term is closed, and has a Fraction value due to our use of Fraction coefficients.

The same process applies to bracketChargeCount, termChargeCount, chargeCount - except that charge is only ever added at an Ion node rather than at an Element node.

The Nuclear Checker has a much more basic structure with just termNucleonCount and nucleonCount in the structure [atomCount, massCount].


Also adds isChargeBalanced and sameCharge to the response, in order to allow the API to give feedback on them.

While making this change, more comments were added across the Checker to (hopefully) make it a lot clearer, as well as some restructuring work - mostly such that Statements have a separate CheckerResponse on their left and right side to stop cross-interference. They are merged for the final response that is logged/sent to API.

@sjd210
Copy link
Contributor Author

sjd210 commented Nov 14, 2024

The tests are failing on this branch, but this is an issue with the tests - not with the checker itself.

An in-progress branch with this nested bracket change and all tests working can be found here.

@sjd210 sjd210 merged commit 43f6235 into main Nov 26, 2024
1 check failed
@sjd210 sjd210 deleted the feature/nested-brackets branch November 26, 2024 10:29
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