%{
#include <stdlib.h>
#include <stdio.h>
#include <stream.h>
#include <string.h>
#include "parsing.h"
%}

%token NEWLINE
%token PUTTAB
%token NEWPAR
%token NEWPAGE
%token WAIT

%token KUNTEN
%token KUNTENB
%token KUNTENO
%token KUNTENOS

%token RUBY
%token RUBYLEFT
%token HOR
%token COLOR
%token BGIMAGE
%token BGTILE

%token TEXTA
%token TEXTJ


%%

vtexts
	: /* empty */
	| vtexts WAIT		{if(XWin->event()==-1){XWin->close();exit(0);}}
	| vtexts TEXTJ			{ XWin->putJText     ($2);delete[]$2;}
	| vtexts TEXTA			{ XWin->putAText     ($2);delete[]$2;}
	| vtexts HOR     '{' TEXTA '}'	{ XWin->putHText     ($4);delete[]$4;}
	| vtexts KUNTEN  '{' TEXTJ '}'	{ XWin->putKunten    ($4);delete[]$4;}
	| vtexts KUNTEN  '{' TEXTJ '}'  { XWin->putTmpKunten ($4);delete[]$4;}
			    rubies	{ XWin->setTmpToText ();}
	| vtexts KUNTENB '{' TEXTJ '}'	{ XWin->putKuntenB   ($4);delete[]$4;}
	| vtexts KUNTENB '{' TEXTJ '}'	{ XWin->putTmpKuntenB($4);delete[]$4;}
			     rubies  	{ XWin->setTmpToText ();}
	| vtexts KUNTENO     rubies	{ XWin->setTmpToText ();}
	| vtexts KUNTENOS'{' rubyLeft'}'{ XWin->setTmpToText ();}
	| vtexts NEWLINE		{ XWin->newline      ();}
	| vtexts PUTTAB			{ XWin->putTab       ();}
	| vtexts NEWPAR			{ XWin->newPar       ();}
	| vtexts NEWPAGE		{ XWin->newParPage   ();}
	| vtexts COLOR	 '{' TEXTA '}'	{ XWin->setColor($4);delete[]$4;}
	| vtexts BGIMAGE '{' TEXTA '}'	{ XWin->setImage($4);delete[]$4;}
	| vtexts BGTILE  '{' TEXTA '}'	{ XWin->setTile ($4);delete[]$4;}
	| vtexts RUBY	 '{' main  '}' 
			     rubies	{ XWin->setTmpToText ();}
	| vtexts RUBYLEFT'{' main  '}'
			 '{' rubyLeft'}'{ XWin->setTmpToText ();}
	;

rubies
	: '{' ruby '}'
	| '{' ruby '}' '{' rubyLeft '}'
	;

main
	: /* empty */
	| main TEXTA			{ XWin->putTmpAText  ($2);delete[]$2;}
	| main TEXTJ			{ XWin->putTmpJText  ($2);delete[]$2;}
	| main KUNTEN  '{' TEXTJ '}'	{ XWin->putTmpKunten ($4);delete[]$4;}
	| main KUNTENB '{' TEXTJ '}'	{ XWin->putTmpKuntenB($4);delete[]$4;}
	;

ruby
	: /* empty */
	| ruby TEXTA		{ XWin->putTmpARuby    ($2);delete[]$2;}
	| ruby TEXTJ		{ XWin->putTmpJRuby    ($2);delete[]$2;}
	;

rubyLeft
	: /* empty */
	| rubyLeft TEXTA	{ XWin->putTmpARubyLeft($2);delete[]$2;}
	| rubyLeft TEXTJ	{ XWin->putTmpJRubyLeft($2);delete[]$2;}
	;


