/* global describe, it, xit */
/* jslint node: true, esnext: true */

"use strict";

const chai = require('chai');
const assert = chai.assert;
const expect = chai.expect;
const should = chai.should();

const defineGrammar = require('../src/grammar');


describe("calculator",
  function () {
    function Value(value) {
      return Object.create(null, {
        value: {
          value: value
        }
      });
    }

    let myGrammar = defineGrammar({
      terminals: {
        'number': {}
      },
      infix: {
        '(': {
          precedence: 80
        },
        '+': {
          precedence: 50,
          combine: function (left, right) {
            return Value(left.value + right.value);
          }
        },
        '-': {
          precedence: 50,
          combine: function (left, right) {
            return Value(left.value - right.value);
          }
        },
        '*': {
          precedence: 60,
          combine: function (left, right) {
            return Value(left.value * right.value);
          }
        },
        '/': {
          precedence: 60,
          combine: function (left, right) {
            return Value(left.value / right.value);
          }
        }
      }
    });

    it("evaluates", function () {
      assert.equal(myGrammar.parse("1 + 41 * 3 - 2").value, 122);
    });

    /*
        it("evaluates 2", function () {
          assert.equal(myGrammar.parse("(1 + 41) * 3 - 2").value, 124);
        });
    */
  });

/*
 att1.att2[name='herbert'].att3
*/

@@ -506,18 +506,19 @@
 ,%0A      
-in
+pre
 fix: %7B%0A 
@@ -527,24 +527,238 @@
      '(': %7B%0A
+           led: function(grammar,left) %7B%0A              const e = grammar.expression(0);%0A              grammar.advance(')');%0A              return e; %0A           %7D%0A         %7D%0A      %7D,%0A      infix: %7B%0A        /*'(': %7B%0A
           pr
@@ -772,32 +772,34 @@
 e: 80%0A        %7D,
+*/
 %0A        '+': %7B%0A
@@ -845,32 +845,41 @@
 bine: function (
+grammar, 
 left, right) %7B%0A 
@@ -1014,32 +1014,41 @@
 bine: function (
+grammar, 
 left, right) %7B%0A 
@@ -1183,32 +1183,41 @@
 bine: function (
+grammar, 
 left, right) %7B%0A 
@@ -1323,32 +1323,32 @@
 precedence: 60,%0A
-
           combin
@@ -1360,16 +1360,25 @@
 nction (
+grammar, 
 left, ri

pass grammer as 1st. arg to led