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

Runner does not handle division expression #70

Open
ghost opened this issue Oct 3, 2020 · 1 comment
Open

Runner does not handle division expression #70

ghost opened this issue Oct 3, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 3, 2020

The lexer and parser both handle the division expression correctly and there are existing tests that demonstrate this. The runner fails to handle division with the error:
Error: I don't recognize expression/literal type ArithmeticExpressionDivideNode

To test this, add the following to assignment.json:

,  {
    "title": "AssignmentWithDivision",
    "tags": "Tag",
    "body": "Test Line\n<<set $testvar to 100 / 5>>\nTest Line2",
    "position": {
      "x": 449,
      "y": 252
    },
    "colorID": 0
  }

Add the following to test_runner.js:

  it('Can evaluate a numeric assignment with division expression', () => {
    runner.load(assignmentYarnData);
    const run = runner.run('AssignmentWithDivision');

    let value = run.next().value;
    expect(value).to.deep.equal(new bondage.TextResult('Test Line', value.data, value.lineNum));

    expect(runner.variables.get('testvar')).to.be.undefined;

    value = run.next().value;
    expect(value).to.deep.equal(new bondage.TextResult('Test Line2', value.data, value.lineNum));

    expect(runner.variables.get('testvar')).to.equal(100 / 5);

    expect(run.next().done).to.be.true;
  });

Run the tests.

@ghost
Copy link
Author

ghost commented Oct 3, 2020

The source of the problem resides in the parser\node.js file

  ArithmeticExpressionDivideNode: class {
    constructor(expression1, expression2) {
      this.type = 'ArithmeticExpressionDivideNode';
      this.expression1 = expression1;
      this.expression2 = expression2;
    }
  },

The definition of ArithmeticExpressionDivideNode is missing "extends Expression".
Should be:

  ArithmeticExpressionDivideNode: class extends Expression {
    constructor(expression1, expression2) {
      super();
      this.type = 'ArithmeticExpressionDivideNode';
      this.expression1 = expression1;
      this.expression2 = expression2;
    }
  },

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

0 participants