%{
#include <stdio.h>
#include <string.h>
#include <stream.h>
#include <ctype.h>
#include "parsing.h"
#include "parser.tab.h"
int       LineNumber= 0;
%}

letDigit	[a-zA-Z][a-zA-Z0-9]*

%%

[ \t\f]					;
\n					{ LineNumber++;}
([^ \t\n\{\}\\\x0-\x1f\x80-\xff]|\\\{|\\\}|\\\\)+	{
					  yylval=new char[strlen(yytext)+1];
					  char* YYP=yytext;char* YYL=yylval;
					  while(*YYP!='\0')
					    {
					     if(*YYP=='\\'&&*(YYP+1)!='\\')
					       YYP++;
					     else *(YYL++)=*(YYP++);
					    }
					  *YYL='\0'; return TEXTA;
					}
([\x80-\xff][\x80-\xff])+		{
					  yylval=new char[strlen(yytext)+1];
					  strcpy(yylval,yytext); return TEXTJ;
					}
"\x1b$B"([\x20-\x7f][\x20-\x7f])*"\x1b(B"	{
					  yylval=new char[strlen(yytext)-5];
					  for(int I=0;I<strlen(yytext)-6;++I)
					    {
					      yylval[I]=(char)((uchar)
					        yytext[I+3]+0x80);
					     }
					  yylval[strlen(yytext)-6]='\0';
					  return TEXTJ;
					}
\\"color"				{ return COLOR;}
\\"clr"					{ return COLOR;}
\\"c"					{ return COLOR;}
\\"bgimage"				{ return BGIMAGE;}
\\"bgtile"				{ return BGTILE;}
\\"newline"				{ return NEWLINE;}
\\"n"					{ return NEWLINE;}
\\"tab"					{ return PUTTAB;}
\\"t"					{ return PUTTAB;}
\\"paragraph"				{ return NEWPAR;}
\\"par"					{ return NEWPAR;}
\\"page"				{ return NEWPAGE;}
\\"f"					{ return NEWPAGE;}
\\"w"					{ return WAIT;}
\\"wait"				{ return WAIT;}
\\"horizon"				{ return HOR;}
\\"h"					{ return HOR;}
\\"kunten"				{ return KUNTEN;}
\\"k"					{ return KUNTEN;}
\\"-kunten"				{ return KUNTENB;}
\\"-k"					{ return KUNTENB;}
\\"kuntenokuri"				{ return KUNTENO;}
\\"ko"					{ return KUNTENO;}
\\"kuntensaidoku"			{ return KUNTENOS;}
\\"ks"					{ return KUNTENOS;}
\\"ruby"				{ return RUBY;}
\\"rb"					{ return RUBY;}
\\"rubyleft"				{ return RUBYLEFT;}
\\"rl"					{ return RUBYLEFT;}
.					{ return yytext[0];}
%%

int yyerror(char* Error)
{ cerr << form("%s:%d: %s.\n",FileName,LineNumber+1,Error); return 0;}

