%{

/*
 * Copyright (C) 2003 Clemens Fuchslocher
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "VRMLReader.yacc.h"

%}

%option noyywrap
%option yylineno

DIGIT    [0-9]
SIGN     [\+\-]
EXPONENT ([Ee]{SIGN}?{DIGIT}+)

%x LITERAL_STATE

%%

^"#VRML V2.0 utf8"	{ return VRML_HEADER; }
"#"[^\n\r]*		{ }

DEF               { BEGIN(LITERAL_STATE); return DEF; }
USE               { BEGIN(LITERAL_STATE); return USE; }
Group             { return GROUP; }
Transform         { return TRANSFORM; }
center            { return CENTER; }
rotation          { return ROTATION; }
scale             { return SCALE; }
scaleOrientation  { return SCALEORIENTATION; }
translation       { return TRANSLATION; }
bboxCenter        { return BBOXCENTER; }
bboxSize          { return BBOXSIZE; }
Children          { return CHILDREN; }
Shape             { return SHAPE; }
appearance        { return APPEARANCE; }
Appearance        { return APPEARANCE; }
material          { return MATERIAL; }
Material          { return MATERIAL; }
diffuseColor      { return DIFFUSECOLOR; }
emissiveColor     { return EMISSIVECOLOR; }
specularColor     { return SPECULARCOLOR; }
ambientIntensity  { return AMBIENTINTENSITY; }
transparency      { return TRANSPARENCY; }
shininess         { return SHININESS; }
geometry          { return GEOMETRY; }
IndexedFaceSet    { return INDEXEDFACESET; }
coord             { return COORD; }
Coordinate        { return COORDINATE; }
point             { return POINT; }
coordIndex        { return COORDINDEX; }
normal            { return NORMAL; }
Normal            { return NORMAL; }
normalIndex       { return NORMALINDEX; }
normalPerVertex   { return NORMALPERVERTEX; }
vector            { return VECTOR; }
color             { return COLOR; }
Color             { return COLOR; }
colorIndex        { return COLORINDEX; }
colorPerVertex    { BEGIN(LITERAL_STATE); return COLORPERVERTEX; }
texCoord          { return TEXCOORD; }
TextureCoordinate { return TEXTURECOORDINATE; }
texCoordIndex     { return TEXCOORDINDEX; }
ccw               { BEGIN(LITERAL_STATE); return CCW; }
convex            { BEGIN(LITERAL_STATE); return CONVEX; }
creaseAngle       { return CREASEANGLE; }
solid             { return SOLID; }
TRUE              { return VRML_TRUE; }
FALSE             { return VRML_FALSE; }


"{" { return '{'; }
"}" { return '}'; }
"[" { return '['; }
"]" { return ']'; }
"," { return ','; }


{SIGN}?{DIGIT}*("."{DIGIT}+)?{EXPONENT}? {
	VRMLReader_lval.double_value = atof(yytext);
	return NUMBER;
}


<LITERAL_STATE>[^ \#\n\r]+ {
	BEGIN(INITIAL);
	VRMLReader_lval.literal_value = strdup(yytext);
	return LITERAL;
}


" "|\t|\r|\n { /* void */ }
.            { fprintf(stderr, "%s[%d]: Uncatched character: `%s'\n", __FILE__, __LINE__, yytext); return UNCATCHED; }

%%

void VRMLReader_error(const char *error)
{
	fprintf(stderr, "%s[%d]: %s, line %d\n", __FILE__, __LINE__, error, VRMLReader_lineno);
}
