bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`cherry pick -x' with conflicts (was: Re: FYI: variables: accept dashes)


From: Joel E. Denny
Subject: `cherry pick -x' with conflicts (was: Re: FYI: variables: accept dashes)
Date: Wed, 29 Apr 2009 19:32:32 -0400 (EDT)

On Sun, 26 Apr 2009, Akim Demaille wrote:

> Le 23 avr. 09 ? 07:00, Joel E. Denny a ?crit :
> 
> > > I wanted to push it seem Joel preferred dashes to underscores in his newly
> > > introduced variables.
> > 
> > I was able to cherry-pick this patch into branch-2.5 without any other
> > cherry-picking.  The main conflict was that I couldn't apply the bison.m4
> > change, but that change isn't relevant in branch-2.5, right?
> 
> The clash was big in bison.m4, indeed, and I stopped there.  But you are
> right, we don't need it.
> 
> 
> > The other
> > conflict relates to the change discussed below, and it's superficial.
> > Did I miss anything?  I think it's a nice patch, and I'd like to use it.
> > I haven't pushed.
> 
> Please, go ahead.

Ok, I cherry picked it into branch-2.5 and pushed.

Normally I run `git cherry-pick -x <commit>' so that the log message picks 
up the nice "(cherry picked from commit <commit>)" line.  I like that line 
because it shows that the patch is being applied to a different branch 
than the branch for which it was originally developed.  Moreover, that 
line makes it a little easier to determine what patches are shared since 
the two branches were split.

When there are conflicts, git encourages me to commit with `git commit -c 
<commit>' in order to retain author and date info.  Unfortunately, the log 
message then loses the "(cherry picked ...)" line.  However, because of 
the conflicts, I think it's even more important to record that the patch 
was not originally developed for this branch.  If I commit with `git 
commit' instead, the log message loses the original author and date info, 
but it gains back the "(cherry picked ...)" line plus information on which 
files had conflicts that needed to be resolved.

For the cherry pick I just pushed, I used `git cherry-pick -x <commit>', I 
resolved the conflicts, and I committed with `git commit -c <commit>' to 
retain the original author and date information.  However, when prompted 
to edit the log message, I removed the old message and read in 
.git/MERGE_MSG, which contains the "(cherry picked ...)" line plus 
conflict information.

I like the result, shown below, but am I going too far?  Is there a better 
way?

From 663ce7bb3e7e325eaa321f22509e6163f1bec4e2 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Mon, 20 Apr 2009 12:24:23 +0200
Subject: [PATCH] variables: accept dashes.

        * src/scan-gram.l ({id}): Also accept dashes after the initial
        letter.
        ({directive}): Use {id}.
        * src/parse-gram.y: Comment and formatting changes.
        * doc/bison.texinfo (Symbols): Adjust the lexical definitions of
        symbols.
        * src/complain.h, src/complain.c (yacc_at): New.
        * src/symtab.c (symbol_new): Use yacc_at to report inappropriate
        symbol names.
        * src/output.c (token_definitions_output): Do not #define token
        names with dashes.
(cherry picked from commit 4f646c3794c45940aaf96d5409eff02a2c74978e)

Conflicts:

        data/bison.m4
        src/parse-gram.y

diff --git a/ChangeLog b/ChangeLog
index b42a91d..69edc6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2009-04-20  Akim Demaille  <address@hidden>
+
+       variables: accept dashes.
+       * src/scan-gram.l ({id}): Also accept dashes after the initial
+       letter.
+       ({directive}): Use {id}.
+       * src/parse-gram.y: Comment and formatting changes.
+       * doc/bison.texinfo (Symbols): Adjust the lexical definitions of
+       symbols.
+       * src/complain.h, src/complain.c (yacc_at): New.
+       * src/symtab.c (symbol_new): Use yacc_at to report inappropriate
+       symbol names.
+       * src/output.c (token_definitions_output): Do not #define token
+       names with dashes.
+
 2009-04-24  Joel E. Denny  <address@hidden>
 
        Clean up recent patches a little.
diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index c52d7b8..46c95f0 100644
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -3051,8 +3051,12 @@ A @dfn{nonterminal symbol} stands for a class of 
syntactically
 equivalent groupings.  The symbol name is used in writing grammar rules.
 By convention, it should be all lower case.
 
-Symbol names can contain letters, digits (not at the beginning),
-underscores and periods.  Periods make sense only in nonterminals.
+Symbol names can contain letters, underscores, period, and (not at the
+beginning) digits and dashes.  Dashes in symbol names are a GNU
+extension, incompatible with @acronym{POSIX} Yacc.  Terminal symbols
+that contain periods or dashes make little sense: since they are not
+valid symbols (in most programming languages) they are not exported as
+token names.
 
 There are three ways of writing terminal symbols in the grammar:
 
diff --git a/src/complain.c b/src/complain.c
index 2c26c4e..4cc35c8 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -1,6 +1,6 @@
 /* Declaration for error-reporting function for Bison.
 
-   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006
+   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2009
    Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -120,6 +120,27 @@ complain (const char *message, ...)
 }
 
 
+/*--------------------------------------------------------------.
+| An incompatibility with POSIX Yacc: mapped either to warn* or |
+| complain* depending on yacc_flag.                             |
+`--------------------------------------------------------------*/
+
+void
+yacc_at (location loc, const char *message, ...)
+{
+  if (yacc_flag)
+    {
+      ERROR_MESSAGE (&loc, NULL, message);
+      complaint_issued = true;
+    }
+  else if (warnings_flag & warnings_yacc)
+    {
+      set_warning_issued ();
+      ERROR_MESSAGE (&loc, _("warning"), message);
+    }
+}
+
+
 /*-------------------------------------------------.
 | A severe error has occurred, we cannot proceed.  |
 `-------------------------------------------------*/
diff --git a/src/complain.h b/src/complain.h
index a633613..89cdd91 100644
--- a/src/complain.h
+++ b/src/complain.h
@@ -1,5 +1,5 @@
 /* Declaration for error-reporting function for Bison.
-   Copyright (C) 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2006, 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
@@ -39,6 +39,13 @@ void complain (char const *format, ...)
 void complain_at (location loc, char const *format, ...)
   __attribute__ ((__format__ (__printf__, 2, 3)));
 
+/** An incompatibility with POSIX Yacc: mapped either to warn* or
+    complain* depending on yacc_flag. */
+
+void yacc_at (location loc, char const *format, ...)
+  __attribute__ ((__format__ (__printf__, 2, 3)));
+
+
 /** A fatal error, causing immediate exit.  */
 
 void fatal (char const *format, ...)
diff --git a/src/output.c b/src/output.c
index f725147..e299230 100644
--- a/src/output.c
+++ b/src/output.c
@@ -363,9 +363,11 @@ token_definitions_output (FILE *out)
       if (sym->tag[0] == '\'' || sym->tag[0] == '\"')
        continue;
 
-      /* Don't #define nonliteral tokens whose names contain periods
-        or '$' (as does the default value of the EOF token).  */
-      if (strchr (sym->tag, '.') || strchr (sym->tag, '$'))
+      /* Don't #define nonliteral tokens whose names contain periods,
+         dashes or '$' (as does the default value of the EOF token).  */
+      if (strchr (sym->tag, '.')
+          || strchr (sym->tag, '-')
+          || strchr (sym->tag, '$'))
        continue;
 
       fprintf (out, "%s[[[%s]], %d]",
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 83b02e3..2e4168b 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -547,15 +547,12 @@ rhs:
 
 variable:
   ID
-  | STRING { $$ = uniqstr_new ($1); } /* deprecated and not M4-friendly */
-  ;
+| STRING { $$ = uniqstr_new ($1); }
+;
 
 /* Some content or empty by default. */
 content.opt:
-  /* Nothing. */
-    {
-      $$ = "";
-    }
+  /* Nothing. */   { $$ = ""; }
 | STRING
 ;
 
diff --git a/src/scan-gram.l b/src/scan-gram.l
index 292960c..2ef4eb3 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -90,8 +90,8 @@ static void unexpected_newline (boundary, char const *);
 %x SC_STRING SC_CHARACTER
 
 letter   [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
-id       {letter}({letter}|[0-9])*
-directive %{letter}({letter}|[0-9]|-)*
+id       {letter}({letter}|[0-9]|-)*
+directive %{id}
 int      [0-9]+
 
 /* POSIX says that a tag must be both an id and a C union member, but
@@ -382,7 +382,7 @@ splice       (\\[ \f\t\v]*\n)*
     unexpected_eof (token_start, "'");
     STRING_FINISH;
     loc->start = token_start;
-    if (strlen(last_string) > 1)
+    if (strlen (last_string) > 1)
       val->character = last_string[1];
     else
       val->character = last_string[0];
diff --git a/src/symtab.c b/src/symtab.c
index 1db83f6..f9560ef 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -1,6 +1,7 @@
 /* Symbol table manager for Bison.
 
-   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007,
+   2008, 2009
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
@@ -58,6 +59,13 @@ symbol_new (uniqstr tag, location loc)
   symbol *res = xmalloc (sizeof *res);
 
   uniqstr_assert (tag);
+
+  /* If the tag is not a string (starts with a double quote), check
+     that it is valid for Yacc. */
+  if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-'))
+    yacc_at (loc, _("POSIX Yacc forbids dashes in symbol names: %s"),
+             tag);
+
   res->tag = tag;
   res->location = loc;
 
-- 
1.5.4.3

reply via email to

[Prev in Thread] Current Thread [Next in Thread]