summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in1
-rw-r--r--doc/flex.texi5
-rw-r--r--scan.l30
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/descriptions1
-rw-r--r--tests/test-extended/.cvsignore9
-rw-r--r--tests/test-extended/Makefile.am44
-rw-r--r--tests/test-extended/scanner.l69
-rw-r--r--tests/test-extended/test.input1
9 files changed, 162 insertions, 0 deletions
diff --git a/configure.in b/configure.in
index dd6abed..ddf7426 100644
--- a/configure.in
+++ b/configure.in
@@ -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.
)
diff --git a/doc/flex.texi b/doc/flex.texi
index 97d2275..f4ad42a 100644
--- a/doc/flex.texi
+++ b/doc/flex.texi
@@ -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 5393ab0..367cf43 100644
--- 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 );
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0644674..c9d970d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 \
diff --git a/tests/descriptions b/tests/descriptions
index c8f3aaf..9bf891a 100644
--- a/tests/descriptions
+++ b/tests/descriptions
@@ -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
index 0000000..325d9be
--- /dev/null
+++ b/tests/test-extended/.cvsignore
@@ -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
index 0000000..f121603
--- /dev/null
+++ b/tests/test-extended/Makefile.am
@@ -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
index 0000000..e027ec5
--- /dev/null
+++ b/tests/test-extended/scanner.l
@@ -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
index 0000000..b0883f3
--- /dev/null
+++ b/tests/test-extended/test.input
@@ -0,0 +1 @@
+abcdefghijklmnopqrstuvwxyz