yast2-core
|
Scanner for scanning YCP syntax. More...
#include <Scanner.h>
Public Member Functions | |
Scanner (FILE *inputfile, const char *filename) | |
Scanner (const char *inputbuffer) | |
Scanner (int input_fd, const char *filename) | |
~Scanner () | |
void | setBuffered () |
void | initTables (SymbolTable *globalTable, SymbolTable *localTable) |
SymbolTable * | globalTable () const |
SymbolTable * | localTable () const |
int | yylex () |
int | LexerInput (char *buf, int max_size) |
void | LexerError (const char *msg) |
tokenValue | scannedValue () const |
constTypePtr | scannedType () const |
std::string | commentBefore () const |
int | lineNumber () const |
string | filename () const |
void | logError (const char *loginfo, int lineno,...) __attribute__((format(printf |
void void | logWarning (const char *loginfo, int lineno,...) __attribute__((format(printf |
void void const std::list< std::pair< std::string, Y2Namespace * > > & | autoimport_predefined () const |
void | closeInput () |
virtual void | error (string error) |
virtual void | warning (string warning) |
![]() | |
virtual | ~Logger () |
Static Public Member Functions | |
static char * | doStrdup (const char *s) |
Private Member Functions | |
void | setScannedToken (const tokenValue &value, constTypePtr type) |
void | setCommentBefore (const string &comment_before) |
char * | extend_scanbuffer (int size) |
Private Attributes | |
string | m_filename |
const char * | m_inputBuffer |
FILE * | m_inputFile |
int | m_inputFd |
tokenValue | m_scannedValue |
constTypePtr | m_scannedType |
std::string | m_commentBefore |
int | m_lineNumber |
char * | m_scandataBufferPtr |
char * | m_scandataBuffer |
int | m_scandataBufferSize |
bool | m_buffered |
SymbolTable * | m_globalTable |
SymbolTable * | m_localTable |
bool | m_owningGlobal |
bool | m_owningLocal |
std::list< std::pair< std::string, Y2Namespace * > > | m_autoimport_predefined |
Static Private Attributes | |
static const int | STRING_HUNK = 1024 |
Scanner for scanning YCP syntax.
Scanner::Scanner | ( | FILE * | inputfile, |
const char * | filename | ||
) |
Creates a new scanner that scans from an open clib-level file descriptor that has been opened with fopen(filename, "r"). You have to close the file yourself afterwards.
inputfile | the open file |
filename | If you have the name of the file in hand here, tell it, it makes nicer error messages. Give 0 otherwise. |
References m_scannedValue, StaticDeclaration::symbolTable(), tokenValue::val, and y2debug.
Scanner::Scanner | ( | const char * | inputbuffer | ) |
Creates a new scanner that scans from a zero terminated constant C string. Your buffer is left untouched. We don't make a copy of it, so ist must be valid all the time this class is used.
inputbuffer | Pointer to the string. |
References m_scannedValue, StaticDeclaration::symbolTable(), tokenValue::val, and y2debug.
Scanner::Scanner | ( | int | input_fd, |
const char * | filename | ||
) |
Creates a new scanner that scans from an open unix lowlevel file descriptor. You have to close the descriptor yourself afterwards
input_fd | the file descriptor |
filename | If you have the name of the file in hand here, tell it, it makes nicer error messages. Give 0 otherwise. |
References m_scannedValue, tokenValue::sval, StaticDeclaration::symbolTable(), and y2debug.
Scanner::~Scanner | ( | ) |
Cleans up
References m_globalTable, m_localTable, m_owningGlobal, m_owningLocal, and m_scandataBuffer.
|
inline |
get list of predefined namespaces which have been autoloaded by the scanner
References formalparamstack::type.
void Scanner::closeInput | ( | ) |
References m_inputFd, and m_inputFile.
Referenced by yylex().
std::string Scanner::commentBefore | ( | ) | const |
References m_commentBefore.
Referenced by yylex().
|
static |
|
virtual |
Implements Logger.
References logError(), and m_lineNumber.
|
private |
Internal helper function that deals with strings of arbitrary length
References m_scandataBuffer, m_scandataBufferSize, STRING_HUNK, and y2error.
string Scanner::filename | ( | void | ) | const |
Gets the currently scanned file
References m_filename.
Referenced by logError(), logWarning(), parsefile(), and start_block().
SymbolTable * Scanner::globalTable | ( | ) | const |
return current globalTable. used by parser.
References m_globalTable.
Referenced by initTables(), and switch().
void Scanner::initTables | ( | SymbolTable * | globalTable, |
SymbolTable * | localTable | ||
) |
Initialize tables for global and local symbols.
If gTable and lTable are set, they're used instead of local ones. This is used for include files using the symbol tables of the including block. see: Parser::parse()
References globalTable(), localTable(), m_globalTable, m_localTable, m_owningGlobal, m_owningLocal, and y2debug.
Referenced by Parser::parse().
void Scanner::LexerError | ( | const char * | msg | ) |
Is called by the flex lexer, if a scan error occurs. Calls logError.
References logError().
int Scanner::LexerInput | ( | char * | buf, |
int | max_size | ||
) |
Overriden from yyFlexLexer. The flex scanner uses this function to get the next input characters. Our implementation always returns just one character. Too much lookahead would result in blocking and deadlock in a protocol situation. FIXME: when reading from file read max_size characters
buf | Buffer where the input is to be stored in |
max_size | size of this buffer |
References m_buffered, m_inputBuffer, m_inputFd, m_inputFile, and y2internal.
int Scanner::lineNumber | ( | ) | const |
Gets the line number of the latest scanned token.
References m_lineNumber.
Referenced by parsefile(), and yylex().
SymbolTable * Scanner::localTable | ( | ) | const |
return current localTable. used by parser.
References m_localTable.
Referenced by attach_parameter(), initTables(), and switch().
void Scanner::logError | ( | const char * | loginfo, |
int | lineno, | ||
... | |||
) |
Is called by LexerError. Is also called by yyerror for error reporting. It reports the error via y2log and also reports the filename, if available and the linenumber.
msg | the plain error message |
References filename(), m_filename, and syn2error.
Referenced by error(), LexerError(), yyerror_assign_const(), yyerror_cant_cast(), yyerror_no_module(), yyerror_type_mismatch(), yyerror_with_code(), yyerror_with_file(), yyerror_with_lineinfo(), yyerror_with_name(), and yyerror_with_tableentry().
void Scanner::logWarning | ( | const char * | loginfo, |
int | lineno, | ||
... | |||
) |
logs a warning.
References filename(), m_filename, and syn2warning.
Referenced by warning(), yywarning_with_lineinfo(), and yywarning_with_tableentry().
constTypePtr Scanner::scannedType | ( | ) | const |
Gets the value of the latest scanned token. Returns 0, if that token does not represent a proper value.
References m_scannedType.
Referenced by yylex().
tokenValue Scanner::scannedValue | ( | ) | const |
Gets the value of the latest scanned token. Returns 0, if that token does not represent a proper value.
References m_scannedValue.
Referenced by yylex().
void Scanner::setBuffered | ( | ) |
Makes the scanner use buffering, i.e. read more than one character at once.
References m_buffered.
Referenced by Parser::setBuffered(), and Parser::setInput().
|
private |
References m_commentBefore.
|
private |
Used in the rules of the scanner to define the value of a token.
References m_scannedType, and m_scannedValue.
|
virtual |
Implements Logger.
References logWarning(), and m_lineNumber.
int Scanner::yylex | ( | ) |
Scans and returns the next token. Return 0, in case of EOF. The value of the scanned token is saved in #scanned_value and can be retrieved with scannedValue. The implementation of this function is generated by flex++.
Referenced by parsefile(), and yylex().
|
private |
list of predefined namespace which have been auto-imported Y2Namespace is non-const since the block might get evaluated (constructor)
|
private |
Is true, if the input can be buffered, i.e. more than one character may be read at once in order to gain performance.
Referenced by LexerInput(), and setBuffered().
|
private |
Holds the comment before the most recent token
Referenced by commentBefore(), and setCommentBefore().
|
private |
The name of the file being parsed. It is used for generating nice error messages only. It is the empty string, if no filename is available (e.g. while scanning from stdin).
Referenced by filename(), logError(), and logWarning().
|
private |
Referenced by globalTable(), initTables(), and ~Scanner().
|
private |
If the YCP text source is given in form of a string buffer, this buffer is stored here. 0 otherwise.
Referenced by LexerInput().
|
private |
If the YCP text source is given in form of a unix lowlevel file descriptor, this variable holds the descriptor. Must be -1 otherwise, since 0 is a valid file descriptor (stdin).
Referenced by closeInput(), and LexerInput().
|
private |
If the YCP text source is given in form of an open clib-level file pointer, this variable hold it. Must be 0 otherwise.
Referenced by closeInput(), and LexerInput().
|
private |
Holds the line number of scanned_value
Referenced by error(), lineNumber(), and warning().
|
private |
Referenced by initTables(), localTable(), and ~Scanner().
|
private |
This is a kludge rather than proper memory management. Klaus, who owns the tables in various cases?
Referenced by initTables(), and ~Scanner().
|
private |
Referenced by initTables(), and ~Scanner().
|
private |
Used for string constant scanning
Referenced by extend_scanbuffer(), and ~Scanner().
|
private |
Used for string constant scanning
|
private |
Used for string constant scanning
Referenced by extend_scanbuffer().
|
private |
Holds the type of the value being scanned lastly.
Referenced by scannedType(), and setScannedToken().
|
private |
Holds the value being scanned lastly.
Referenced by scannedValue(), Scanner(), and setScannedToken().
|
staticprivate |
Allocate this many bytes for a string. If a larger string is encountered, the buffer size is at least doubled. I don't believe, that the value of STRING_HUNK has a great impact on speed. 1024 is probably a nice value for it.
Referenced by extend_scanbuffer().