Re: ylwrap proposition
Ralf Wildenhues [EMAIL PROTECTED] ha escrit: Can s/yy/.../ change anything unintended? E.g., do we need to ensure it only changes words beginning with yy? In theory it could, for example if the programmer used identifiers beginning with, or containing `yy'. However, I can hardly imagine someone who does that. At least, all yacc manuals declare that `yy' prefix is reserved for yacc/lex identifiers and explicitly discourage its use in application identifiers. It would be preferable, of course, to change only those `yy' that occur at the beginning of words. But I cannot figure out a portable way of doing so in sed. Anyways, the similar ylwrap version was used by GNU mailutils and radius for the last six years, without apparent problems. Can it omit anything that needs changed (what about `YY...')? The purpose of the `--prefix' option is to make it possible for a program to contain several parsers without name clashes. All identifiers starting with `YY' are macros and they are not used outside the y.tab.c source, or, at the very most, outside of y.tab.c and the corresponding lexical analizer, so they will not cause name clashes either. What about the header file, doesn't that need to be changed as well? It will be changed as well, if specified in the command line: ylwrap --prefix fmt \ mh_fmtgram.y y.tab.c fmtgram.c y.tab.h fmtgram.h -- yacc -d Does the renaming work for extensions such as bison's for C++ parsers? I never tried. I will test this. ylwrap is used for both lex and yacc: should we disable the functionality for lex (as it may produce garbage there?), and should it be made clear in the help output that -p is only for the yacc part? No, on the contrary, it is important that lex sources be processed as well. They follow the same naming scheme as grammars and it is necessary for proper parser-lexer interaction. This patch needs the following things to be complete. If you are willing to help with any of them, that'd be great. No problem. - update scriptversion and copyright year in the ylwrap script. - add test(s) to ensure the new functionality works as expected. tests/yacc8.test can serve as a starting point for a new test. - write ChangeLog entry, adjust NEWS, THANKS, doc/automake.texi: mention new option, change recommendation about multiple parsers (probably the list of #defines should not be removed just yet, it may be interesting if only for historical purposes). Allow me a couple of days to do that. + --p|--pr|--pre|--pref|--prefi|--prefix) -p is not actually supported, but documented. Oh, yes. I'll fix it. Let's just rewrite the whole thing like: sed -e $YYREPL /^#/!b s,$input_rx,, s,$from,$2, s,$FROM,$TARGET, $from $target || ret=$? OK Regards, Sergey
Re: ylwrap proposition
* Sergey Poznyakoff wrote on Sat, Jun 23, 2007 at 02:04:29PM CEST: Ralf Wildenhues [EMAIL PROTECTED] ha escrit: Can s/yy/.../ change anything unintended? E.g., do we need to ensure it only changes words beginning with yy? In theory it could, for example if the programmer used identifiers beginning with, or containing `yy'. However, I can hardly imagine someone who does that. At least, all yacc manuals declare that `yy' prefix is reserved for yacc/lex identifiers and explicitly discourage its use in application identifiers. It would be preferable, of course, to change only those `yy' that occur at the beginning of words. But I cannot figure out a portable way of doing so in sed. Something like s/^yy/REPL/ s/\([^a-zA-Z0-9]\)yy/\1REPL/ but then sed should be executed as 'LC_ALL=C sed' to avoid locale issues. Another possibility is to just list all letters, as is done elsewhere in the script (and could be factored in shell variables, like Autoconf does. Cheers, Ralf
Re: ylwrap proposition
Sergey Poznyakoff wrote: Ralf Wildenhues ha escrit: Can s/yy/.../ change anything unintended? E.g., do we need to ensure it only changes words beginning with yy? In theory it could, for example if the programmer used identifiers beginning with, or containing `yy'. However, I can hardly imagine someone who does that. At least, all yacc manuals declare that `yy' prefix is reserved for yacc/lex identifiers and explicitly discourage its use in application identifiers. I believe that it is very well known and well propagated knowledge that the strings yy and YY are often used to mutate the result into a unique identifier. Almost all practical documentation uses sed substitution in the examples. In fact this may be such a well known technique that many users are probably relying upon this happening for their own identifiers in addition to the ones from yacc/lex. Adding a lot of extra work to avoid this mutation may actually create problems when expected transformations don't occur. I am pretty sure that I have code that falls into this area but would have to look. Bob
Re: ylwrap proposition
Bob Proulx [EMAIL PROTECTED] ha escrit: I believe that it is very well known and well propagated knowledge that the strings yy and YY are often used to mutate the result into a unique identifier. Almost all practical documentation uses sed substitution in the examples. In fact this may be such a well known technique that many users are probably relying upon this happening for their own identifiers in addition to the ones from yacc/lex. That is true when one has only one parser in his program. Note, that `--prefix' is designed only for the cases, when one needs to have several yacc-generated parsers within a single program. In such cases, it is impossible to link them together without renaming all globally-visible identifiers. Regards, Sergey