Qucs-core  0.0.19
scan_csv.l
Go to the documentation of this file.
00001 /* -*-c-*- */
00002 
00003 %{
00004 /*
00005  * scan_csv.l - scanner for CSV files
00006  *
00007  * Copyright (C) 2007 Stefan Jahn <stefan@lkcc.org>
00008  *
00009  * This is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013  *
00014  * This software is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this package; see the file COPYING.  If not, write to
00021  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00022  * Boston, MA 02110-1301, USA.
00023  *
00024  * $Id$
00025  *
00026  */
00027 
00028 #if defined(__clang__)
00029 #pragma clang diagnostic push
00030 #pragma clang diagnostic ignored "-Wdeprecated-register"
00031 #endif
00032 
00033 #if HAVE_CONFIG_H
00034 # include <config.h>
00035 #endif
00036 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <ctype.h>
00041 
00042 #ifdef __MINGW32__
00043 #include <io.h>
00044 #endif
00045 
00046 #ifdef HAVE_UNISTD_H
00047 #include <unistd.h>
00048 #endif
00049 
00050 #include "logging.h"
00051 #include "complex.h"
00052 #include "object.h"
00053 #include "vector.h"
00054 #include "dataset.h"
00055 #include "check_csv.h"
00056 #include "tokens_csv.h"
00057 
00058 using namespace qucs;
00059 
00060 %}
00061 
00062 WS       [ \t\n\r]
00063 SEP      [;,]
00064 ARRAY    \[[0-9]+,[0-9]+\]
00065 ID1      [a-zA-Z_][a-zA-Z0-9_.]*{ARRAY}?
00066 ID2      [^\"\n\r]*
00067 DIGIT    [0-9]
00068 EXPONENT [Ee][+-]?{DIGIT}+
00069 INT      [+-]?{DIGIT}+
00070 FLOAT1   [+-]?{DIGIT}+{EXPONENT}
00071 FLOAT2   [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})?
00072 SPACE    [ \t]
00073 
00074 %x COMMENT IDENT
00075 %option yylineno noyywrap nounput noinput prefix="csv_"
00076 
00077 %%
00078 
00079 <INITIAL>\"    { BEGIN(IDENT); /* pass the '"' to the parser */ return '"'; }
00080 <INITIAL>\r?\n { /* detect end of line */ return Eol; }
00081 
00082 <INITIAL>{ID1} { /* identify identifier */
00083     csv_lval.ident = strdup (csv_text);
00084     return Identifier;
00085   }
00086 
00087 <IDENT>{ID2} { /* identify identifier */
00088     csv_lval.ident = strdup (csv_text);
00089     return Identifier;
00090   }
00091 
00092 <IDENT>\"    { BEGIN(INITIAL); return '"'; }
00093 <IDENT>\r?\n { BEGIN(INITIAL); return Eol; }
00094 
00095 <*>({SPACE}|{SEP}) /* skip spaces and separators */
00096 
00097 <INITIAL>({FLOAT1}|{FLOAT2}|{INT}) { /* identify float */
00098     csv_lval.f = strtod (csv_text, NULL);
00099     return Float;
00100   }
00101 
00102 <INITIAL>. { /* any other character in invalid */
00103     logprint (LOG_ERROR,
00104               "line %d: syntax error, unrecognized character: `%s'\n",
00105               csv_lineno, csv_text);
00106     return InvalidCharacter;
00107   }
00108 
00109 <COMMENT>.     { /* skip any character in here */ }
00110 <COMMENT>\r?\n { BEGIN(INITIAL); /* skipping ends here */ return Eol; }
00111 
00112 %%