// $Id: SPARQLfedScanner.hpp,v 1.3 2008/10/03 07:06:02 eric Exp $

#ifndef SPARQLfedScanner_H
#define SPARQLfedScanner_H

// Flex expects the signature of yylex to be defined in the macro YY_DECL, and
// the C++ parser expects it to be declared. We can factor both as follows.

#ifndef YY_DECL

#define	YY_DECL						\
    w3c_sw::SPARQLfedParser::token_type				\
    w3c_sw::SPARQLfedScanner::lex(				\
	w3c_sw::SPARQLfedParser::semantic_type* yylval,		\
	w3c_sw::SPARQLfedParser::location_type* yylloc		\
    )
#endif

#ifndef __FLEX_LEXER_H
#define yyFlexLexer SPARQLfedFlexLexer
#include "FlexLexer.h"
#undef yyFlexLexer
#endif

#include "SPARQLfedParser.hpp"

namespace w3c_sw {

/** SPARQLfedScanner is a derived class to add some extra function to the scanner
 * class. Flex itself creates a class named yyFlexLexer, which is renamed using
 * macros to SPARQLfedFlexLexer. However we change the context of the generated
 * yylex() function to be contained within the SPARQLfedScanner class. This is required
 * because the yylex() defined in SPARQLfedFlexLexer has no parameters. */
class SPARQLfedScanner : public SPARQLfedFlexLexer
{
private:
    SPARQLfedDriver* driver;
public:
    /** Create a new scanner object. The streams arg_yyin and arg_yyout default
     * to cin and cout, but that assignment is only made when initializing in
     * yylex(). */
    SPARQLfedScanner(SPARQLfedDriver* driver, std::istream* arg_yyin = 0,
	    std::ostream* arg_yyout = 0);

    /** Required for virtual functions */
    virtual ~SPARQLfedScanner();

    /** This is the main lexing function. It is generated by flex according to
     * the macro declaration YY_DECL above. The generated bison parser then
     * calls this virtual function to fetch new tokens. */
    virtual SPARQLfedParser::token_type lex(
	SPARQLfedParser::semantic_type* yylval,
	SPARQLfedParser::location_type* yylloc
	);

    /** Enable debug output (via arg_yyout) if compiled into the scanner. */
    void set_debug(bool b);

    SPARQLfedParser::token_type typedLiteral(SPARQLfedParser::semantic_type*&, SPARQLfedParser::token_type tok);
    SPARQLfedParser::token_type unescape(SPARQLfedParser::semantic_type*&, size_t skip, SPARQLfedParser::token_type tok);
    URI* resolvePrefix(const char*);
    URI* resolveBase(const char*, bool stripDelims);
};

} // namespace w3c_sw

#endif // SPARQLfedScanner_H
