]> git.saurik.com Git - bison.git/blobdiff - tests/input.at
tests: check the use of dashes and periods in symbols.
[bison.git] / tests / input.at
index 8bf61faa45af629017393911b05c68544474f225..71adf0b7b49fbbcea1fd045e452cf19e8911497d 100644 (file)
@@ -1,6 +1,6 @@
 # Checking the Bison scanner.                    -*- Autotest -*-
-# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
-# Inc.
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+# Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -69,10 +69,9 @@ AT_CLEANUP
 
 
 # _AT_UNUSED_VALUES_DECLARATIONS()
-# --------------------------------------------
+# --------------------------------
 # Generate the token, type, and destructor
 # declarations for the unused values tests.
-
 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
 [[[%token <integer> INT;
 %type <integer> a b c d e f g h i j k l;
@@ -80,15 +79,11 @@ m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
 
 
 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
-# ------------------------------------------------------------------
-# Generate a grammar to test unused values,
-# compile it, run it.  If DECLARATIONS_AFTER
-# is set, then the token, type, and destructor
-# declarations are generated after the rules
-# rather than before.  If CHECK_MIDRULE_VALUES
-# is set, then --warnings=midrule-values is
-# set.
-
+# ----------------------------------------------------------------
+# Generate a grammar to test unused values, compile it, run it.  If
+# DECLARATIONS_AFTER is set, then the token, type, and destructor
+# declarations are generated after the rules rather than before.  If
+# CHECK_MIDRULE_VALUES is set, then --warnings=midrule-values is set.
 m4_define([AT_CHECK_UNUSED_VALUES],
 [AT_DATA([input.y],
 m4_ifval($1, [
@@ -97,16 +92,16 @@ m4_ifval($1, [
 ], [_AT_UNUSED_VALUES_DECLARATIONS
 ])[[%%
 start:
-  'a' a { $]2[ } | 'b' b { $]2[ } | 'c' c { $]2[ } | 'd' d { $]2[ } | 'e' e { $]2[ }
-| 'f' f { $]2[ } | 'g' g { $]2[ } | 'h' h { $]2[ } | 'i' i { $]2[ } | 'j' j { $]2[ }
-| 'k' k { $]2[ } | 'l' l { $]2[ }
+  'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; }
+| 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; }
+| 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; }
 ;
 
 a: INT | INT { } INT { } INT { };
 b: INT | /* empty */;
-c: INT | INT { $]1[ } INT { $<integer>2 } INT { $<integer>4 };
-d: INT | INT { } INT { $]1[ } INT { $<integer>2 };
-e: INT | INT { } INT {  } INT { $]1[ };
+c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; };
+d: INT | INT { } INT { $]1[; } INT { $<integer>2; };
+e: INT | INT { } INT {  } INT { $]1[; };
 f: INT | INT { } INT {  } INT { $]$[ = $]1[ + $]3[ + $]5[; };
 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
@@ -123,18 +118,18 @@ input.y:11.10-32: warning: unused value: $]1[
 input.y:11.10-32: warning: unused value: $]3[
 input.y:11.10-32: warning: unused value: $]5[
 input.y:12.9: warning: empty rule for typed nonterminal, and no action
-]]m4_ifval($2, [[[input.y:13.14-19: warning: unset value: $$
-input.y:13.25-39: warning: unset value: $$
-]]])[[input.y:13.10-59: warning: unset value: $]$[
-input.y:13.10-59: warning: unused value: $]3[
-input.y:13.10-59: warning: unused value: $]5[
+]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $$
+input.y:13.26-41: warning: unset value: $$
+]]])[[input.y:13.10-62: warning: unset value: $]$[
+input.y:13.10-62: warning: unused value: $]3[
+input.y:13.10-62: warning: unused value: $]5[
 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $$
-]]])[[input.y:14.10-47: warning: unset value: $]$[
-input.y:14.10-47: warning: unused value: $]3[
-input.y:14.10-47: warning: unused value: $]5[
-input.y:15.10-36: warning: unset value: $]$[
-input.y:15.10-36: warning: unused value: $]3[
-input.y:15.10-36: warning: unused value: $]5[
+]]])[[input.y:14.10-49: warning: unset value: $]$[
+input.y:14.10-49: warning: unused value: $]3[
+input.y:14.10-49: warning: unused value: $]5[
+input.y:15.10-37: warning: unset value: $]$[
+input.y:15.10-37: warning: unused value: $]3[
+input.y:15.10-37: warning: unused value: $]5[
 input.y:17.10-58: warning: unset value: $]$[
 input.y:17.10-58: warning: unused value: $]1[
 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]2[
@@ -600,8 +595,8 @@ AT_CHECK_REQUIRE(100.0, 63)
 
 AT_SETUP([String aliases for character tokens])
 
-# Bison once thought a character token and its alias were different symbols
-# with the same user token number.
+# Bison once thought a character token and its alias were different
+# symbols with the same user token number.
 
 AT_DATA_GRAMMAR([input.y],
 [[%token 'a' "a"
@@ -615,16 +610,75 @@ AT_BISON_CHECK([-o input.c input.y])
 AT_CLEANUP
 
 
+## -------------- ##
+## Symbol names.  ##
+## -------------- ##
+
+AT_SETUP([Symbols])
+
+# Bison once thought a character token and its alias were different
+# symbols with the same user token number.
+
+AT_DATA_GRAMMAR([input.y],
+[[%token WITH-DASH
+%token WITHOUT_DASH "WITHOUT-DASH"
+%token WITH.PERIOD
+%token WITHOUT_PERIOD "WITHOUT.PERIOD"
+%%
+start: with-dash without_dash with.period without_period;
+with-dash: WITH-DASH;
+without_dash: "WITHOUT-DASH";
+with.period: WITH.PERIOD;
+without_period: "WITHOUT.PERIOD";
+%%
+]])
+
+# POSIX Yacc accept periods, but not dashes.
+AT_BISON_CHECK([--yacc input.y], [1], [],
+[[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH
+input.y:14.8-16: POSIX Yacc forbids dashes in symbol names: with-dash
+]])
+
+# So warn about them.
+AT_BISON_CHECK([-Wyacc input.y], [], [],
+[[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH
+input.y:14.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
+]])
+
+# Dashes are fine for GNU Bison.
+AT_BISON_CHECK([-o input.c input.y])
+
+# Make sure we don't export silly token identifiers with periods or dashes.
+AT_COMPILE([input.o], [-c input.c])
+
+
+# Period are genuine letters, they can start identifiers.  Dashes
+# and digits can't.
+AT_DATA_GRAMMAR([input.y],
+[[%token .good
+%token -wrong
+%token 1nv4l1d
+%%
+start: .good
+]])
+AT_BISON_CHECK([-o input.c input.y], [1], [],
+[[input.y:10.8: invalid character: `-'
+input.y:11.8: syntax error, unexpected integer, expecting char or identifier or <tag>
+]])
+
+AT_CLEANUP
+
+
 ## --------------------- ##
 ## Unclosed constructs.  ##
 ## --------------------- ##
 
 AT_SETUP([Unclosed constructs])
 
-# Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
-# they were prepended to whatever it STRING_GROW'ed next.  It also threw them
-# away rather than returning them to the parser.  The effect was confusing
-# subsequent error messages.
+# Bison's scan-gram.l once forgot to STRING_FINISH some unclosed
+# constructs, so they were prepended to whatever it STRING_GROW'ed
+# next.  It also threw them away rather than returning them to the
+# parser.  The effect was confusing subsequent error messages.
 
 AT_DATA([input.y],
 [[%token A "a
@@ -666,8 +720,8 @@ AT_CLEANUP
 
 AT_SETUP([%start after first rule])
 
-# Bison once complained that a %start after the first rule was a redeclaration
-# of the start symbol.
+# Bison once complained that a %start after the first rule was a
+# redeclaration of the start symbol.
 
 AT_DATA([input.y],
 [[%%
@@ -821,6 +875,32 @@ input.y:5.9-16: warning: %define variable `special2' is not used
 
 AT_CLEANUP
 
+
+## ------------------- ##
+## %define, --define.  ##
+## ------------------- ##
+
+AT_SETUP([%define, --define])
+
+AT_DATA([input.y],
+[[%define var "value1"
+%%
+start: ;
+]])
+
+AT_BISON_CHECK([[-DFOO -DFOO -Dvar=value input.y]], [0], [],
+[[<command line>:3: warning: %define variable `FOO' redefined
+<command line>:2: warning: previous definition
+input.y:1.9-11: warning: %define variable `var' redefined
+<command line>:4: warning: previous definition
+<command line>:2: warning: %define variable `FOO' is not used
+<command line>:3: warning: %define variable `FOO' is not used
+<command line>:4: warning: %define variable `var' is not used
+input.y:1.9-11: warning: %define variable `var' is not used
+]])
+
+AT_CLEANUP
+
 ## --------------------------- ##
 ## %define Boolean variables.  ##
 ## --------------------------- ##
@@ -841,6 +921,24 @@ AT_BISON_CHECK([[Input.y]], [1], [],
 
 AT_CLEANUP
 
+## ----------------------------------------- ##
+## %define lr.default_rules invalid values.  ##
+## ----------------------------------------- ##
+
+AT_SETUP([[%define lr.default_rules invalid values]])
+
+AT_DATA([[input.y]],
+[[%define lr.default_rules "bogus"
+%%
+start: ;
+]])
+
+AT_BISON_CHECK([[input.y]], [[1]], [[]],
+[[input.y:1.9-24: invalid value for %define variable `lr.default_rules': `bogus'
+]])
+
+AT_CLEANUP
+
 ## ------------------------ ##
 ## %define enum variables.  ##
 ## ------------------------ ##