[f87edd]: src / parser / scanner.l  Maximize  Restore  History

Download this file

230 lines (182 with data), 6.3 kB

/*
 *  scanner.h
 *
 *  Copyright  Daniel M. German
 *  
 *  April 2007
 *
 *  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 software 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 software; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *  Author: Daniel M German dmgerman at uvic doooot ca
 * 
 *  This lex input file implements the panotools and hugin input scripts
 *
 *  It ignores 'v' and 'c' lines:
 * 
 *  in 'i' lines it ignores 'K' and 'V' variables which are unique to hugin
 *
 */

%option noyywrap

%{
/* need this for the call to atof() below */
#include <math.h>
#include <string.h>
#include "tparser.h"
#include "tparserprivate.h"
#include "parser.h"

char strBuffer[PT_TOKEN_MAX_LEN+1];
char *strBuffer_ptr;

double ptTokenInt;
double ptTokenFloat;
char ptTokenLineType;
int inVariable = 0;

#define YY_INPUT(buf,result,max_size)  {\
    result = panoScriptScannerGetNextChar(buf, max_size); \
    if (  result <= 0  ) \
      result = YY_NULL; \
    }

%}

DIGIT    [0-9]
LINETYPE [a-zA-Z]
ID       [a-zA-Z]

%x str
%x parm


%%

-?{DIGIT}+    {
              /*  printf( "An integer: %s (%d)\n", yytext, atoi( yytext ) );*/
                panoScriptScannerTokenBegin(yytext); 
                yylval.iVal = atoi( yytext );
                return PT_TOKEN_INT;
               }

-?{DIGIT}+"."{DIGIT}* {
               /*printf( "A float: %s (%g)\n", yytext, atof( yytext ) );*/
                panoScriptScannerTokenBegin(yytext); 
                yylval.fVal = atof( yytext );
                return PT_TOKEN_FLOAT;
            }

^[ \t]*\n    { /* Ignore empty lines */
              inVariable = 0;
            }


[ \t]*\n    { /* END OF LINE is an important marker */
            /*printf( "End of line: %s\n", yytext );*/
            panoScriptScannerTokenBegin(yytext); 
            return PT_TOKEN_EOL;
            }

<<EOF>>     {
               panoScriptScannerTokenBegin(yytext); 
               return 0;
            }


   /* Tokens to ignore */

^v.*\n   { ; } /* Ignore v lines */

^c.*\n   { ; } /* Ignore c lines */

[KV][0-9A-Za-z.=-]+[ \t]* { ; } /* ignore K and V parameters */



   /* These are the types of lines supported */
^o  {
             panoScriptScannerTokenBegin(yytext); 
             return PT_TOKEN_OUTPUT_LINE;
             }

^i           {
             panoScriptScannerTokenBegin(yytext); 
             return PT_TOKEN_INPUT_LINE;
             }

^p  {
             panoScriptScannerTokenBegin(yytext); 
             return PT_TOKEN_PANO_LINE;
             }

^m  {
             panoScriptScannerTokenBegin(yytext); 
             return PT_TOKEN_OPTIMIZE_LINE;
             }

^C  {
             panoScriptScannerTokenBegin(yytext); 
             return PT_TOKEN_CONTROL_PTS_LINE;
             }

  /*********************************/

","           { 
              panoScriptScannerTokenBegin(yytext); 
              return PT_TOKEN_COMMA; }


{ID}        {
               /*printf( "An identifier: %s\n", yytext );*/
                if (!inVariable) {
                   inVariable = 1;
                   panoScriptScannerTokenBegin(yytext); 
                   strncpy(yylval.strVal, yytext, PT_TOKEN_MAX_LEN);
                   return PT_TOKEN_KEYWORD;
                } else {
                 /* Sometimes this correponds to the first char of
                   a parameter without quotes */
                   BEGIN(parm);
                   strncpy(strBuffer, yytext, PT_TOKEN_MAX_LEN);
                }
             }

<parm>[0-9a-zA-Z]+ {
                  /* Read the rest of the parameter */
                   BEGIN(INITIAL);
                   inVariable = 0;
                   strncat(strBuffer, yytext, PT_TOKEN_MAX_LEN -1);
                   strncpy(yylval.strVal, strBuffer, PT_TOKEN_MAX_LEN);
                   return PT_TOKEN_STRING;
                }


[ \t]+        {  /*printf("skypping separator\n");  */
                panoScriptScannerTokenBegin(yytext); 
                inVariable = 0;
                return PT_TOKEN_SEPARATOR;
              }


=            { 
                panoScriptScannerTokenBegin(yytext); 
                return PT_TOKEN_REFERENCE; }

"#".+\n        /* eat up comments */
              {
                ;
              }

\"             {
                 panoScriptScannerTokenBegin(yytext); 
                 strBuffer_ptr = strBuffer; BEGIN(str);
                 //printf("Beginning of string\n");
               }

<str>\"        { /* saw closing quote - all done */
                   BEGIN(INITIAL);
                   *strBuffer_ptr = '\0';
                   /* return string constant token type and
                    * value to parser
                    */
              //     printf("A string %s\n", strBuffer);
                   strncpy(yylval.strVal, strBuffer, PT_TOKEN_MAX_LEN);
                   return PT_TOKEN_STRING;
                }

<str>\n        {
                 /* error - unterminated string constant */
                 /* generate error message */
                 panoScriptParserError( "non-terminated string: %s\n", yytext ); 
                 return -0;
               }

<str>\\n  *strBuffer_ptr++ = '\n';
<str>\\t  *strBuffer_ptr++ = '\t';
<str>\\r  *strBuffer_ptr++ = '\r';
<str>\\b  *strBuffer_ptr++ = '\b';
<str>\\f  *strBuffer_ptr++ = '\f';

<str>\\(.|\n)  *strBuffer_ptr++ = yytext[1];

<str>[^\\\n\"]+    {
                     int currentLen = strlen(strBuffer);
                     char *yptr = yytext;
                     while ( *yptr && ++currentLen < PT_TOKEN_MAX_LEN)
                           *strBuffer_ptr++ = *yptr++;
                   }

.           { 
              panoScriptParserError( "Unrecognized character: %s\n", yytext );
              return 0;
            }

%%

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks