From 9160ceb67ff5317753ff71c623b037126862a32f Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 28 Feb 2016 21:12:45 +0100 Subject: cast to get rid of warnings --- src/scan.l | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index cfc832d..65bdf89 100644 --- a/src/scan.l +++ b/src/scan.l @@ -685,7 +685,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ else { /* push back name surrounded by ()'s */ - int len = strlen( nmdefptr ); + size_t len = strlen( nmdefptr ); if (end_is_ws) unput(end_ch); -- cgit v1.2.3 From 48152721a0591f3bdb4a96c4dc12bb210685151c Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 28 Feb 2016 10:36:06 +0100 Subject: scan.l, rewrite two loops to avoid unneccesairy casting --- src/scan.l | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 65bdf89..6c1985b 100644 --- a/src/scan.l +++ b/src/scan.l @@ -78,8 +78,10 @@ extern const char *escaped_qstart, *escaped_qend; return NAME; #define PUT_BACK_STRING(str, start) \ - for ( i = strlen( str ) - 1; i >= start; --i ) \ - unput((str)[i]) + { size_t i = strlen( str ); \ + while ( i > start ) \ + unput((str)[--i]); \ + } #define CHECK_REJECT(str) \ if ( all_upper( str ) ) \ @@ -134,7 +136,7 @@ M4QEND "]]" static int option_sense; int doing_codeblock = false; - int i, brace_depth=0, brace_start_line=0; + int brace_depth=0, brace_start_line=0; char nmdef[MAXLINE]; @@ -301,12 +303,12 @@ M4QEND "]]" FLEX_EXIT(EXIT_FAILURE); } /* Skip trailing whitespace. */ - for ( i = strlen( nmdef ) - 1; - i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t'); - --i ) - ; - - nmdef[i + 1] = '\0'; + { + size_t i = strlen( nmdef ); + while (i > 0 && (nmdef[i-1] == ' ' || nmdef[i-1] == '\t')) + --i; + nmdef[i] = '\0'; + } ndinstal( nmstr, nmdef ); didadef = true; -- cgit v1.2.3 From 7528bc0aee69c32fad8ffd8c84a4008627b7e445 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Sun, 4 Sep 2016 18:27:36 -0400 Subject: Fix escaping of `[[` and `]]` in strings Previously, `[[` and `]]` were not escaped in strings, which led to bad interactions with m4. Also, don't break strings on newline, as GCC et al support whitespace between a backslash and the subsequent newline. --- src/scan.l | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 6c1985b..f8b7058 100644 --- a/src/scan.l +++ b/src/scan.l @@ -939,7 +939,9 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { [^"\\\n]+ ACTION_ECHO; \\. ACTION_ECHO; - {NL} ++linenum; ACTION_ECHO; BEGIN(ACTION); + {M4QEND} ACTION_ECHO_QEND; + {M4QSTART} ACTION_ECHO_QSTART; + {NL} ++linenum; ACTION_ECHO; \" ACTION_ECHO; BEGIN(ACTION); . ACTION_ECHO; } -- cgit v1.2.3 From e50d903620be9b81e8dd89d1ed1063c13836ff26 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Fri, 23 Sep 2016 11:28:56 -0400 Subject: no longer generate K&R C scanners --- src/scan.l | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index f8b7058..49c2155 100644 --- a/src/scan.l +++ b/src/scan.l @@ -340,8 +340,6 @@ M4QEND "]]" interactive = option_sense; } array yytext_is_array = option_sense; - ansi-definitions ansi_func_defs = option_sense; - ansi-prototypes ansi_func_protos = option_sense; backup backing_up_report = option_sense; batch interactive = ! option_sense; bison-bridge bison_bridge_lval = option_sense; -- cgit v1.2.3 From ee87e5df0056671be04eefaaeb85979d7bfca89c Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Mon, 5 Sep 2016 20:43:32 -0400 Subject: scanner: M4 quoting fixes --- src/scan.l | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 49c2155..afafa7d 100644 --- a/src/scan.l +++ b/src/scan.l @@ -38,6 +38,9 @@ extern bool tablesverify, tablesext; extern int trlcontxt; /* Set in parse.y for each rule. */ extern const char *escaped_qstart, *escaped_qend; +#define M4QSTART "[[" +#define M4QEND "]]" + #define ACTION_ECHO add_action( yytext ) #define ACTION_IFDEF(def, should_define) \ { \ @@ -208,8 +211,6 @@ M4QEND "]]" { "*/" ACTION_ECHO; yy_pop_state(); "*" ACTION_ECHO; - {M4QSTART} ACTION_ECHO_QSTART; - {M4QEND} ACTION_ECHO_QEND; [^*\n] ACTION_ECHO; {NL} ++linenum; ACTION_ECHO; } @@ -225,7 +226,7 @@ M4QEND "]]" { ")" yy_pop_state(); [^\n\)]+ ; - {NL} ++linenum; + {NL} ++linenum; } { @@ -239,12 +240,14 @@ M4QEND "]]" } . /* ignore spurious characters */ } +{ + "M4"|"YY"|"m4" add_action(M4QSTART); ACTION_ECHO; add_action(M4QEND); + {M4QSTART} ACTION_ECHO_QSTART; + {M4QEND} ACTION_ECHO_QEND; +} { ^"%}".*{NL} ++linenum; BEGIN(INITIAL); - - {M4QSTART} ACTION_ECHO_QSTART; - {M4QEND} ACTION_ECHO_QEND; . ACTION_ECHO; {NL} { @@ -276,6 +279,11 @@ M4QEND "]]" {M4QSTART} buf_strnappend(&top_buf, escaped_qstart, (int) strlen(escaped_qstart)); {M4QEND} buf_strnappend(&top_buf, escaped_qend, (int) strlen(escaped_qend)); + m4|M4|YY { + buf_strnappend(&top_buf, M4QSTART, 2); + buf_strnappend(&top_buf, yytext, 2); + buf_strnappend(&top_buf, M4QEND, 2); + } [^{}\r\n] { buf_strnappend(&top_buf, yytext, yyleng); @@ -603,7 +611,9 @@ M4QEND "]]" sectnum = 3; BEGIN(SECT3); outn("/* Begin user sect3 */"); + //fwrite(M4QSTART, 1, 2, yyout); yyterminate(); /* to stop the parser */ + } "["({FIRST_CCL_CHAR}|{CCL_EXPR})({CCL_CHAR}|{CCL_EXPR})* { @@ -889,8 +899,6 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ } } - {M4QSTART} ACTION_ECHO_QSTART; - {M4QEND} ACTION_ECHO_QEND; . ACTION_ECHO; {NL} { ++linenum; @@ -912,8 +920,6 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { "{" ACTION_ECHO; ++bracelevel; "}" ACTION_ECHO; --bracelevel; - {M4QSTART} ACTION_ECHO_QSTART; - {M4QEND} ACTION_ECHO_QEND; [^[:alpha:]_{}"'/\n\[\]]+ ACTION_ECHO; [\[\]] ACTION_ECHO; {NAME} ACTION_ECHO; @@ -935,10 +941,8 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ } { - [^"\\\n]+ ACTION_ECHO; + [^]"\\\n[]+ ACTION_ECHO; \\. ACTION_ECHO; - {M4QEND} ACTION_ECHO_QEND; - {M4QSTART} ACTION_ECHO_QSTART; {NL} ++linenum; ACTION_ECHO; \" ACTION_ECHO; BEGIN(ACTION); . ACTION_ECHO; @@ -965,11 +969,16 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { - {M4QSTART} fwrite (escaped_qstart, 1, strlen(escaped_qstart), yyout); - {M4QEND} fwrite (escaped_qend, 1, strlen(escaped_qend), yyout); + /* "M4"|"m4"|"YY" fprintf (yyout, "[[%s]]", yytext); */ + {M4QSTART} fwrite (escaped_qstart, 1, strlen(escaped_qstart) - 0, yyout); + {M4QEND} fwrite (escaped_qend, 1, strlen(escaped_qend) - 0, yyout); [^\[\]\n]*(\n?) ECHO; (.|\n) ECHO; - <> sectnum = 0; yyterminate(); + <> { + //fwrite(M4QEND, 1, strlen(M4QEND), yyout); + sectnum = 0; + yyterminate(); + } } <*>.|\n format_synerr( _( "bad character: %s" ), yytext ); -- cgit v1.2.3 From 9d3ddf572e3744e4cf5e9788b676f423fe69aee8 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Tue, 27 Sep 2016 10:54:16 -0400 Subject: Fix M4 quoting of section 3. This fixes M4 quoting of section 3 of the input file, including escape sequences and character constants. Tests were added to verify the behavior in section 3 with respect to quoting. Both escaping of quotes and quoting of potential macro-start characters are tested. Existing tests were also fixed to account for the new -- and now correct -- behavior. Many tests relied on the old behavior of expanding M4 macros in section 3. They needed to be updated for the new behavior. --- src/scan.l | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index afafa7d..9a2bd83 100644 --- a/src/scan.l +++ b/src/scan.l @@ -41,6 +41,9 @@ extern const char *escaped_qstart, *escaped_qend; #define M4QSTART "[[" #define M4QEND "]]" +#define SECT3_ESCAPED_QSTART "[" M4QEND M4QSTART "[" M4QEND M4QSTART +#define SECT3_ESCAPED_QEND M4QEND "]" M4QSTART M4QEND "]" M4QSTART + #define ACTION_ECHO add_action( yytext ) #define ACTION_IFDEF(def, should_define) \ { \ @@ -110,6 +113,8 @@ extern const char *escaped_qstart, *escaped_qend; %x GROUP_MINUS_PARAMS %x EXTENDED_COMMENT %x COMMENT_DISCARD +%x SECT3_NOESCAPE +%x CHARACTER_CONSTANT WS [[:blank:]]+ OPTWS [[:blank:]]* @@ -240,8 +245,8 @@ M4QEND "]]" } . /* ignore spurious characters */ } -{ - "M4"|"YY"|"m4" add_action(M4QSTART); ACTION_ECHO; add_action(M4QEND); +{ + M4|YY|m4 add_action(M4QSTART); ACTION_ECHO; add_action(M4QEND); {M4QSTART} ACTION_ECHO_QSTART; {M4QEND} ACTION_ECHO_QEND; } @@ -285,9 +290,9 @@ M4QEND "]]" buf_strnappend(&top_buf, M4QEND, 2); } - [^{}\r\n] { - buf_strnappend(&top_buf, yytext, yyleng); - } + ([^{}\r\nmMY\[\]]+)|[^{}\r\n] { + buf_strnappend(&top_buf, yytext, yyleng); + } <> { linenum = brace_start_line; @@ -920,10 +925,11 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { "{" ACTION_ECHO; ++bracelevel; "}" ACTION_ECHO; --bracelevel; - [^[:alpha:]_{}"'/\n\[\]]+ ACTION_ECHO; + [^[:alpha:]_{}\"'/\n\[\]]+ ACTION_ECHO; [\[\]] ACTION_ECHO; {NAME} ACTION_ECHO; - "'"([^'\\\n]|\\.)*"'" ACTION_ECHO; /* character constant */ + "'"([^\'\\\n]|\\.)"'" ACTION_ECHO; /* character constant */ + "'" ACTION_ECHO; yy_push_state(CHARACTER_CONSTANT); \" ACTION_ECHO; BEGIN(ACTION_STRING); {NL} { ++linenum; @@ -941,14 +947,20 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ } { - [^]"\\\n[]+ ACTION_ECHO; + [^\]\"\\\n\[MmY]+ ACTION_ECHO; + \" ACTION_ECHO; BEGIN(ACTION); +} +{ + [^\[\]\'\\\nMmY]+ ACTION_ECHO; + \' ACTION_ECHO; yy_pop_state(); +} +{ \\. ACTION_ECHO; {NL} ++linenum; ACTION_ECHO; - \" ACTION_ECHO; BEGIN(ACTION); . ACTION_ECHO; } -<> { +<> { synerr( _( "EOF encountered inside an action" ) ); yyterminate(); } @@ -969,10 +981,15 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { - /* "M4"|"m4"|"YY" fprintf (yyout, "[[%s]]", yytext); */ + "M4"|"m4"|"YY" { + if (no_section3_escape) { + ECHO; + } else + fprintf (yyout, "[[%s]]", yytext); + } {M4QSTART} fwrite (escaped_qstart, 1, strlen(escaped_qstart) - 0, yyout); {M4QEND} fwrite (escaped_qend, 1, strlen(escaped_qend) - 0, yyout); - [^\[\]\n]*(\n?) ECHO; + [^\[\]MmY\n]*(\n?) ECHO; (.|\n) ECHO; <> { //fwrite(M4QEND, 1, strlen(M4QEND), yyout); -- cgit v1.2.3 From 4bffa41e4ed434f1e2ba64ac5a8fe661fa089cfb Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Tue, 27 Sep 2016 10:54:16 -0400 Subject: Improved M4 quotation This fixes M4 quotation of certain strings beginning with `yy` (in section 3 of the input file only) and character literals. The new quotation method is also less brittle and faster. Tests that relied on the old behavior were fixed. Also, `yyconst` is no longer defined; use `const` (which it unconditionally was defined to) instead. --- src/scan.l | 104 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 54 insertions(+), 50 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 9a2bd83..ecf238a 100644 --- a/src/scan.l +++ b/src/scan.l @@ -38,8 +38,8 @@ extern bool tablesverify, tablesext; extern int trlcontxt; /* Set in parse.y for each rule. */ extern const char *escaped_qstart, *escaped_qend; -#define M4QSTART "[[" -#define M4QEND "]]" +#define M4QSTART "[""[" +#define M4QEND "]""]" #define SECT3_ESCAPED_QSTART "[" M4QEND M4QSTART "[" M4QEND M4QSTART #define SECT3_ESCAPED_QEND M4QEND "]" M4QSTART M4QEND "]" M4QSTART @@ -51,8 +51,8 @@ extern const char *escaped_qstart, *escaped_qend; action_define( def, 1 ); \ } -#define ACTION_ECHO_QSTART add_action (escaped_qstart) -#define ACTION_ECHO_QEND add_action (escaped_qend) +#define ACTION_ECHO_QSTART add_action (SECT3_ESCAPED_QSTART) +#define ACTION_ECHO_QEND add_action (SECT3_ESCAPED_QEND) #define ACTION_M4_IFDEF(def, should_define) \ do{ \ @@ -101,6 +101,10 @@ extern const char *escaped_qstart, *escaped_qend; if ( getenv("POSIXLY_CORRECT") ) \ posix_compat = true; +#define START_CODEBLOCK do { add_action(M4QSTART); BEGIN(CODEBLOCK); } while(0) +#define END_CODEBLOCK do { add_action(M4QEND); BEGIN(INITIAL); } while (0) +#define CODEBLOCK_QSTART "[]""][""[""[]""][""[" +#define CODEBLOCK_QEND "]""]""][""[""]""]""][""[" %} %option caseless nodefault noreject stack noyy_top_state @@ -112,7 +116,7 @@ extern const char *escaped_qstart, *escaped_qend; %x GROUP_WITH_PARAMS %x GROUP_MINUS_PARAMS %x EXTENDED_COMMENT -%x COMMENT_DISCARD +%x COMMENT_DISCARD CODE_COMMENT %x SECT3_NOESCAPE %x CHARACTER_CONSTANT @@ -135,8 +139,8 @@ CCL_EXPR ("[:"^?[[:alpha:]]+":]") LEXOPT [aceknopr] -M4QSTART "[[" -M4QEND "]]" +M4QSTART "[""[" +M4QEND "]""]" %% static int bracelevel, didadef, indented_code; @@ -149,8 +153,8 @@ M4QEND "]]" { - ^{WS} indented_code = true; BEGIN(CODEBLOCK); - ^"/*" ACTION_ECHO; yy_push_state( COMMENT ); + ^{WS} indented_code = true; START_CODEBLOCK; + ^"/*" add_action("/*[""["); yy_push_state( COMMENT ); ^#{OPTWS}line{WS} yy_push_state( LINEDIR ); ^"%s"{NAME}? return SCDECL; ^"%x"{NAME}? return XSCDECL; @@ -158,7 +162,7 @@ M4QEND "]]" ++linenum; line_directive_out(NULL, 1); indented_code = false; - BEGIN(CODEBLOCK); + START_CODEBLOCK; } ^"%top"[[:blank:]]*"{"[[:blank:]]*{NL} { brace_start_line = linenum; @@ -213,12 +217,18 @@ M4QEND "]]" } -{ - "*/" ACTION_ECHO; yy_pop_state(); - "*" ACTION_ECHO; - [^*\n] ACTION_ECHO; +{ /* */ + [^\[\]\*\n]* ACTION_ECHO; + . ACTION_ECHO; + {NL} ++linenum; ACTION_ECHO; } +{ + "*/" add_action("*/]""]"); yy_pop_state(); +} +{ + "*/" ACTION_ECHO; yy_pop_state(); +} { /* This is the same as COMMENT, but is discarded rather than output. */ @@ -245,21 +255,20 @@ M4QEND "]]" } . /* ignore spurious characters */ } -{ - M4|YY|m4 add_action(M4QSTART); ACTION_ECHO; add_action(M4QEND); +{ {M4QSTART} ACTION_ECHO_QSTART; {M4QEND} ACTION_ECHO_QEND; } { - ^"%}".*{NL} ++linenum; BEGIN(INITIAL); - . ACTION_ECHO; - + ^"%}".*{NL} ++linenum; END_CODEBLOCK; + [^\n%\[\]]* ACTION_ECHO; + . ACTION_ECHO; {NL} { ++linenum; ACTION_ECHO; - if ( indented_code ) - BEGIN(INITIAL); + if ( indented_code ) END_CODEBLOCK; } } @@ -284,13 +293,7 @@ M4QEND "]]" {M4QSTART} buf_strnappend(&top_buf, escaped_qstart, (int) strlen(escaped_qstart)); {M4QEND} buf_strnappend(&top_buf, escaped_qend, (int) strlen(escaped_qend)); - m4|M4|YY { - buf_strnappend(&top_buf, M4QSTART, 2); - buf_strnappend(&top_buf, yytext, 2); - buf_strnappend(&top_buf, M4QEND, 2); - } - - ([^{}\r\nmMY\[\]]+)|[^{}\r\n] { + ([^{}\r\n\[\]]+)|[^{}\r\n] { buf_strnappend(&top_buf, yytext, yyleng); } @@ -545,6 +548,7 @@ M4QEND "]]" yyless(amt); } else { + add_action("]""]"); continued_action = true; ++linenum; return '\n'; @@ -614,9 +618,8 @@ M4QEND "]]" ^"%%".* { sectnum = 3; - BEGIN(SECT3); + BEGIN(no_section3_escape ? SECT3_NOESCAPE : SECT3); outn("/* Begin user sect3 */"); - //fwrite(M4QSTART, 1, 2, yyout); yyterminate(); /* to stop the parser */ } @@ -891,7 +894,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { {OPTWS}"%}".* bracelevel = 0; - "/*" ACTION_ECHO; yy_push_state( COMMENT ); + "/*" ACTION_ECHO; yy_push_state( CODE_COMMENT ); { "reject" { @@ -912,7 +915,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ (doing_codeblock && indented_code) ) { if ( doing_rule_action ) - add_action( "\tYY_BREAK\n" ); + add_action( "\tYY_BREAK]""]\n" ); doing_rule_action = doing_codeblock = false; BEGIN(SECT2); @@ -937,7 +940,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ if ( bracelevel == 0 ) { if ( doing_rule_action ) - add_action( "\tYY_BREAK\n" ); + add_action( "\tYY_BREAK]""]\n" ); doing_rule_action = false; BEGIN(SECT2); @@ -960,7 +963,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ . ACTION_ECHO; } -<> { +<> { synerr( _( "EOF encountered inside an action" ) ); yyterminate(); } @@ -979,25 +982,26 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ return CHAR; } - { - "M4"|"m4"|"YY" { - if (no_section3_escape) { - ECHO; - } else - fprintf (yyout, "[[%s]]", yytext); + {M4QSTART} fputs(escaped_qstart, yyout); + {M4QEND} fputs(escaped_qend, yyout); + [^\[\]\n]*(\n?) ECHO; + .|\n ECHO; + <> { + sectnum = 0; + yyterminate(); + } +} +{ + {M4QSTART} fprintf(yyout, "[""[%s]""]", escaped_qstart); + {M4QEND} fprintf(yyout, "[""[%s]""]", escaped_qend); + [^\[\]\n]*(\n?) ECHO; + (.|\n) ECHO; + <> { + sectnum = 0; + yyterminate(); } - {M4QSTART} fwrite (escaped_qstart, 1, strlen(escaped_qstart) - 0, yyout); - {M4QEND} fwrite (escaped_qend, 1, strlen(escaped_qend) - 0, yyout); - [^\[\]MmY\n]*(\n?) ECHO; - (.|\n) ECHO; - <> { - //fwrite(M4QEND, 1, strlen(M4QEND), yyout); - sectnum = 0; - yyterminate(); - } } - <*>.|\n format_synerr( _( "bad character: %s" ), yytext ); %% -- cgit v1.2.3 From b02489f58815b84180664c5b9b2fcfa949d7c286 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Thu, 20 Oct 2016 15:55:47 -0400 Subject: Fix M4 quotation in section 2 prologue and refactor duplicated code --- src/scan.l | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index ecf238a..d5fe347 100644 --- a/src/scan.l +++ b/src/scan.l @@ -41,8 +41,8 @@ extern const char *escaped_qstart, *escaped_qend; #define M4QSTART "[""[" #define M4QEND "]""]" -#define SECT3_ESCAPED_QSTART "[" M4QEND M4QSTART "[" M4QEND M4QSTART -#define SECT3_ESCAPED_QEND M4QEND "]" M4QSTART M4QEND "]" M4QSTART +#define ESCAPED_QSTART "[" M4QEND M4QSTART "[" M4QEND M4QSTART +#define ESCAPED_QEND M4QEND "]" M4QSTART M4QEND "]" M4QSTART #define ACTION_ECHO add_action( yytext ) #define ACTION_IFDEF(def, should_define) \ @@ -51,8 +51,8 @@ extern const char *escaped_qstart, *escaped_qend; action_define( def, 1 ); \ } -#define ACTION_ECHO_QSTART add_action (SECT3_ESCAPED_QSTART) -#define ACTION_ECHO_QEND add_action (SECT3_ESCAPED_QEND) +#define ACTION_ECHO_QSTART add_action (ESCAPED_QSTART) +#define ACTION_ECHO_QEND add_action (ESCAPED_QEND) #define ACTION_M4_IFDEF(def, should_define) \ do{ \ @@ -75,13 +75,13 @@ extern const char *escaped_qstart, *escaped_qend; if(yyleng < MAXLINE) \ { \ strcpy( nmstr, yytext ); \ + return NAME; \ } \ else \ - { \ + do { \ synerr(_("Input line too long\n")); \ FLEX_EXIT(EXIT_FAILURE); \ - } \ - return NAME; + } while (0) #define PUT_BACK_STRING(str, start) \ { size_t i = strlen( str ); \ @@ -101,10 +101,21 @@ extern const char *escaped_qstart, *escaped_qend; if ( getenv("POSIXLY_CORRECT") ) \ posix_compat = true; -#define START_CODEBLOCK do { add_action(M4QSTART); BEGIN(CODEBLOCK); } while(0) -#define END_CODEBLOCK do { add_action(M4QEND); BEGIN(INITIAL); } while (0) -#define CODEBLOCK_QSTART "[]""][""[""[]""][""[" -#define CODEBLOCK_QEND "]""]""][""[""]""]""][""[" +#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) +#define END_CODEBLOCK do { \ + yy_pop_state();\ + add_action(M4QEND); \ + if (!indented_code) line_directive_out(NULL, 0);\ + } while (0) %} %option caseless nodefault noreject stack noyy_top_state @@ -153,17 +164,12 @@ M4QEND "]""]" { - ^{WS} indented_code = true; START_CODEBLOCK; + ^{WS} START_CODEBLOCK(true); ^"/*" add_action("/*[""["); yy_push_state( COMMENT ); ^#{OPTWS}line{WS} yy_push_state( LINEDIR ); ^"%s"{NAME}? return SCDECL; ^"%x"{NAME}? return XSCDECL; - ^"%{".*{NL} { - ++linenum; - line_directive_out(NULL, 1); - indented_code = false; - START_CODEBLOCK; - } + ^"%{".*{NL} START_CODEBLOCK(false); ^"%top"[[:blank:]]*"{"[[:blank:]]*{NL} { brace_start_line = linenum; ++linenum; @@ -478,7 +484,7 @@ COMMENT,CODE_COMMENT>{ ^"%{".* ++bracelevel; yyless( 2 ); /* eat only %{ */ ^"%}".* --bracelevel; yyless( 2 ); /* eat only %} */ - ^{WS}.* ACTION_ECHO; /* indented code in prolog */ + ^{WS} START_CODEBLOCK(true); /* indented code in prolog */ ^{NOT_WS}.* { /* non-indented code */ if ( bracelevel <= 0 ) -- cgit v1.2.3 From e1038db19a6fda98a19a1df4d5f62c74c63b57d5 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Tue, 1 Nov 2016 20:20:46 -0400 Subject: Fix another escaping bug in non-indented verbatim section 2 code. I also did some reformatting. --- src/scan.l | 129 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 65 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index d5fe347..7444c22 100644 --- a/src/scan.l +++ b/src/scan.l @@ -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 @@ -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; @@ -903,30 +906,28 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ "/*" ACTION_ECHO; yy_push_state( CODE_COMMENT ); { - "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); + } + } } @@ -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); + } + } } { - [^\]\"\\\n\[MmY]+ ACTION_ECHO; + [^\]\"\\\n\[]+ ACTION_ECHO; \" ACTION_ECHO; BEGIN(ACTION); } { - [^\[\]\'\\\nMmY]+ ACTION_ECHO; - \' ACTION_ECHO; yy_pop_state(); + [^\[\]\'\\\n]+ ACTION_ECHO; + \' ACTION_ECHO; yy_pop_state(); } { \\. ACTION_ECHO; - {NL} ++linenum; ACTION_ECHO; - . ACTION_ECHO; + {NL} ++linenum; ACTION_ECHO; + [\]\['"] ACTION_ECHO; } <> { @@ -991,8 +990,8 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { {M4QSTART} fputs(escaped_qstart, yyout); {M4QEND} fputs(escaped_qend, yyout); - [^\[\]\n]*(\n?) ECHO; - .|\n ECHO; + [^\[\]]* ECHO; + [][] ECHO; <> { sectnum = 0; yyterminate(); @@ -1001,8 +1000,8 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { {M4QSTART} fprintf(yyout, "[""[%s]""]", escaped_qstart); {M4QEND} fprintf(yyout, "[""[%s]""]", escaped_qend); - [^\[\]\n]*(\n?) ECHO; - (.|\n) ECHO; + [^][]* ECHO; + [][] ECHO; <> { sectnum = 0; yyterminate(); -- cgit v1.2.3 From c8ad3d682fb0ea39e30a70449c7f88b8cd8da6b4 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Tue, 8 Nov 2016 10:05:49 -0500 Subject: Fixes a major bug in Flex's own lexing of literals. My changes caused Flex to mishandle string and character literals in line comments. This commit fixes them. Fixes #113. --- src/scan.l | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 7444c22..7c9f092 100644 --- a/src/scan.l +++ b/src/scan.l @@ -936,10 +936,9 @@ 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; "'"([^\'\\\n]|\\.)"'" ACTION_ECHO; /* character constant */ - "'" ACTION_ECHO; yy_push_state(CHARACTER_CONSTANT); + "'" ACTION_ECHO; BEGIN(CHARACTER_CONSTANT); \" ACTION_ECHO; BEGIN(ACTION_STRING); {NL} { ++linenum; @@ -952,20 +951,22 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ BEGIN(SECT2); } } + . ACTION_ECHO; } { - [^\]\"\\\n\[]+ ACTION_ECHO; + [^\[\]\"\\\n]+ ACTION_ECHO; \" ACTION_ECHO; BEGIN(ACTION); } { - [^\[\]\'\\\n]+ ACTION_ECHO; - \' ACTION_ECHO; yy_pop_state(); + [^\[\]\'\\\n]+ ACTION_ECHO; + \' ACTION_ECHO; BEGIN(ACTION); } { - \\. ACTION_ECHO; - {NL} ++linenum; ACTION_ECHO; - [\]\['"] ACTION_ECHO; + (\\\n)* ACTION_ECHO; + \\(\\\n)*. ACTION_ECHO; + {NL} ++linenum; ACTION_ECHO; BEGIN(ACTION); + . ACTION_ECHO; } <> { -- cgit v1.2.3 From 7f263e35204db8ade3f0fb424f4597d7758caf25 Mon Sep 17 00:00:00 2001 From: luistung Date: Mon, 9 Jan 2017 20:18:41 +0800 Subject: scanner: join symbol list. Removed a newline that caused a problem building the scanner in some circumstances. Specifically: 'bad character' error when executing /bin/sh ../build-aux/ylwrap scan.l lex.yy.c scan.c -- flex --- src/scan.l | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 7c9f092..181b28c 100644 --- a/src/scan.l +++ b/src/scan.l @@ -263,8 +263,7 @@ M4QEND "]""]" } . /* ignore spurious characters */ } -{ +{ {M4QSTART} ACTION_ECHO_QSTART; {M4QEND} ACTION_ECHO_QEND; } -- cgit v1.2.3 From 7ca76038dfa985f3f9560be53d775343cd1cf725 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Sun, 22 Jan 2017 18:22:26 +0100 Subject: scanner: Use strncpy --- src/scan.l | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 181b28c..8400cf6 100644 --- a/src/scan.l +++ b/src/scan.l @@ -74,7 +74,7 @@ extern const char *escaped_qstart, *escaped_qend; #define RETURNNAME \ if(yyleng < MAXLINE) \ { \ - strcpy( nmstr, yytext ); \ + strncpy( nmstr, yytext, sizeof(nmstr) ); \ return NAME; \ } \ else \ @@ -207,7 +207,7 @@ M4QEND "]""]" ^{NAME} { if(yyleng < MAXLINE) { - strcpy( nmstr, yytext ); + strncpy( nmstr, yytext, sizeof(nmstr) ); } else { @@ -318,7 +318,7 @@ M4QEND "]""]" {NOT_WS}[^\r\n]* { if(yyleng < MAXLINE) { - strcpy( nmdef, yytext ); + strncpy( nmdef, yytext, sizeof(nmdef) ); } else { @@ -460,7 +460,7 @@ M4QEND "]""]" \"[^"\n]*\" { if(yyleng-1 < MAXLINE) { - strcpy( nmstr, yytext + 1 ); + strncpy( nmstr, yytext + 1, sizeof(nmstr) ); } else { @@ -637,7 +637,7 @@ M4QEND "]""]" if(yyleng < MAXLINE) { - strcpy( nmstr, yytext ); + strncpy( nmstr, yytext, sizeof(nmstr) ); } else { @@ -695,7 +695,7 @@ M4QEND "]""]" if(yyleng-1 < MAXLINE) { - strcpy( nmstr, yytext + 1 ); + strncpy( nmstr, yytext + 1, sizeof(nmstr) ); } else { -- cgit v1.2.3 From b1c2957b3fb9081acf58606e669eca0a7aea9377 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Wed, 3 May 2017 09:34:34 -0400 Subject: scanner: when bracelevel is negative, treat as zero. This really should never happen, but this at least fixes the breakage on Verilator. --- src/scan.l | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index 8400cf6..abe47f4 100644 --- a/src/scan.l +++ b/src/scan.l @@ -940,16 +940,16 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ "'" ACTION_ECHO; BEGIN(CHARACTER_CONSTANT); \" ACTION_ECHO; BEGIN(ACTION_STRING); {NL} { - ++linenum; - ACTION_ECHO; - if (bracelevel == 0) { - if ( doing_rule_action ) - add_action( "\tYY_BREAK]""]\n" ); + ++linenum; + ACTION_ECHO; + if (bracelevel <= 0) { + if ( doing_rule_action ) + add_action( "\tYY_BREAK]""]\n" ); - doing_rule_action = false; - BEGIN(SECT2); - } - } + doing_rule_action = false; + BEGIN(SECT2); + } + } . ACTION_ECHO; } -- cgit v1.2.3 From ba530cd52fa2d69ddf7194459445a19fc9648014 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Wed, 3 May 2017 13:45:11 -0400 Subject: scanner: Check for 0 bracecount when EOL ends quoted literal. This can happen in the case of // comments (which Flex doesn't handle specially). --- src/scan.l | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/scan.l') diff --git a/src/scan.l b/src/scan.l index abe47f4..66db864 100644 --- a/src/scan.l +++ b/src/scan.l @@ -919,7 +919,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ {NL} { ++linenum; ACTION_ECHO; - if (bracelevel == 0 || (doing_codeblock && indented_code)) { + if (bracelevel <= 0 || (doing_codeblock && indented_code)) { if ( doing_rule_action ) add_action( "\tYY_BREAK]""]\n" ); @@ -964,7 +964,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ { (\\\n)* ACTION_ECHO; \\(\\\n)*. ACTION_ECHO; - {NL} ++linenum; ACTION_ECHO; BEGIN(ACTION); + {NL} ++linenum; ACTION_ECHO; if (bracelevel <= 0) { BEGIN(SECT2); } else { BEGIN(ACTION); } . ACTION_ECHO; } -- cgit v1.2.3