Good idea! I decided to implement this; here's the patch I used:
=== CUT HERE ===
---
src/lexer.l | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/lexer.l b/src/lexer.l
index d1ade32..91da32e 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -106,19 +106,25 @@ void yyerror(const char *errtype);
* generated by lex(1) and does normal tokenizing.
*/
+static bool bangflag = false;
+
#undef getc
int getc(FILE *fp)
{
extern FILE* yyin;
- static bool bangflag = false;
static bool backflag = false;
-
static bool eolflag = false;
+ static bool bangcheck = false; /* AIS: for lexer-based bang checks */
if ((size_t)(lineptr - linebuf) > sizeof linebuf)
ick_lose(IE666, iyylineno, (char *)NULL);
+ if (bangcheck)
+ {
+ bangcheck = false;
+ return 0;
+ }
if (bangflag)
{
bangflag = false;
@@ -160,13 +166,14 @@ int getc(FILE *fp)
eolflag = false;
- if (c == '!')
+ if (c == '!' || c == 0xB0)
{
- *lineptr++ = '!';
- bangflag = true;
- return(c = '\'');
+ /* AIS: A potential bang/rabbit; insert a NUL character after it to
+ give the lexer time to set the bangflag */
+ bangcheck = true;
}
- else if (c == '\b') /* convert ctrl-H (backspace) to
+
+ if (c == '\b') /* convert ctrl-H (backspace) to
two chars "^" and "H" so lex can take it */
{
*lineptr++ = '\b';
@@ -226,6 +233,7 @@ I [A-Z]
%%
+\x00 ;
{D} {yylval.numval = myatoi(yytext); return(NUMBER);}
\_ {return(NOSPOT);}
\. {return(ick_ONESPOT);}
@@ -292,9 +300,17 @@ V {yylval.numval = OR; return(UNARY);}
CLOSE\(SPARK\|EARS\),
and CLEARSPARKEARSTACK */
return(temp?OPENSPARK:CLOSESPARK);}
+\! {char temp = sparkearsstack[sparkearslev/32]&1;
+ STACKSPARKEARS(0);
+ bangflag=1; /* AIS: New bangflag handling */
+ return(temp?OPENSPARK:CLOSESPARK);}
\" {char temp = sparkearsstack[sparkearslev/32]&1;
STACKSPARKEARS(1);
return(temp?CLOSEEARS:OPENEARS);}
+\xF0\x9F\x90\xB0 {char temp = sparkearsstack[sparkearslev/32]&1;
+ STACKSPARKEARS(1);
+ bangflag=1; /* AIS: The rabbit case is new */
+ return(temp?CLOSEEARS:OPENEARS);}
\({W}{D}\) {SETLINENO; yylval.numval = myatoi(yytext); return(LABEL);}
=== CUT HERE ===
It's pretty hacky, but then so was the existing patch for this, and I
wanted to get something working.
--
ais523