Skip to content

Commit

Permalink
move lingering debug logging behind the devDebug check, report the …
Browse files Browse the repository at this point in the history
…number of **unresolved conflicts** as part of the `-I` output at the end of a jison run and clean up the corresponding conflict counting while we re-run the state machine generation in jison when such conflicts have been found... (more work for zaach#205 + zaach#342) Also augment the test set fed into the zaach#342 test grammar to make sure it behaves exactly as desired.
  • Loading branch information
GerHobbelt committed Feb 3, 2017
1 parent cbc0393 commit 1f12e1d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
32 changes: 32 additions & 0 deletions examples/issue-342.jison
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ expr
{ $$ = 'E'; }
;


%%
// feature of the GH fork: specify your own main.
Expand All @@ -63,6 +64,37 @@ parser.main = function () {
console.log("test #2: 'a;' ==> ", rv);
assert.equal(rv, 'XE');
console.log("\nAnd now the failing inputs: even these deliver a result:\n");
// set up an aborting error handler which does not throw an exception
// but returns a special parse 'result' instead:
var errmsg = null;
var errReturnValue = '@@@';
parser.yy.parseError = function (msg, hash) {
errmsg = msg;
return errReturnValue + (hash.parser ? hash.value_stack.slice(0, hash.stack_pointer).join('.') : '???');
};
rv = parser.parse('aa');
console.log("test #3: 'aa' ==> ", rv);
assert.equal(rv, '@@@.T.a');
rv = parser.parse('a');
console.log("test #4: 'a' ==> ", rv);
assert.equal(rv, '@@@.a');
rv = parser.parse(';');
console.log("test #5: ';' ==> ", rv);
assert.equal(rv, '@@@');
rv = parser.parse('?');
console.log("test #6: '?' ==> ", rv);
assert.equal(rv, '@@@');
rv = parser.parse('a?');
console.log("test #7: 'a?' ==> ", rv);
assert.equal(rv, '@@@.a');
// if you get past the assert(), you're good.
console.log("tested OK");
};
Expand Down
42 changes: 24 additions & 18 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ generator.reportGrammarInformation = function reportGrammarInformation() {
this.warn('Number of rows in table:................ ' + rows);
this.warn('Number of columns in table:............. ' + cols);
this.warn('Number of defaulted rows in table:...... ' + defrows);
this.warn('Number of unresolvable conflicts:....... ' + this.conflicts);
this.warn('\n');
};

Expand Down Expand Up @@ -5695,15 +5696,14 @@ var lalr = generator.beget(lookaheadMixin, generatorMixin, lrGeneratorMixin, {
for (var round = 1; round <= 2; round++) {
this.states = this.canonicalCollection();

if (this.DEBUG) {
if (this.DEBUG || devDebug) {
Jison.print('\n-------------------------------------------\nSymbol/Follow sets AFTER canonicalCollection:');
this.displayFollowSets();
Jison.print('\n');
}

this.terms_ = {};

Jison.print('\n-------------------------------------------\nROUND: ' + round);
var newg = this.newg = typal.beget(lookaheadMixin, {
oldg: this,
trace: this.trace,
Expand Down Expand Up @@ -5775,14 +5775,28 @@ var lalr = generator.beget(lookaheadMixin, generatorMixin, lrGeneratorMixin, {
break;
}

Jison.print('\n-------------------------------------------\nNew round to fix conflicts?????????????????????????? ', {
round: round,
conflict_fixing_round: this.conflict_fixing_round,
states: this.conflict_states_LU,
productions: this.conflict_productions_LU
});
if (devDebug > 4) {
Jison.print('\n-------------------------------------------\nNew round to fix conflicts? Completed round:', {
round: round,
conflict_fixing_round: this.conflict_fixing_round,
states: this.conflict_states_LU,
productions: this.conflict_productions_LU
});
} else {
Jison.print('\n'
+ '----------------------------------- NOTICE -------------------------------\n'
+ 'Attempting to resolve the unresolved conflicts in partial LR mode...\n\n'
+ 'When no conflicts are reported in this second round, your grammar is\n'
+ 'accepted as mixed LR/LALR and should work as expected.\n'
+ '--------------------------------------------------------------------------\n\n');
}

this.conflict_fixing_round = true;

// and reset the conflict trackers, which we do not use to attempt to fix the conflict in round #2:
this.conflicts = 0;
this.conflicting_states = [];
this.resolutions = [];
}

this.defaultActions = findDefaults(this.table, this.hasErrorRecovery);
Expand Down Expand Up @@ -5871,23 +5885,15 @@ var lalr = generator.beget(lookaheadMixin, generatorMixin, lrGeneratorMixin, {
handle += ':P' + item.production.id;
}

Jison.print('prod creation for: ', {
prod_id: item.production.id,
new_prod_id: p.id,
stateNum: i,
symbol: symbol,
state: state,
production: item.production,
new_production: p
});

var goes = self.states.item(pathInfo.endState).goes;
if (!goes[handle]) {
goes[handle] = [];
}
goes[handle].push(symbol);

if (devDebug > 2) Jison.print('new production:', {
prod_id: item.production.id,
new_prod_id: p.id,
state: state,
stateNum: i,
production: p,
Expand Down

0 comments on commit 1f12e1d

Please sign in to comment.