zaach / jison-lex

generates lexical analyzers. used by jison.
57 stars 33 forks source link

Simplify simple return statements. #11

Closed RubenVerborgh closed 1 year ago

RubenVerborgh commented 10 years ago

I noticed a lexer of mine had a lot of the following generated code:

switch($avoiding_name_collisions) {
case 0:/* ignore */
case 1:return 13
break;
case 2:return 16
break;
case 3:return 25
break;
case 4:return 278
break;
case 5:return 279
break;
// …
case 120:console.log(yy_.yytext);
break;
}

This pull requests simplifies this generated code into:

switch($avoiding_name_collisions) {
case 0:/* ignore */
break;
case 120:console.log(yy_.yytext);
break;
default:
  return $case_helper[$avoiding_name_collisions]
}