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

Basic example results in Unexpected token error #31

Open
prokls opened this issue Jul 11, 2014 · 0 comments
Open

Basic example results in Unexpected token error #31

prokls opened this issue Jul 11, 2014 · 0 comments

Comments

@prokls
Copy link

prokls commented Jul 11, 2014

Hi,

I am trying to get kyuri up and running, but am experiencing problems with the most basic example.

prokls@cratch ~/kyuri-test % cat test.feature
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scenario: Add two numbers
      Given I have entered 50 into the calculator
        And I have entered 70 into the calculator
       When I press add
       Then the result should be 120 on the screen
prokls@cratch ~/kyuri-test % ./node_modules/kyuri/bin/kyuri test.feature
/home/prokls/kyuri-test/node_modules/kyuri/lib/kyuri/parser.js:407
      throw new Error('Unexpected token "' + token[0] + '" at line ' + token[2
            ^
Error: Unexpected token "SENTENCE" at line 1
    at Object.Parser.checkToken (/home/prokls/kyuri-test/node_modules/kyuri/lib/kyuri/parser.js:407:13)
    at Object.Parser.parse (/home/prokls/kyuri-test/node_modules/kyuri/lib/kyuri/parser.js:391:14)
    at Object.exports.parse (/home/prokls/kyuri-test/node_modules/kyuri/lib/kyuri/core.js:59:17)
    at /home/prokls/kyuri-test/node_modules/kyuri/bin/kyuri:91:27
    at Array.forEach (native)
    at complete (/home/prokls/kyuri-test/node_modules/kyuri/bin/kyuri:85:9)
    at Array.forEach (native)
    at Object.<anonymous> (/home/prokls/kyuri-test/node_modules/kyuri/bin/kyuri:70:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
prokls@cratch ~/kyuri-test %

So I looked into node_modules/kyuri/lib/kyuri/parser.js and printed token and this.current.transitions.

Parser.prototype = {
  parse: function (tokens) {
    this.tokens = tokens;
    this.ast = {};
    this.isPystring = false;
    this.hasTag = false;
    this.tags = [];
    this.states = Object.create(_states);
    this.current = this.states['start'];
    this.last = null;

    while (this.tokens.length > 0) {
      var token = this.tokens.shift();

      if (token[0] === 'COMMENT') {
        // Ignore comments in parsing for now. 
        // Remark: What would comments look like in generated code?
      }
      else if (token[0] === 'PYSTRING') {
        this.checkPystring(token);
      } 
      else if (token[0] === 'TAG') {
        this.checkTag(token);
      }
      else {
        console.log(token);
        this.checkToken(token);
        this.last = token;
      }
    }

    return this.ast;
  },

  checkToken: function (token) {
    var next = Object.keys(this.current.transitions);
    console.log(this.current.transitions);

    if (next.indexOf(token[0]) !== -1) {
      this.checkTransition(token, this.current.transitions[token[0]]);
    }
    else {
      throw new Error('Unexpected token "' + token[0] + '" at line ' + token[2]);
    }
  },
  ...
}

This gives me

[ 'FEATURE', 'FEATURE', 0 ]
{ FEATURE: { value: 'FEATURE', next: 'feature' } }
[ 'SENTENCE', 'Addition', 0 ]
{ SENTENCE: { value: '*', next: 'featureHeader', build: [Function] } }
[ 'TERMINATOR', '\n', 0 ]
{ TERMINATOR: 
   { value: '*',
     next: 'featureHeader',
     last: [ 'TERMINATOR', 'SENTENCE' ] },
  INDENT: { value: 1, next: 'featureDescription', last: 'TERMINATOR' } }
[ 'SENTENCE', 'In order to avoid silly mistakes', 1 ]
{ TERMINATOR: 
   { value: '*',
     next: 'featureHeader',
     last: [ 'TERMINATOR', 'SENTENCE' ] },
  INDENT: { value: 1, next: 'featureDescription', last: 'TERMINATOR' } }

So the transition table does not contain a SENTENCE, which is really strange.

I hope you guys can help me out here :-)

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