Repository navigation
Conversation
replace_top required a scalar, so -A and -trace(A) raised a type mismatch although negation is defined in all three domains. It now visits the operand variant and negates any expression alternative; only a bracket-list is rejected. Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
The '^' right operand was `power`, which cannot start with '-', so 2^-3 and x^-1 failed with a misleading eof error. It is now `unary`, which recurses back into `power`: right associativity of 2^3^2 and the -(x^2) reading of -x^2 are unchanged. Tests cover both issues: negative exponents (literal, identifier, decimal, parenthesized-equivalence, right associativity) and unary minus on tensor and t2s operands compared against the C++-built nodes. Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
This was referenced Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #365.
Closes #366.
Two independent grammar/action defects, one commit each.
#365 — unary minus rejected tensor and t2s operands
replace_top(src/numsim_cas/parser/actions.h) calledrequire_scalar, so-A,-trace(A)and-det(A)raisedtype_mismatch_error: operator expects scalar operandseven though negation is defined in all three domains (expression_holder::operator-, withneg_fntag_invokes for tensor and t2s). Users had to write-1 * A.It now visits the operand variant and negates whichever expression alternative it holds; only
index_list_valueis rejected, with a message matching the existing bracket-list wording used by the binary operators.#366 — negative exponents unparseable
power_tailwasseq<ws, caret_op, ws, power>, andpowercannot start with-, so2^-3andx^-1failed. The parser accepted the left operand and then choked, producing the misleadingparse error at 1:2: parse error matching tao::pegtl::eof.The right operand is now
unary, which recurses back intopower.Precedence decisions (unchanged, and pinned by tests):
2^3^22^(3^2)= 512unary→powerkeeps the right recursion2^-3^22^(-(3^2))= 2⁻⁹^tail binds before negating the exponent-x^2-(x^2)unarylevel abovepower; left operands stay atprimary2^3*4(2^3)*4= 32^still binds tighter than*2^-3*4(2^-3)*4= 0.5x^-3andx^(-3)now produce structurally identical nodes (hash and deep equality both checked).Tests
10 new in
ParserGrammar:NegativeExponentLiteral,NegativeExponentOnIdentifier(incl.x^-2.5),NegativeExponentMatchesParenthesizedForm,NegativeExponentKeepsRightAssociativity,UnaryMinusOnTensorMatchesCppNegation,UnaryMinusOnT2sMatchesCppNegation,UnaryMinusOnTensorSum,DoubleUnaryMinusOnTensorCancels,UnaryMinusOnDetIsT2s,UnaryMinusRejectsBracketList. The tensor/t2s cases compare the parsed expression against the C++-built node with deep==, not just "parsing succeeded".Negative control: against unfixed sources, 9 of the 10 fail (the bracket-list rejection passes both ways by design). The pre-existing precedence pins —
PowerRightAssociative,PowerBindsTighterThanMul,PowerBindsTighterThanUnaryMinus,UnaryMinusBindsTighterThanMul,DoubleUnaryMinusCancels,BinaryMinusVsUnaryMinusAfterBinary— pass throughout; none was modified.Error quality: verified against
mainthat genuinely invalid inputs are unchanged —2^,2^*3andx^-produce the same message and position as before (the internal PEGTL rule name leaking there is pre-existing, #367's scope).Full parser-enabled suite: 2601/2601 (gcc-14 Debug,
NUMSIM_CAS_BUILD_PARSER=ON). clang-format-18 clean.