Skip to content

Commit

Permalink
Fix another escaping bug
Browse files Browse the repository at this point in the history
in non-indented verbatim section 2 code.

I also did some reformatting.
  • Loading branch information
DemiMarie committed Nov 2, 2016
1 parent 75f4305 commit e1038db
Showing 1 changed file with 64 additions and 65 deletions.
129 changes: 64 additions & 65 deletions src/scan.l
Expand Up @@ -102,20 +102,22 @@ extern const char *escaped_qstart, *escaped_qend;
posix_compat = true;

#define START_CODEBLOCK(x) do { \
/* Emit the needed line directive... */\
if (indented_code == false) { \
linenum++; \
line_directive_out(NULL, 1); \
} \
add_action(M4QSTART); \
yy_push_state(CODEBLOCK); \
if ((indented_code = x)) ACTION_ECHO; \
} while(0)
/* Emit the needed line directive... */\
if (indented_code == false) { \
linenum++; \
line_directive_out(NULL, 1); \
} \
add_action(M4QSTART); \
yy_push_state(CODEBLOCK); \
if ((indented_code = x)) ACTION_ECHO; \
} while(0)

#define END_CODEBLOCK do { \
yy_pop_state();\
yy_pop_state();\
add_action(M4QEND); \
if (!indented_code) line_directive_out(NULL, 0);\
} while (0)
if (!indented_code) line_directive_out(NULL, 0);\
} while (0)

%}

%option caseless nodefault noreject stack noyy_top_state
Expand Down Expand Up @@ -486,17 +488,18 @@ COMMENT,CODE_COMMENT>{

^{WS} START_CODEBLOCK(true); /* indented code in prolog */

^{NOT_WS}.* { /* non-indented code */
if ( bracelevel <= 0 )
{ /* not in %{ ... %} */
yyless( 0 ); /* put it all back */
yy_set_bol( 1 );
mark_prolog();
BEGIN(SECT2);
}
else
ACTION_ECHO;
}
^{NOT_WS}.* {
/* non-indented code */
if ( bracelevel <= 0 ) {
/* not in %{ ... %} */
yyless( 0 ); /* put it all back */
yy_set_bol( 1 );
mark_prolog();
BEGIN(SECT2);
} else {
START_CODEBLOCK(true);
}
}

. ACTION_ECHO;
{NL} ++linenum; ACTION_ECHO;
Expand Down Expand Up @@ -903,30 +906,28 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */
<ACTION>"/*" ACTION_ECHO; yy_push_state( CODE_COMMENT );

<CODEBLOCK,ACTION>{
"reject" {
ACTION_ECHO;
CHECK_REJECT(yytext);
}
"yymore" {
ACTION_ECHO;
CHECK_YYMORE(yytext);
}
"reject" {
ACTION_ECHO;
CHECK_REJECT(yytext);
}
"yymore" {
ACTION_ECHO;
CHECK_YYMORE(yytext);
}
}

. ACTION_ECHO;
{NL} {
++linenum;
ACTION_ECHO;
if ( bracelevel == 0 ||
(doing_codeblock && indented_code) )
{
if ( doing_rule_action )
add_action( "\tYY_BREAK]""]\n" );

doing_rule_action = doing_codeblock = false;
BEGIN(SECT2);
}
}
. ACTION_ECHO;
{NL} {
++linenum;
ACTION_ECHO;
if (bracelevel == 0 || (doing_codeblock && indented_code)) {
if ( doing_rule_action )
add_action( "\tYY_BREAK]""]\n" );

doing_rule_action = doing_codeblock = false;
BEGIN(SECT2);
}
}
}


Expand All @@ -935,38 +936,36 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */
"{" ACTION_ECHO; ++bracelevel;
"}" ACTION_ECHO; --bracelevel;
[^[:alpha:]_{}\"'/\n\[\]]+ ACTION_ECHO;
[\[\]] ACTION_ECHO;
{NAME} ACTION_ECHO;
[\[\]] ACTION_ECHO;
{NAME} ACTION_ECHO;
"'"([^\'\\\n]|\\.)"'" ACTION_ECHO; /* character constant */
"'" ACTION_ECHO; yy_push_state(CHARACTER_CONSTANT);
\" ACTION_ECHO; BEGIN(ACTION_STRING);
{NL} {
{NL} {
++linenum;
ACTION_ECHO;
if ( bracelevel == 0 )
{
if (bracelevel == 0) {
if ( doing_rule_action )
add_action( "\tYY_BREAK]""]\n" );
add_action( "\tYY_BREAK]""]\n" );

doing_rule_action = false;
BEGIN(SECT2);
}
}
. ACTION_ECHO;
doing_rule_action = false;
BEGIN(SECT2);
}
}
}

<ACTION_STRING>{
[^\]\"\\\n\[MmY]+ ACTION_ECHO;
[^\]\"\\\n\[]+ ACTION_ECHO;
\" ACTION_ECHO; BEGIN(ACTION);
}
<CHARACTER_CONSTANT>{
[^\[\]\'\\\nMmY]+ ACTION_ECHO;
\' ACTION_ECHO; yy_pop_state();
[^\[\]\'\\\n]+ ACTION_ECHO;
\' ACTION_ECHO; yy_pop_state();
}
<ACTION_STRING,CHARACTER_CONSTANT>{
\\. ACTION_ECHO;
{NL} ++linenum; ACTION_ECHO;
. ACTION_ECHO;
{NL} ++linenum; ACTION_ECHO;
[\]\['"] ACTION_ECHO;
}

<COMMENT,CODE_COMMENT,COMMENT_DISCARD,ACTION,ACTION_STRING,CHARACTER_CONSTANT><<EOF>> {
Expand All @@ -991,8 +990,8 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */
<SECT3>{
{M4QSTART} fputs(escaped_qstart, yyout);
{M4QEND} fputs(escaped_qend, yyout);
[^\[\]\n]*(\n?) ECHO;
.|\n ECHO;
[^\[\]]* ECHO;
[][] ECHO;
<<EOF>> {
sectnum = 0;
yyterminate();
Expand All @@ -1001,8 +1000,8 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */
<SECT3_NOESCAPE>{
{M4QSTART} fprintf(yyout, "[""[%s]""]", escaped_qstart);
{M4QEND} fprintf(yyout, "[""[%s]""]", escaped_qend);
[^\[\]\n]*(\n?) ECHO;
(.|\n) ECHO;
[^][]* ECHO;
[][] ECHO;
<<EOF>> {
sectnum = 0;
yyterminate();
Expand Down

0 comments on commit e1038db

Please sign in to comment.