Skip to content

Commit 0fd385d

Browse files
committed
working on examples set to test code generator feature filters
1 parent f03efdf commit 0fd385d

22 files changed

+272
-389
lines changed

examples/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ ALL_TARGETS = \
238238

239239
all: $(ALL_TARGETS)
240240

241-
.PHONY: all clean superclean error-handling-tests basic-tests github-issue-tests misc-tests $(ALL_TARGETS) comparison
241+
.PHONY: all clean superclean error-handling-tests basic-tests github-issue-tests misc-tests codegen-feature-tester $(ALL_TARGETS) comparison
242242

243243

244244
clean:
@@ -715,6 +715,8 @@ comparison: \
715715
diff -q -r -t --tabsize=4 -a -I ' generated by ' -B -E -Z -w -X comparison-diff-filter-extensions.txt ./reference-output/ ./output/
716716

717717

718+
codegen-feature-tester: $(CODEGEN_TARGETS)
719+
718720
codegen-feature-tester-base:
719721
$(JISON) --main ./$(CGT)-base.jison -o ./output/$(CGT)/$(CGT)-base.js
720722
node ./output/$(CGT)/$(CGT)-base.js

examples/codegen-feature-tester-base.jison

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110

111111
%start expressions
112112

113-
%options parser-errors-are-recoverable lexer-errors-are-recoverable
113+
%option parser-errors-are-recoverable
114+
%option lexer-errors-are-recoverable
114115

115116

116117

@@ -364,8 +365,16 @@ parser.main = function () {
364365
for (var i = 0, len = formulas_and_expectations.length; i < len; i += 2) {
365366
var formula = formulas_and_expectations[i];
366367
var expectation = formulas_and_expectations[i + 1];
367-
368-
var rv = parser.parse(formula);
368+
var rv;
369+
370+
try {
371+
rv = parser.parse(formula);
372+
} catch (ex) {
373+
var stk = '' + ex.stack;
374+
stk = stk.replace(/\t/g, ' ')
375+
.replace(/ at (.+?)\(.*?[\\/]([^\\/\s]+)\)/g, ' at $1($2)');
376+
rv = 'ERROR:' + ex.name + '::' + ex.message + '::' + stk;
377+
}
369378
print("'" + formula + "' ==> ", rv, "\n");
370379
if (isNaN(rv) && isNaN(expectation)) {
371380
assert(1);

examples/codegen-feature-tester-no-default-action.jison

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110

111111
%start expressions
112112

113-
%options parser-errors-are-recoverable lexer-errors-are-recoverable
113+
%option parser-errors-are-recoverable
114+
%option lexer-errors-are-recoverable
114115

115116

116117

@@ -364,8 +365,16 @@ parser.main = function () {
364365
for (var i = 0, len = formulas_and_expectations.length; i < len; i += 2) {
365366
var formula = formulas_and_expectations[i];
366367
var expectation = formulas_and_expectations[i + 1];
367-
368-
var rv = parser.parse(formula);
368+
var rv;
369+
370+
try {
371+
rv = parser.parse(formula);
372+
} catch (ex) {
373+
var stk = '' + ex.stack;
374+
stk = stk.replace(/\t/g, ' ')
375+
.replace(/ at (.+?)\(.*?[\\/]([^\\/\s]+)\)/g, ' at $1($2)');
376+
rv = 'ERROR:' + ex.name + '::' + ex.message + '::' + stk;
377+
}
369378
print("'" + formula + "' ==> ", rv, "\n");
370379
if (isNaN(rv) && isNaN(expectation)) {
371380
assert(1);

examples/codegen-feature-tester-no-err-api-usage.jison

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110

111111
%start expressions
112112

113-
%options parser-errors-are-recoverable lexer-errors-are-recoverable
113+
// %option parser-errors-are-recoverable
114+
// %option lexer-errors-are-recoverable
114115

115116

116117

@@ -128,19 +129,6 @@ expressions
128129
// to be a recognizer, but that is not the case here!)
129130
$$ = $1;
130131
}
131-
| error EOF
132-
{
133-
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, '@$': @$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
134-
135-
print('~~~EOF~~~', parser.describeSymbol(#error), ' error: ', { '$1': typeof $1, yytext: yytext, '@error': @error, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
136-
yyerrok;
137-
yyclearin;
138-
$$ = 17;
139-
// ^-- every error recovery rule in this grammar adds a different value
140-
// so we can track which error rule(s) were executed during the parse
141-
// of (intentionally) erroneous test expressions.
142-
print('ERROR', #1, $2, '==>', $$);
143-
}
144132
;
145133

146134
e
@@ -154,17 +142,6 @@ e
154142
$$ = $1 - $3;
155143
print($1, $2, $3, '==>', $$);
156144
}
157-
| e error e
158-
{
159-
print('~~~EXPR-OPERATOR~~~', parser.describeSymbol(#error), ' error: ', { '$1': $1, '$2': typeof $2, '$3': $3, yytext: yytext, '@error': @error, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
160-
yyerrok;
161-
yyclearin;
162-
$$ = $e1 + 13 + $e2;
163-
// ^-- every error recovery rule in this grammar adds a different value
164-
// so we can track which error rule(s) were executed during the parse
165-
// of (intentionally) erroneous test expressions.
166-
print($1, 'ERROR', #2, $3, '==>', $$);
167-
}
168145
| m
169146
;
170147

@@ -254,19 +231,6 @@ v
254231
$$ = Math.PI;
255232
print($1, '==>', $$);
256233
}
257-
| error
258-
{
259-
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, '@$': @$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
260-
261-
print('~~~V~~~', parser.describeSymbol(#$), ' error: ', { '$1': typeof $1, '@$': @$, token: parser.describeSymbol(#$), msg: $error.errStr }, yy.lastErrorMessage, yy.lastErrorHash.token, yysp);
262-
yyerrok;
263-
yyclearin;
264-
$$ = 5;
265-
// ^-- every error recovery rule in this grammar adds a different value
266-
// so we can track which error rule(s) were executed during the parse
267-
// of (intentionally) erroneous test expressions.
268-
print('ERROR', #1, '==>', $$);
269-
}
270234
;
271235

272236

@@ -323,20 +287,6 @@ if (0) {
323287
324288
325289
326-
parser.yy.parseError = function parseError(str, hash, ExceptionClass) {
327-
assert(hash.yy);
328-
assert(this);
329-
assert(this !== parser.yy);
330-
assert(this === hash.yy.parser || this === hash.yy.lexer);
331-
if (hash.recoverable) {
332-
hash.yy.parser.trace(str);
333-
hash.yy.lastErrorMessage = str;
334-
hash.yy.lastErrorHash = hash;
335-
} else {
336-
console.error(str, hash && hash.exception);
337-
throw new ExceptionClass(str, hash);
338-
}
339-
};
340290
341291
342292
@@ -355,7 +305,7 @@ parser.main = function () {
355305
const formulas_and_expectations = [
356306
basenum + '+2*(3-5--+--+6!)-7/-8%', 1523.5 + basenum,
357307
basenum + '+2*0.7%^PI^2+4+5', 9 + basenum, /* this bets on JS floating point calculations discarding the small difference with this integer value... */
358-
basenum + '+(2+3*++++)+5+6+7+8+9 9', 74 + basenum, // with error recovery and all it gives you a value...
308+
basenum + '+(2+3*++++)+5+6+7+8+9 9', NaN, // with no error recovery it'll give you a crash result
359309
basenum + '+2*(3!-5!-6!)/7/8', -29.785714285714285 + basenum,
360310
];
361311
@@ -364,8 +314,16 @@ parser.main = function () {
364314
for (var i = 0, len = formulas_and_expectations.length; i < len; i += 2) {
365315
var formula = formulas_and_expectations[i];
366316
var expectation = formulas_and_expectations[i + 1];
367-
368-
var rv = parser.parse(formula);
317+
var rv;
318+
319+
try {
320+
rv = parser.parse(formula);
321+
} catch (ex) {
322+
var stk = '' + ex.stack;
323+
stk = stk.replace(/\t/g, ' ')
324+
.replace(/ at (.+?)\(.*?[\\/]([^\\/\s]+)\)/g, ' at $1($2)');
325+
rv = 'ERROR:' + ex.name + '::' + ex.message + '::' + stk;
326+
}
369327
print("'" + formula + "' ==> ", rv, "\n");
370328
if (isNaN(rv) && isNaN(expectation)) {
371329
assert(1);

examples/codegen-feature-tester-no-error-recovery.jison

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110

111111
%start expressions
112112

113-
%options parser-errors-are-recoverable lexer-errors-are-recoverable
113+
// %option parser-errors-are-recoverable
114+
// %option lexer-errors-are-recoverable
114115

115116

116117

@@ -128,19 +129,6 @@ expressions
128129
// to be a recognizer, but that is not the case here!)
129130
$$ = $1;
130131
}
131-
| error EOF
132-
{
133-
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, '@$': @$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
134-
135-
print('~~~EOF~~~', parser.describeSymbol(#error), ' error: ', { '$1': typeof $1, yytext: yytext, '@error': @error, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
136-
yyerrok;
137-
yyclearin;
138-
$$ = 17;
139-
// ^-- every error recovery rule in this grammar adds a different value
140-
// so we can track which error rule(s) were executed during the parse
141-
// of (intentionally) erroneous test expressions.
142-
print('ERROR', #1, $2, '==>', $$);
143-
}
144132
;
145133

146134
e
@@ -154,17 +142,6 @@ e
154142
$$ = $1 - $3;
155143
print($1, $2, $3, '==>', $$);
156144
}
157-
| e error e
158-
{
159-
print('~~~EXPR-OPERATOR~~~', parser.describeSymbol(#error), ' error: ', { '$1': $1, '$2': typeof $2, '$3': $3, yytext: yytext, '@error': @error, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
160-
yyerrok;
161-
yyclearin;
162-
$$ = $e1 + 13 + $e2;
163-
// ^-- every error recovery rule in this grammar adds a different value
164-
// so we can track which error rule(s) were executed during the parse
165-
// of (intentionally) erroneous test expressions.
166-
print($1, 'ERROR', #2, $3, '==>', $$);
167-
}
168145
| m
169146
;
170147

@@ -254,19 +231,6 @@ v
254231
$$ = Math.PI;
255232
print($1, '==>', $$);
256233
}
257-
| error
258-
{
259-
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, '@$': @$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
260-
261-
print('~~~V~~~', parser.describeSymbol(#$), ' error: ', { '$1': typeof $1, '@$': @$, token: parser.describeSymbol(#$), msg: $error.errStr }, yy.lastErrorMessage, yy.lastErrorHash.token, yysp);
262-
yyerrok;
263-
yyclearin;
264-
$$ = 5;
265-
// ^-- every error recovery rule in this grammar adds a different value
266-
// so we can track which error rule(s) were executed during the parse
267-
// of (intentionally) erroneous test expressions.
268-
print('ERROR', #1, '==>', $$);
269-
}
270234
;
271235

272236

@@ -355,7 +319,7 @@ parser.main = function () {
355319
const formulas_and_expectations = [
356320
basenum + '+2*(3-5--+--+6!)-7/-8%', 1523.5 + basenum,
357321
basenum + '+2*0.7%^PI^2+4+5', 9 + basenum, /* this bets on JS floating point calculations discarding the small difference with this integer value... */
358-
basenum + '+(2+3*++++)+5+6+7+8+9 9', 74 + basenum, // with error recovery and all it gives you a value...
322+
basenum + '+(2+3*++++)+5+6+7+8+9 9', NaN, // with no error recovery it'll give you a crash result
359323
basenum + '+2*(3!-5!-6!)/7/8', -29.785714285714285 + basenum,
360324
];
361325
@@ -364,8 +328,16 @@ parser.main = function () {
364328
for (var i = 0, len = formulas_and_expectations.length; i < len; i += 2) {
365329
var formula = formulas_and_expectations[i];
366330
var expectation = formulas_and_expectations[i + 1];
367-
368-
var rv = parser.parse(formula);
331+
var rv;
332+
333+
try {
334+
rv = parser.parse(formula);
335+
} catch (ex) {
336+
var stk = '' + ex.stack;
337+
stk = stk.replace(/\t/g, ' ')
338+
.replace(/ at (.+?)\(.*?[\\/]([^\\/\s]+)\)/g, ' at $1($2)');
339+
rv = 'ERROR:' + ex.name + '::' + ex.message + '::' + stk;
340+
}
369341
print("'" + formula + "' ==> ", rv, "\n");
370342
if (isNaN(rv) && isNaN(expectation)) {
371343
assert(1);

examples/codegen-feature-tester-no-location-tracking.jison

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ expressions
130130
}
131131
| error EOF
132132
{
133-
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, '@$': @$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
133+
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
134134
135-
print('~~~EOF~~~', parser.describeSymbol(#error), ' error: ', { '$1': typeof $1, yytext: yytext, '@error': @error, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
135+
print('~~~EOF~~~', parser.describeSymbol(#error), ' error: ', { '$1': typeof $1, yytext: yytext, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
136136
yyerrok;
137137
yyclearin;
138138
$$ = 17;
@@ -156,7 +156,7 @@ e
156156
}
157157
| e error e
158158
{
159-
print('~~~EXPR-OPERATOR~~~', parser.describeSymbol(#error), ' error: ', { '$1': $1, '$2': typeof $2, '$3': $3, yytext: yytext, '@error': @error, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
159+
print('~~~EXPR-OPERATOR~~~', parser.describeSymbol(#error), ' error: ', { '$1': $1, '$2': typeof $2, '$3': $3, yytext: yytext, token: parser.describeSymbol(#error), msg: $error.errStr }, yy.lastErrorMessage);
160160
yyerrok;
161161
yyclearin;
162162
$$ = $e1 + 13 + $e2;
@@ -256,9 +256,9 @@ v
256256
}
257257
| error
258258
{
259-
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, '@$': @$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
259+
//print('~~~ (...) error: ', { '$1': $1, '#1': #1, yytext: yytext, '$$': $$, token: parser.describeSymbol(#$), 'yystack': yystack, 'yyvstack': yyvstack, 'yylstack': yylstack, last_error: yy.lastErrorMessage});
260260
261-
print('~~~V~~~', parser.describeSymbol(#$), ' error: ', { '$1': typeof $1, '@$': @$, token: parser.describeSymbol(#$), msg: $error.errStr }, yy.lastErrorMessage, yy.lastErrorHash.token, yysp);
261+
print('~~~V~~~', parser.describeSymbol(#$), ' error: ', { '$1': typeof $1, token: parser.describeSymbol(#$), msg: $error.errStr }, yy.lastErrorMessage, yy.lastErrorHash.token, yysp);
262262
yyerrok;
263263
yyclearin;
264264
$$ = 5;

0 commit comments

Comments
 (0)