[ragel-users] making \n, \t etc printable
Adrian Thurston
thurs... at cs.queensu.ca
Fri Feb 9 04:39:24 UTC 2007
Thanks, I applied it and added \a and \v.
One other character I'd like to change is 32. Printing it as ' ' looks a
little strange sometimes. I'm thinking of changing it to SP instead.
-Adrian
Arne Goedeke wrote:
> hey!
>
> I thought it would be nice for most people to have \n, \t and such
> being printed out by rlcodegen -Vp using backslash escapes. here is my
> patch:
>
> --- common/common.h 2007-01-21 23:58:22.000000000 +0100
> +++ common/common.h 2007-02-08 23:24:29.000000000 +0100
> @@ -60,7 +60,11 @@
>
> bool isUpper() const { return ( 'A' <= key && key <= 'Z' ); }
> bool isLower() const { return ( 'a' <= key && key <= 'z' ); }
> - bool isPrintable() const { return ( 32 <= key && key < 127 ); }
> + bool isPrintable() const
> + {
> + return ( 32 <= key && key < 127 ) || key == '\b' || key == '\t'
> + || key == '\n' || key == '\f' || key == '\r';
> + }
>
> Key toUpper() const
> { return Key( 'A' + ( key - 'a' ) ); }
> --- rlcodegen/gvdotgen.cpp 2007-01-21 23:58:22.000000000 +0100
> +++ rlcodegen/gvdotgen.cpp 2007-02-08 23:24:36.000000000 +0100
> @@ -47,6 +47,21 @@
> case '"': case '\\':
> out << "\\" << cVal;
> break;
> + case '\n':
> + out << "\\\\n";
> + break;
> + case '\t':
> + out << "\\\\t";
> + break;
> + case '\r':
> + out << "\\\\r";
> + break;
> + case '\b':
> + out << "\\\\b";
> + break;
> + case '\f':
> + out << "\\\\f";
> + break;
> default:
> out << cVal;
> break;
>
>
>
More information about the ragel-users
mailing list