]> granicus.if.org Git - flex/commitdiff
Added extended, perl-compatible comment syntax.
authorJohn Millaway <john43@users.sourceforge.net>
Sat, 25 Mar 2006 19:03:04 +0000 (19:03 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Sat, 25 Mar 2006 19:03:04 +0000 (19:03 +0000)
Added test for extended comment syntax.
Documented extended comment syntax.

configure.in
doc/flex.texi
scan.l
tests/Makefile.am
tests/descriptions
tests/test-extended/.cvsignore [new file with mode: 0644]
tests/test-extended/Makefile.am [new file with mode: 0644]
tests/test-extended/scanner.l [new file with mode: 0644]
tests/test-extended/test.input [new file with mode: 0644]

index dd6abed3b2c4a5bb73c44a52a8d3a00c242b6f31..ddf74267d82b67a37d58fef61ce229d8b5f51655 100644 (file)
@@ -147,6 +147,7 @@ tests/test-rescan-nr/Makefile
 tests/test-rescan-r/Makefile
 tests/test-quotes/Makefile
 tests/test-ccl/Makefile
+tests/test-extended/Makefile
 dnl --new-test-here-- This line is processed by tests/create-test.
 )
 
index 97d22751c5580b0175315499a5424f09579543ef..f4ad42ade391c8735d93879937fd2d36bf71ad3c 100644 (file)
@@ -746,6 +746,11 @@ the character with hexadecimal value 2a
 @item (r)
 match an @samp{r}; parentheses are used to override precedence (see below)
 
+@item (?# comment )
+omit everything within @samp{()}. The first @samp{)}
+character encountered ends the pattern. It is not possible to for the comment
+to contain a @samp{)} character. The comment may span lines.
+
 @cindex concatenation, in patterns
 @item rs
 the regular expression @samp{r} followed by the regular expression @samp{s}; called
diff --git a/scan.l b/scan.l
index 5393ab09f739b9eb67025fa3061a2deafada0f29..367cf43e789f8c18aa846e178a1e433e819dc026 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -101,6 +101,9 @@ extern const char *escaped_qstart, *escaped_qend;
 %x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
 %x FIRSTCCL CCL ACTION RECOVER COMMENT ACTION_STRING PERCENT_BRACE_ACTION
 %x OPTION LINEDIR CODEBLOCK_MATCH_BRACE
+%x GROUP_WITH_PARAMS
+%x GROUP_MINUS_PARAMS
+%x EXTENDED_COMMENT
 
 WS             [[:blank:]]+
 OPTWS          [[:blank:]]*
@@ -208,6 +211,12 @@ M4QEND      "]]"
        {NL}        ++linenum; ACTION_ECHO;
 }
 
+<EXTENDED_COMMENT>{
+    ")"         BEGIN(SECT2);
+    [^\n\)]+      ;
+    {NL}        ++linenum;        
+}
+
 <LINEDIR>{
        \n              yy_pop_state();
        [[:digit:]]+    linenum = myctoi( yytext );
@@ -594,6 +603,7 @@ M4QEND      "]]"
                        }
     "{-}"       return CCL_OP_DIFF;
 
+
     /* Check for :space: at the end of the rule so we don't
      * wrap the expanded regex in '(' ')' -- breaking trailing
      * context.
@@ -646,6 +656,11 @@ nmstr[yyleng - 2 - end_is_ws] = '\0';  /* chop trailing brace */
                                }
                        }
 
+    "(?#"       BEGIN(EXTENDED_COMMENT);
+    "(?"        BEGIN(GROUP_WITH_PARAMS); return '('; /* TODO: push parameterized rule state. */
+    "("         return '('; /* TODO: push  parameterized rule state. */
+    ")"         return ')'; /* TODO: pop  parameterized rule state. */
+
        [/|*+?.(){}]    return (unsigned char) yytext[0];
        .               RETURNCHAR;
 }
@@ -678,6 +693,17 @@ nmstr[yyleng - 2 - end_is_ws] = '\0';  /* chop trailing brace */
                        }
 }
 
+<GROUP_WITH_PARAMS>{
+    ":"     BEGIN(SECT2);
+    "-"     BEGIN(GROUP_MINUS_PARAMS);
+    i       ; /* TODO: temporarily case-insensitive. */
+    s       ; /* TODO: temporary dot-all. */
+}
+<GROUP_MINUS_PARAMS>{
+    ":"     BEGIN(SECT2);
+    i       ; /* TODO: temporarily NOT case-insensitive. */
+    s       ; /* TODO: temporarily NOT dot-all. */
+}
 
 <FIRSTCCL>{
        "^"/[^-\]\n]    BEGIN(CCL); return '^';
@@ -834,6 +860,10 @@ nmstr[yyleng - 2 - end_is_ws] = '\0';  /* chop trailing brace */
                        yyterminate();
                        }
 
+<EXTENDED_COMMENT,GROUP_WITH_PARAMS,GROUP_MINUS_PARAMS><<EOF>> {
+                       synerr( _( "EOF encountered inside pattern" ) );
+                       yyterminate();
+                       }
 
 <SECT2,QUOTE,FIRSTCCL,CCL>{ESCSEQ}     {
                        yylval = myesc( (Char *) yytext );
index 064467493c70f58c9e5e45d13bca5d3555fc1b7f..c9d970daf1c9d8687a631c25ec2195e76907e925 100644 (file)
@@ -26,6 +26,7 @@ dist_noinst_SCRIPTS = \
        create-test
 
 DIST_SUBDIRS = \
+       test-extended \
        test-ccl \
        test-quotes \
        test-rescan-r \
@@ -71,6 +72,7 @@ DIST_SUBDIRS = \
        test-table-opts
 
 SUBDIRS = \
+       test-extended \
        test-ccl \
        test-quotes \
        test-rescan-r \
index c8f3aaf10cd1495cf3545df080011a361c69314c..9bf891a0a16613e535b4a3cc33990e843d963bf5 100644 (file)
@@ -15,6 +15,7 @@ c++-basic             - The C++ scanner.
 c++-multiple-scanners - Multiple C++ scanners.
 debug-nr              - Use yy_flex_debug, non-reentrant.
 debug-r               - Use debugging functions, reentrant.
+extended              - Extended pattern syntax.
 header-nr             - Test generated header file, non-reentrant.
 header-r              - Test generated header file, reentrant.
 include-by-buffer     - YY_BUFFER_STATE, yy_push_state, etc.
diff --git a/tests/test-extended/.cvsignore b/tests/test-extended/.cvsignore
new file mode 100644 (file)
index 0000000..325d9be
--- /dev/null
@@ -0,0 +1,9 @@
+Makefile
+Makefile.in
+parser.c
+parser.h
+scanner.c
+TEMPLATE
+OUTPUT
+.deps
+test-extended
diff --git a/tests/test-extended/Makefile.am b/tests/test-extended/Makefile.am
new file mode 100644 (file)
index 0000000..f121603
--- /dev/null
@@ -0,0 +1,44 @@
+# This file is part of flex.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+
+# Neither the name of the University nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE.
+
+FLEX = $(top_builddir)/flex
+
+builddir = @builddir@
+
+EXTRA_DIST = scanner.l test.input
+CLEANFILES = scanner.c scanner.h test-extended OUTPUT $(OBJS)
+OBJS = scanner.o
+
+AM_CPPFLAGS = -I$(srcdir) -I$(builddir) -I$(top_srcdir) -I$(top_builddir)
+
+testname = test-extended
+
+scanner.c: $(srcdir)/scanner.l
+       $(FLEX) $(LFLAGS) $<
+
+$(testname)$(EXEEXT): $(OBJS)
+       $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES)
+
+test: $(testname)$(EXEEXT)
+       ./$(testname)$(EXEEXT) < $(srcdir)/test.input | diff -q test.input -
+
+.c.o:
+       $(CC) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $<
diff --git a/tests/test-extended/scanner.l b/tests/test-extended/scanner.l
new file mode 100644 (file)
index 0000000..e027ec5
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * This file is part of flex.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+%{
+/* This test is for correctness of extended (?...) patterns. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+
+%}
+
+%option 8bit outfile="scanner.c" prefix="test"
+%option nounput nomain noyywrap 
+%option warn
+
+
+%%
+
+    /* Output should match the input. */
+
+abc(?# Single Line Comment )def    ECHO;
+ghi(?#
+    multi-line 
+    comment
+    )jkl                           ECHO;
+
+mno(?#
+    multi-line //
+    comment with ##
+    ~~!@#$ %^&*(@-_+=\|,.<>/ ?: ;
+    punctuation
+    )pqr                           ECHO;
+(?# Start of a rule.)stu           ECHO;
+vwxyz(?#End of a rule.)            ECHO;
+\n                                 ECHO;
+%%
+
+int main(void);
+
+int
+main ()
+{
+    yyin = stdin;
+    yyout = stdout;
+    yylex();
+    //printf("TEST RETURNING OK.\n");
+    return 0;
+}
diff --git a/tests/test-extended/test.input b/tests/test-extended/test.input
new file mode 100644 (file)
index 0000000..b0883f3
--- /dev/null
@@ -0,0 +1 @@
+abcdefghijklmnopqrstuvwxyz