/* --------------------------------------------------------------------- * File: check.l * (input file for flex - read check files for Eis/Fair) * * Copyright (C) 2006 * Daniel Vogel, * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * --------------------------------------------------------------------- */ %{ #include "global.h" #include "check.h" #ifndef FALSE #define FALSE 0 #define TRUE !FALSE #endif #ifdef ECHO #undef ECHO #endif #define YY_NO_UNPUT ErrorCallback CheckError = NULL; int CheckCurrentLine; char* CheckInputFile = NULL; %} IDENTIFIER [A-Z][A-Z0-9_%]* OPT_ELEM \+ OPT_ARRAY_ELEM \+\+ REGEXP RE:[^[:space:]]+ NL [\n] HYPHEN [-] SPACE [ ]+ CR [\r] TAB [\t] COMMENT [#] ANYCHAR . %x COMMENT %% {COMMENT} BEGIN(COMMENT); {NL} { CheckCurrentLine++; BEGIN(INITIAL); } {ANYCHAR} /* */ {OPT_ELEM} { return CHECK_OPT_ELEM; } {OPT_ARRAY_ELEM} { return CHECK_OPT_ARRAY_ELEM; } {HYPHEN} { return CHECK_HYPHEN; } {IDENTIFIER} { return CHECK_IDENT; } {REGEXP} { return CHECK_REGEXP; } {NL} { CheckCurrentLine++; return CHECK_NL; } {CR} /* */ {SPACE}|{TAB} /* */ <> { return CHECK_EOF; } {ANYCHAR} { if (CheckError) { CheckError( "Unrecognised input!", CheckInputFile, CheckCurrentLine, FALSE ); } } %% /* ----------------------------------------------------------------------- * CheckFileOpen * Open a file for reading and prepare the scanner * ----------------------------------------------------------------------- */ int CheckFileOpen(const char* filename, ErrorCallback errout) { chkin = fopen(filename, "rt"); if (chkin) { CheckInputFile = strdup(filename); CheckCurrentLine = 1; CheckError = errout; } return chkin != NULL; } /* ----------------------------------------------------------------------- * CheckRead * Read the next token from the file input * ----------------------------------------------------------------------- */ int CheckRead(void) { return yylex(); } /* ----------------------------------------------------------------------- * CheckClose * Close the file input * ----------------------------------------------------------------------- */ void CheckClose() { if (CheckInputFile) { free(CheckInputFile); CheckInputFile = NULL; CheckError = NULL; } fclose(chkin); } /* ----------------------------------------------------------------------- * CheckGetText * Return the text read by the scanner. This can be an idetifier or an * regular expression * ----------------------------------------------------------------------- */ const char* CheckGetText(void) { return chktext; } /* ----------------------------------------------------------------------- * CheckGetFileName * Return the name of the file the scanner is processing * ----------------------------------------------------------------------- */ const char* CheckGetFileName(void) { return CheckInputFile; } /* ----------------------------------------------------------------------- * CheckGetLineNumber * Return the current line number, the scanner input currently is on. * ----------------------------------------------------------------------- */ int CheckGetLineNumber(void) { return CheckCurrentLine; } /* ----------------------------------------------------------------------- * CheckRecoverFromError * Recover from a read error be consuming the rest of the line without * further action * ----------------------------------------------------------------------- */ int CheckRecoverFromError(void) { int sym = CheckRead(); while ((sym != CHECK_NL)&&(sym != CHECK_EOF)) { sym = CheckRead(); } return sym; } /* ----------------------------------------------------------------------- * chkwrap * Is called when the scanner reaches the end of the input stream. * To activate the standard procedure it is necessary to return a value * != 0 * ----------------------------------------------------------------------- */ int chkwrap () { return 1; }