2005-05-28 00:45:31 +02:00
|
|
|
/*
|
|
|
|
*
|
1.- Style.
2.- Cleanup.
3.- Fix what I assume may cause astray behavior. Only an inept could create an enumeration in Lex.h like this
enum TokenType {
END_OF_STREAM,
PUNCT,
NAME,
to be used in the data member tokenType but at the same time, create preprocessor macros like this
#define WHITE 1
#define PUNCT 2
to be stored and retrieved by
char charTableArray [256]
to calculate the character class (punctuation, spaces, etc) in the Lexer,
where the macro PUNCT (value 2) overrides the enum member PUNCT (value 1) and that inconsistent value is used in both tasks, causing PUNCT to be interpreted as tokenType being NAME (value 2 in the enum). Since this module has several bugs, maybe all the bugs cancel among themselves and all works as expected, but it would be pure luck.
2008-04-29 13:05:11 +02:00
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/idpl.html.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on
|
|
|
|
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
|
|
|
|
* express or implied. See the License for the specific
|
2005-05-28 00:45:31 +02:00
|
|
|
* language governing rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The contents of this file or any work derived from this file
|
1.- Style.
2.- Cleanup.
3.- Fix what I assume may cause astray behavior. Only an inept could create an enumeration in Lex.h like this
enum TokenType {
END_OF_STREAM,
PUNCT,
NAME,
to be used in the data member tokenType but at the same time, create preprocessor macros like this
#define WHITE 1
#define PUNCT 2
to be stored and retrieved by
char charTableArray [256]
to calculate the character class (punctuation, spaces, etc) in the Lexer,
where the macro PUNCT (value 2) overrides the enum member PUNCT (value 1) and that inconsistent value is used in both tasks, causing PUNCT to be interpreted as tokenType being NAME (value 2 in the enum). Since this module has several bugs, maybe all the bugs cancel among themselves and all works as expected, but it would be pure luck.
2008-04-29 13:05:11 +02:00
|
|
|
* may not be distributed under any other license whatsoever
|
|
|
|
* without the express prior written permission of the original
|
2005-05-28 00:45:31 +02:00
|
|
|
* author.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The Original Code was created by James A. Starkey for IBPhoenix.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997 - 2000, 2001, 2003 James A. Starkey
|
|
|
|
* Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Lex.h: interface for the Lex class.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if !defined(AFX_LEX_H__89737590_2C93_4F77_99AD_4C3881906C96__INCLUDED_)
|
|
|
|
#define AFX_LEX_H__89737590_2C93_4F77_99AD_4C3881906C96__INCLUDED_
|
|
|
|
|
2005-06-21 12:26:56 +02:00
|
|
|
#if defined _MSC_VER && _MSC_VER >= 1000
|
2005-05-28 00:45:31 +02:00
|
|
|
#pragma once
|
|
|
|
#endif // _MSC_VER > 1000
|
|
|
|
|
|
|
|
#include "Stream.h"
|
2008-04-24 17:49:43 +02:00
|
|
|
#include "../common/classes/alloc.h"
|
2005-05-28 00:45:31 +02:00
|
|
|
|
|
|
|
START_NAMESPACE
|
|
|
|
|
|
|
|
class InputStream;
|
|
|
|
class InputFile;
|
|
|
|
class Stream;
|
|
|
|
|
2008-04-24 17:49:43 +02:00
|
|
|
class Lex : public Firebird::GlobalStorage
|
2005-05-28 00:45:31 +02:00
|
|
|
{
|
|
|
|
public:
|
1.- Style.
2.- Cleanup.
3.- Fix what I assume may cause astray behavior. Only an inept could create an enumeration in Lex.h like this
enum TokenType {
END_OF_STREAM,
PUNCT,
NAME,
to be used in the data member tokenType but at the same time, create preprocessor macros like this
#define WHITE 1
#define PUNCT 2
to be stored and retrieved by
char charTableArray [256]
to calculate the character class (punctuation, spaces, etc) in the Lexer,
where the macro PUNCT (value 2) overrides the enum member PUNCT (value 1) and that inconsistent value is used in both tasks, causing PUNCT to be interpreted as tokenType being NAME (value 2 in the enum). Since this module has several bugs, maybe all the bugs cancel among themselves and all works as expected, but it would be pure luck.
2008-04-29 13:05:11 +02:00
|
|
|
enum LEX_flags { LEX_none = 0, LEX_trace = 1, LEX_list = 2, /* LEX_verbose = 4, */ LEX_upcase = 8 };
|
|
|
|
|
|
|
|
enum TokenType
|
|
|
|
{
|
|
|
|
END_OF_STREAM,
|
|
|
|
TT_PUNCT,
|
|
|
|
TT_NAME,
|
|
|
|
//QUOTED_NAME,
|
|
|
|
TT_NUMBER,
|
|
|
|
//TT_END,
|
|
|
|
QUOTED_STRING,
|
|
|
|
SINGLE_QUOTED_STRING,
|
|
|
|
//DECIMAL_NUMBER,
|
|
|
|
//IP_ADDRESS,
|
|
|
|
TT_NONE
|
|
|
|
};
|
2008-12-05 01:56:15 +01:00
|
|
|
|
1.- Style.
2.- Cleanup.
3.- Fix what I assume may cause astray behavior. Only an inept could create an enumeration in Lex.h like this
enum TokenType {
END_OF_STREAM,
PUNCT,
NAME,
to be used in the data member tokenType but at the same time, create preprocessor macros like this
#define WHITE 1
#define PUNCT 2
to be stored and retrieved by
char charTableArray [256]
to calculate the character class (punctuation, spaces, etc) in the Lexer,
where the macro PUNCT (value 2) overrides the enum member PUNCT (value 1) and that inconsistent value is used in both tasks, causing PUNCT to be interpreted as tokenType being NAME (value 2 in the enum). Since this module has several bugs, maybe all the bugs cancel among themselves and all works as expected, but it would be pure luck.
2008-04-29 13:05:11 +02:00
|
|
|
Lex(const char* punctuation, const LEX_flags debugFlags);
|
|
|
|
virtual ~Lex();
|
|
|
|
|
2005-05-28 00:45:31 +02:00
|
|
|
void captureStuff();
|
1.- Style.
2.- Cleanup.
3.- Fix what I assume may cause astray behavior. Only an inept could create an enumeration in Lex.h like this
enum TokenType {
END_OF_STREAM,
PUNCT,
NAME,
to be used in the data member tokenType but at the same time, create preprocessor macros like this
#define WHITE 1
#define PUNCT 2
to be stored and retrieved by
char charTableArray [256]
to calculate the character class (punctuation, spaces, etc) in the Lexer,
where the macro PUNCT (value 2) overrides the enum member PUNCT (value 1) and that inconsistent value is used in both tasks, causing PUNCT to be interpreted as tokenType being NAME (value 2 in the enum). Since this module has several bugs, maybe all the bugs cancel among themselves and all works as expected, but it would be pure luck.
2008-04-29 13:05:11 +02:00
|
|
|
int& charTable(int ch);
|
2005-05-28 00:45:31 +02:00
|
|
|
bool getSegment();
|
|
|
|
void pushStream (InputStream *stream);
|
|
|
|
void setContinuationChar (char c);
|
|
|
|
virtual void syntaxError (const char* expected);
|
2008-04-24 17:49:43 +02:00
|
|
|
Firebird::string getName();
|
|
|
|
Firebird::PathName reparseFilename();
|
2005-05-28 00:45:31 +02:00
|
|
|
bool match (const char *word);
|
2006-04-06 10:18:53 +02:00
|
|
|
bool isKeyword (const char *word) const;
|
2005-05-28 00:45:31 +02:00
|
|
|
void setCommentString (const char *start, const char *end);
|
|
|
|
void setLineComment (const char *string);
|
|
|
|
void setCharacters (int type, const char *characters);
|
|
|
|
void getToken();
|
2006-04-06 10:18:53 +02:00
|
|
|
static bool match (const char *pattern, const char *string);
|
2005-05-28 00:45:31 +02:00
|
|
|
void skipWhite();
|
2008-04-20 12:40:58 +02:00
|
|
|
protected:
|
1.- Style.
2.- Cleanup.
3.- Fix what I assume may cause astray behavior. Only an inept could create an enumeration in Lex.h like this
enum TokenType {
END_OF_STREAM,
PUNCT,
NAME,
to be used in the data member tokenType but at the same time, create preprocessor macros like this
#define WHITE 1
#define PUNCT 2
to be stored and retrieved by
char charTableArray [256]
to calculate the character class (punctuation, spaces, etc) in the Lexer,
where the macro PUNCT (value 2) overrides the enum member PUNCT (value 1) and that inconsistent value is used in both tasks, causing PUNCT to be interpreted as tokenType being NAME (value 2 in the enum). Since this module has several bugs, maybe all the bugs cancel among themselves and all works as expected, but it would be pure luck.
2008-04-29 13:05:11 +02:00
|
|
|
LEX_flags flags;
|
|
|
|
TokenType tokenType;
|
|
|
|
int priorLineNumber;
|
|
|
|
bool eol;
|
|
|
|
InputStream* inputStream;
|
|
|
|
InputStream* priorInputStream;
|
2007-04-18 13:55:29 +02:00
|
|
|
private:
|
1.- Style.
2.- Cleanup.
3.- Fix what I assume may cause astray behavior. Only an inept could create an enumeration in Lex.h like this
enum TokenType {
END_OF_STREAM,
PUNCT,
NAME,
to be used in the data member tokenType but at the same time, create preprocessor macros like this
#define WHITE 1
#define PUNCT 2
to be stored and retrieved by
char charTableArray [256]
to calculate the character class (punctuation, spaces, etc) in the Lexer,
where the macro PUNCT (value 2) overrides the enum member PUNCT (value 1) and that inconsistent value is used in both tasks, causing PUNCT to be interpreted as tokenType being NAME (value 2 in the enum). Since this module has several bugs, maybe all the bugs cancel among themselves and all works as expected, but it would be pure luck.
2008-04-29 13:05:11 +02:00
|
|
|
enum { MAXTOKEN = 4096 };
|
|
|
|
InputStream* tokenInputStream;
|
|
|
|
Stream stuff;
|
|
|
|
int tokenOffset;
|
|
|
|
char captureStart;
|
|
|
|
char captureEnd;
|
|
|
|
char token [MAXTOKEN];
|
|
|
|
int lineNumber;
|
|
|
|
int tokenLineNumber;
|
|
|
|
const char* ptr;
|
|
|
|
const char* end;
|
|
|
|
const char* lineComment;
|
|
|
|
const char* commentStart;
|
|
|
|
const char* commentEnd;
|
|
|
|
char continuationChar;
|
|
|
|
int charTableArray [256]; // Don't use directly. Use through charTable.
|
2005-05-28 00:45:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // !defined(AFX_LEX_H__89737590_2C93_4F77_99AD_4C3881906C96__INCLUDED_)
|