Scanner Class Reference

Scanner for scanning YCP syntax. More...

#include <Scanner.h>

Inheritance diagram for Scanner:

Logger List of all members.

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)
SymbolTableglobalTable () const
SymbolTablelocalTable () const
int yylex ()
int LexerInput (char *buf, int max_size)
void LexerError (const char *msg)
tokenValue scannedValue () const
constTypePtr scannedType () 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)

Static Public Member Functions

static char * doStrdup (const char *s)

Private Member Functions

void setScannedToken (const tokenValue &value, constTypePtr type)
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
int m_lineNumber
char * m_scandataBufferPtr
char * m_scandataBuffer
int m_scandataBufferSize
bool m_buffered
SymbolTablem_globalTable
SymbolTablem_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

Detailed Description

Scanner for scanning YCP syntax.

See also:
Parser This class is a filter. You give it a YCP text in form of a string, a FILE *pointer or a unix file descriptor. Out of this it produces a stream of tokens representing the lexical items of the YCP text. This scanner class is based on yyFlexLexer, which is generated by flex++.


Constructor & Destructor Documentation

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.

Parameters:
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.

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.

Parameters:
inputbuffer Pointer to the string.

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

Parameters:
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.

Scanner::~Scanner (  ) 

Cleans up


Member Function Documentation

void Scanner::setBuffered (  ) 

Makes the scanner use buffering, i.e. read more than one character at once.

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()

SymbolTable * Scanner::globalTable (  )  const

return current globalTable. used by parser.

SymbolTable * Scanner::localTable (  )  const

return current localTable. used by parser.

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++.

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

Parameters:
buf Buffer where the input is to be stored in
max_size size of this buffer
Returns:
the number of new input character. 0 on EOF.

void Scanner::LexerError ( const char *  msg  ) 

Is called by the flex lexer, if a scan error occurs. Calls logError.

tokenValue Scanner::scannedValue (  )  const

Gets the value of the latest scanned token. Returns 0, if that token does not represent a proper value.

constTypePtr Scanner::scannedType (  )  const

Gets the value of the latest scanned token. Returns 0, if that token does not represent a proper value.

int Scanner::lineNumber (  )  const

Gets the line number of the latest scanned token.

string Scanner::filename (  )  const

Gets the currently scanned file

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.

Parameters:
msg the plain error message

void Scanner::logWarning ( const char *  loginfo,
int  lineno,
  ... 
)

logs a warning.

void void const std::list<std::pair<std::string, Y2Namespace *> >& Scanner::autoimport_predefined (  )  const [inline]

get list of predefined namespaces which have been autoloaded by the scanner

char * Scanner::doStrdup ( const char *  s  )  [static]

strdup via new, so delete [] can be used safely

void Scanner::closeInput (  ) 

void Scanner::setScannedToken ( const tokenValue value,
constTypePtr  type 
) [private]

Used in the rules of the scanner to define the value of a token.

char * Scanner::extend_scanbuffer ( int  size  )  [private]

Internal helper function that deals with strings of arbitrary length

void Scanner::error ( string  error  )  [virtual]

Implements Logger.

void Scanner::warning ( string  warning  )  [virtual]

Implements Logger.


Member Data Documentation

const int Scanner::STRING_HUNK = 1024 [static, private]

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.

string Scanner::m_filename [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).

const char* Scanner::m_inputBuffer [private]

If the YCP text source is given in form of a string buffer, this buffer is stored here. 0 otherwise.

FILE* Scanner::m_inputFile [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.

int Scanner::m_inputFd [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).

tokenValue Scanner::m_scannedValue [private]

Holds the value being scanned lastly.

constTypePtr Scanner::m_scannedType [private]

Holds the type of the value being scanned lastly.

int Scanner::m_lineNumber [private]

Holds the line number of scanned_value

char* Scanner::m_scandataBufferPtr [private]

Used for string constant scanning

char* Scanner::m_scandataBuffer [private]

Used for string constant scanning

int Scanner::m_scandataBufferSize [private]

Used for string constant scanning

bool Scanner::m_buffered [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.

SymbolTable* Scanner::m_globalTable [private]

SymbolTable* Scanner::m_localTable [private]

bool Scanner::m_owningGlobal [private]

This is a kludge rather than proper memory management. Klaus, who owns the tables in various cases?

bool Scanner::m_owningLocal [private]

std::list<std::pair<std::string, Y2Namespace *> > Scanner::m_autoimport_predefined [private]

list of predefined namespace which have been auto-imported Y2Namespace is non-const since the block might get evaluated (constructor)


The documentation for this class was generated from the following files:
Generated on Tue Nov 6 01:20:22 2007 for yast2-core by  doxygen 1.5.0