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

Parsing shift operations (<< and >>) fails #34

Open
kbublitz opened this issue Jul 15, 2024 · 0 comments
Open

Parsing shift operations (<< and >>) fails #34

kbublitz opened this issue Jul 15, 2024 · 0 comments

Comments

@kbublitz
Copy link

kbublitz commented Jul 15, 2024

It looks like binary shift operations are supposed to be supported, but here is a very simple test case that fails:

    test('leftshift', () {
      const evaluator = ExpressionEvaluator();
      final expression = Expression.parse("2 << 3");

      expect(evaluator.eval(expression, {}), 16);
    });

Here is the eexception I get:

Instance of 'ParserException': end of input expected (at 1:3)
package:petitparser/src/core/result.dart 56:22  Failure.value
package:expressions/src/expressions.dart 32:62  Expression.parse

I have done some investigations and it seems like this has something to do with the order in which the operators are defined. (best guess is that they are matched in order of definition so the first match, single <, 'wins'.) If I change the order of the elements in the binaryOperations definition is seems to work, but I'm not sure if this breaks something else when the precedence is out of order now:

  static const Map<String, int> binaryOperations = {
    '??': 0,
    '||': 1,
    '&&': 2,
    '|': 3,
    '^': 4,
    '&': 5,
    '==': 6,
    '!=': 6,
    '<=': 7,
    '>=': 7,
    '<<': 8,
    '>>': 8,
    '<': 7,
    '>': 7,
    '+': 9,
    '-': 9,
    '*': 10,
    '/': 10,
    '%': 10,
    '~/': 10,
  };
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

No branches or pull requests

1 participant