littlewing 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -687,9 +687,11 @@ declare class Parser {
687
687
  private parseFunctionArguments;
688
688
  /**
689
689
  * Get unary operator precedence
690
- * Returns 6 which is higher than add/sub (6) but lower than exponentiation (8)
691
- * This means: -2^2 parses as -(2^2) = -4, not (-2)^2 = 4
692
- * Matches the behavior of Python, Ruby, and most languages
690
+ * Returns 7 which is higher than add/sub (6) but lower than exponentiation (8)
691
+ * This means:
692
+ * - Binds tighter than addition: -2 + 3 parses as (-2) + 3 = 1
693
+ * - Binds looser than exponentiation: -2^2 parses as -(2^2) = -4, not (-2)^2 = 4
694
+ * Matches the behavior of Python, JavaScript, and most languages
693
695
  */
694
696
  private getUnaryPrecedence;
695
697
  /**
package/dist/index.js CHANGED
@@ -353,7 +353,7 @@ class CodeGenerator {
353
353
  generateBinaryOp(node) {
354
354
  const left = this.generate(node.left);
355
355
  const right = this.generate(node.right);
356
- const leftNeedsParens = this.needsParensLeft(node.left, node.operator);
356
+ const leftNeedsParens = this.needsParensLeft(node.left, node.operator) || node.operator === "^" && isUnaryOp(node.left);
357
357
  const leftCode = leftNeedsParens ? `(${left})` : left;
358
358
  const rightNeedsParens = this.needsParensRight(node.right, node.operator);
359
359
  const rightCode = rightNeedsParens ? `(${right})` : right;
@@ -857,7 +857,8 @@ class Parser {
857
857
  } else if (this.isBinaryOperator(token.type)) {
858
858
  const operator = token.value;
859
859
  this.advance();
860
- const right = this.parseExpression(precedence + 1);
860
+ const isRightAssociative = operator === "^";
861
+ const right = this.parseExpression(isRightAssociative ? precedence : precedence + 1);
861
862
  left = binaryOp(left, operator, right);
862
863
  } else {
863
864
  break;
@@ -914,7 +915,7 @@ class Parser {
914
915
  return args;
915
916
  }
916
917
  getUnaryPrecedence() {
917
- return 6;
918
+ return 7;
918
919
  }
919
920
  isBinaryOperator(type) {
920
921
  return BINARY_OPERATOR_TOKENS.has(type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlewing",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "A minimal, high-performance arithmetic expression language with lexer, parser, and executor. Optimized for browsers with zero dependencies and type-safe execution.",
5
5
  "keywords": [
6
6
  "arithmetic",