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

Error "Cannot read property 'format' of undefined " #21

Closed
rogerdielrton opened this issue May 14, 2014 · 3 comments
Closed

Error "Cannot read property 'format' of undefined " #21

rogerdielrton opened this issue May 14, 2014 · 3 comments

Comments

@rogerdielrton
Copy link

The following JS piece of code, on execution, fails:

window.setTimeout(function () {
    var strict = Optional(Terminal("strict"));
    var graph = Choice(Terminal("graph"), Terminal("digraph"));
    var id = Optional(NonTerminal("ID"));
    var stmtList = NonTerminal("stmt_list");
    var seq = Sequence(strict, graph, id, Terminal("{"), stmtList, Terminal("}"));  
    var o = Diagram(seq);
    o.addTo(window.document.body);
}, 1000);

And, this other one (is an equivalent of the preceding) also:

Diagram(
    Sequence(
        Optional(Terminal("strict")),
        Choice(Terminal("graph"), Terminal("digraph")),
        Optional(NonTerminal("ID")),
        Terminal("{"),
        NonTerminal("stmt_list"),
        Terminal("}")))
.addTo();   

Error details:

Message:
    Uncaught TypeError: Cannot read property 'format' of undefined 
File:
    railroad-diagrams.js
Line:
    291
@tabatkins
Copy link
Owner

The first argument of Choice() has to be the index of which option is the "normal" option. I've added some checking and better error-messages, so your mistake gets caught upon construction and tells you what's wrong, rather than just throwing a mysterious-looking error message during .format().

@rogerdielrton
Copy link
Author

Excuse me for the lost of time. I do't put attention to the example of:
http://www.xanthir.com/etc/railroad-diagrams/example.html

Finally, as general reflexion, I must say that coding in JS is not tented to make validation, checking, etc. Principally because it adds more verbosity and is tedious. But, it save a lot of time when the users (pity users like me) of that library use it in his code.

@tabatkins
Copy link
Owner

No problem, the error was showing up at a bad and confusing place; I'm happy to make it simpler to find this common authoring error.

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

2 participants