Blame dds.lex

Packit a4aae4
/*
Packit a4aae4
 -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
 This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
 Access Protocol.
Packit a4aae4
Packit a4aae4
 Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
 Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
Packit a4aae4
 This library is free software; you can redistribute it and/or
Packit a4aae4
 modify it under the terms of the GNU Lesser General Public
Packit a4aae4
 License as published by the Free Software Foundation; either
Packit a4aae4
 version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
Packit a4aae4
 This library is distributed in the hope that it will be useful,
Packit a4aae4
 but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
 Lesser General Public License for more details.
Packit a4aae4
Packit a4aae4
 You should have received a copy of the GNU Lesser General Public
Packit a4aae4
 License along with this library; if not, write to the Free Software
Packit a4aae4
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Packit a4aae4
Packit a4aae4
 You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
 (c) COPYRIGHT URI/MIT 1994-1999
Packit a4aae4
Packit a4aae4
*/
Packit a4aae4
Packit a4aae4
/*
Packit a4aae4
   Scanner for the DDS. This file works with gnu's flex scanner generator. It
Packit a4aae4
   returns either DATASET, INDEPENDENT, DEPENDENT, ARRAY, MAPS, LIST,
Packit a4aae4
   SEQUENCE, STRUCTURE, FUNCTION, GRID, BYTE, INT32, FLOAT64, STRING, URL, ID
Packit a4aae4
   or one of the single character tokens `{', `}', `;', `=' or `\n' as
Packit a4aae4
   integers. In the case of an ID, the scanner stores a pointer to the lexeme
Packit a4aae4
   in yylval (whose type is char *).
Packit a4aae4
Packit a4aae4
   The scanner discards all comment text.
Packit a4aae4
Packit a4aae4
   The scanner is not reentrant, but can share name spaces with other
Packit a4aae4
   scanners.
Packit a4aae4
Packit a4aae4
   Note:
Packit a4aae4
   1) The `defines' file dds.tab.h is built using `bison -d'.
Packit a4aae4
   2) Define YY_DECL such that the scanner is called `ddslex'.
Packit a4aae4
   3) When bison builds the dds.tab.h file, it uses `dds' instead of `yy' for
Packit a4aae4
   variable name prefixes (e.g., yylval --> ddslval).
Packit a4aae4
Packit a4aae4
   jhrg 8/29/94
Packit a4aae4
*/
Packit a4aae4
Packit a4aae4
%{
Packit a4aae4
Packit a4aae4
#include "config_dap.h"
Packit a4aae4
Packit a4aae4
#include <cstdio>
Packit a4aae4
#include <cstring>
Packit a4aae4
Packit a4aae4
#include "parser.h"
Packit a4aae4
#include "dds.tab.hh"
Packit a4aae4
#include "escaping.h"
Packit a4aae4
Packit a4aae4
using namespace libdap ;
Packit a4aae4
Packit a4aae4
#ifndef YY_PROTO
Packit a4aae4
#define YY_PROTO(proto) proto
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#define YY_DECL int ddslex YY_PROTO(( void ))
Packit a4aae4
Packit a4aae4
#define YY_INPUT(buf,result,max_size) { \
Packit a4aae4
    if (fgets((buf), (max_size), (ddsin)) == NULL) { \
Packit a4aae4
      *buf = '\0'; \
Packit a4aae4
    } \
Packit a4aae4
    result = (feof(ddsin) || *buf == '\0' || strncmp(buf, "Data:\n", 6) == 0) \
Packit a4aae4
             ? YY_NULL : strlen(buf); \
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
#define YY_FATAL_ERROR(msg) {\
Packit a4aae4
    throw(Error(string("Error scanning DDS object text: ") + string(msg))); \
Packit a4aae4
    yy_fatal_error(msg); /* see das.lex */ \
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
int dds_line_num = 1;
Packit a4aae4
Packit a4aae4
static void store_word();
Packit a4aae4
Packit a4aae4
%}
Packit a4aae4
Packit a4aae4
%option noyywrap
Packit a4aae4
%option nounput
Packit a4aae4
%option noinput
Packit a4aae4
%option 8bit
Packit a4aae4
%option prefix="dds"
Packit a4aae4
%option outfile="lex.dds.cc"
Packit a4aae4
%x comment
Packit a4aae4
Packit a4aae4
DATASET 	DATASET|Dataset|dataset
Packit a4aae4
LIST 		LIST|List|list
Packit a4aae4
SEQUENCE 	SEQUENCE|Sequence|sequence
Packit a4aae4
STRUCTURE 	STRUCTURE|Structure|structure
Packit a4aae4
GRID 		GRID|Grid|grid
Packit a4aae4
BYTE 		BYTE|Byte|byte
Packit a4aae4
INT16 		INT16|Int16|int16
Packit a4aae4
UINT16 		UINT16|UInt16|uint16
Packit a4aae4
INT32 		INT32|Int32|int32
Packit a4aae4
UINT32 		UINT32|UInt32|uint32
Packit a4aae4
FLOAT32 	FLOAT32|Float32|float32
Packit a4aae4
FLOAT64 	FLOAT64|Float64|float64
Packit a4aae4
STRING 		STRING|String|string
Packit a4aae4
URL 		URL|Url|url
Packit a4aae4
Packit a4aae4
/* See das.lex for comments about the characters allowed in a WORD.
Packit a4aae4
   10/31/2001 jhrg */
Packit a4aae4
Packit a4aae4
WORD        [-+a-zA-Z0-9_/%.\\*][-+a-zA-Z0-9_/%.\\#*]*
Packit a4aae4
Packit a4aae4
NEVER		[^\-+a-zA-Z0-9_/%.\\#,(){}[\]]
Packit a4aae4
Packit a4aae4
%%
Packit a4aae4
Packit a4aae4
"{"         return (int)*yytext;
Packit a4aae4
"}" 	    return (int)*yytext;
Packit a4aae4
"["			return (int)*yytext;
Packit a4aae4
"]"			return (int)*yytext;
Packit a4aae4
":"			return (int)*yytext;
Packit a4aae4
";" 	    return (int)*yytext;
Packit a4aae4
"="			return (int)*yytext;
Packit a4aae4
Packit a4aae4
{DATASET}		store_word(); return SCAN_DATASET;
Packit a4aae4
{LIST}			store_word(); return SCAN_LIST;
Packit a4aae4
{SEQUENCE}		store_word(); return SCAN_SEQUENCE;
Packit a4aae4
{STRUCTURE}		store_word(); return SCAN_STRUCTURE;
Packit a4aae4
{GRID}			store_word(); return SCAN_GRID;
Packit a4aae4
{BYTE}			store_word(); return SCAN_BYTE;
Packit a4aae4
{INT16}			store_word(); return SCAN_INT16;
Packit a4aae4
{UINT16}		store_word(); return SCAN_UINT16;
Packit a4aae4
{INT32}			store_word(); return SCAN_INT32;
Packit a4aae4
{UINT32}		store_word(); return SCAN_UINT32;
Packit a4aae4
{FLOAT32}		store_word(); return SCAN_FLOAT32;
Packit a4aae4
{FLOAT64}		store_word(); return SCAN_FLOAT64;
Packit a4aae4
{STRING}		store_word(); return SCAN_STRING;
Packit a4aae4
{URL}			store_word(); return SCAN_URL;
Packit a4aae4
Packit a4aae4
{WORD}      store_word(); return SCAN_WORD;
Packit a4aae4
Packit a4aae4
[ \t\r]+
Packit a4aae4
\n	    	++dds_line_num;
Packit a4aae4
<INITIAL><<EOF>>    yy_init = 1; dds_line_num = 1; yyterminate();
Packit a4aae4
Packit a4aae4
"#"     BEGIN(comment);
Packit a4aae4
<comment>[^\n]*
Packit a4aae4
<comment>\n		++dds_line_num; BEGIN(INITIAL);
Packit a4aae4
<comment><<EOF>>    yy_init = 1; dds_line_num = 1; yyterminate();
Packit a4aae4
Packit a4aae4
"Data:\n"		yyterminate();
Packit a4aae4
"Data:\r\n"		yyterminate();
Packit a4aae4
Packit a4aae4
{NEVER} {
Packit a4aae4
            if (yytext) {	/* suppress msgs about `' chars */
Packit a4aae4
                fprintf(stderr, "Character `%c' is not", *yytext);
Packit a4aae4
                fprintf(stderr, " allowed and has been ignored\n");
Packit a4aae4
	    }
Packit a4aae4
	}
Packit a4aae4
%%
Packit a4aae4
Packit a4aae4
// These three glue routines enable DDS to reclaim the memory used to parse a
Packit a4aae4
// DDS off the wire. They are here because this file can see the YY_*
Packit a4aae4
// symbols; the file DDS.cc cannot.
Packit a4aae4
Packit a4aae4
void *
Packit a4aae4
dds_buffer(FILE *fp)
Packit a4aae4
{
Packit a4aae4
    return (void *)dds_create_buffer(fp, YY_BUF_SIZE);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void
Packit a4aae4
dds_switch_to_buffer(void *buf)
Packit a4aae4
{
Packit a4aae4
    dds_switch_to_buffer((YY_BUFFER_STATE)buf);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void
Packit a4aae4
dds_delete_buffer(void *buf)
Packit a4aae4
{
Packit a4aae4
    dds_delete_buffer((YY_BUFFER_STATE)buf);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
static void
Packit a4aae4
store_word()
Packit a4aae4
{
Packit a4aae4
    // dods2id(string(yytext)).c_str()
Packit a4aae4
    strncpy(ddslval.word, yytext, ID_MAX-1);
Packit a4aae4
    ddslval.word[ID_MAX-1] = '\0'; // for the paranoid...
Packit a4aae4
}
Packit a4aae4