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

output of parser error to console in debug mode #311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ cli.main = function cliMain(opts) {
function processGrammar(raw, lex, opts) {
var grammar,
parser;
grammar = cli.processGrammars(raw, lex, opts.json);
grammar = cli.processGrammars(raw, lex, opts.json, opts.debug);
parser = cli.generateParserString(opts, grammar);
return parser;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ cli.generateParserString = function generateParserString(opts, grammar) {
return generator.generate(settings);
};

cli.processGrammars = function processGrammars(file, lexFile, jsonMode) {
cli.processGrammars = function processGrammars(file, lexFile, jsonMode, debugMode) {
"use strict";
lexFile = lexFile || false;
jsonMode = jsonMode || false;
Expand All @@ -168,13 +168,19 @@ cli.processGrammars = function processGrammars(file, lexFile, jsonMode) {
grammar = ebnfParser.parse(file);
}
} catch (e) {
if (debugMode === true) {
console.log(e);
}
throw new Error('Could not parse jison grammar');
}
try {
if (lexFile) {
grammar.lex = require('lex-parser').parse(lexFile);
}
} catch (e) {
if (debugMode === true) {
console.log(e);
}
throw new Error('Could not parse lex grammar');
}
return grammar;
Expand Down