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

#ifndef TurtleSScanner_H
#define TurtleSScanner_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::TurtleSParser::token_type				\
    w3c_sw::TurtleSScanner::lex(				\
	w3c_sw::TurtleSParser::semantic_type* yylval,		\
	w3c_sw::TurtleSParser::location_type* yylloc		\
    )
#endif

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

#include "TurtleSParser.hpp"

namespace w3c_sw {

/** TurtleSScanner 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 TurtleSFlexLexer. However we change the context of the generated
 * yylex() function to be contained within the TurtleSScanner class. This is required
 * because the yylex() defined in TurtleSFlexLexer has no parameters. */
class TurtleSScanner : public TurtleSFlexLexer
{
private:
    TurtleSDriver* 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(). */
    TurtleSScanner(TurtleSDriver* driver, std::istream* arg_yyin = 0,
	    std::ostream* arg_yyout = 0);

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

    /** 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 TurtleSParser::token_type lex(
	TurtleSParser::semantic_type* yylval,
	TurtleSParser::location_type* yylloc
	);

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

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

} // namespace w3c_sw

#endif // TurtleSScanner_H
