| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
#ifndef APR_SCANNER_H |
| 9 |
#define APR_SCANNER_H |
| 10 |
|
| 11 |
// Flex expects the signature of yylex to be defined in the macro YY_DECL, and |
| 12 |
// the C++ parser expects it to be declared. We can factor both as follows. |
| 13 |
|
| 14 |
#undef YY_DECL |
| 15 |
#define YY_DECL SEAMS::Parser::token_type SEAMS::Scanner::lex(SEAMS::Parser::semantic_type *yylval) |
| 16 |
|
| 17 |
#ifndef __FLEX_LEXER_H |
| 18 |
#define yyFlexLexer SEAMSFlexLexer |
| 19 |
#include "FlexLexer.h" |
| 20 |
#undef yyFlexLexer |
| 21 |
#endif |
| 22 |
|
| 23 |
#include <iostream> |
| 24 |
|
| 25 |
namespace SEAMS { |
| 26 |
|
| 27 |
/** Scanner is a derived class to add some extra function to the scanner |
| 28 |
* class. Flex itself creates a class named yyFlexLexer, which is renamed using |
| 29 |
* macros to SEAMSFlexLexer. However we change the context of the generated |
| 30 |
* yylex() function to be contained within the Scanner class. This is required |
| 31 |
* because the yylex() defined in SEAMSFlexLexer has no parameters. */ |
| 32 |
class Aprepro; |
| 33 |
class Scanner : public SEAMSFlexLexer |
| 34 |
{ |
| 35 |
public: |
| 36 |
friend class Parser; |
| 37 |
|
| 38 |
/** Create a new scanner object. The streams arg_yyin and arg_yyout default |
| 39 |
* to cin and cout, but that assignment is only made when initializing in |
| 40 |
* yylex(). */ |
| 41 |
explicit Scanner(Aprepro &aprepro_yyarg, std::istream *in = nullptr, |
| 42 |
std::ostream *out = nullptr); |
| 43 |
/** Required for virtual functions */ |
| 44 |
~Scanner() override; |
| 45 |
|
| 46 |
bool add_include_file(const std::string &filename, bool must_exist); |
| 47 |
int yywrap() override; |
| 48 |
void yyerror(const char *s); |
| 49 |
void LexerOutput(const char *buf, int size) override; |
| 50 |
int LexerInput(char *buf, int max_size) override; |
| 51 |
|
| 52 |
/** This is the main lexing function. It is generated by flex according to |
| 53 |
* the macro declaration YY_DECL above. The generated bison parser then |
| 54 |
* calls this virtual function to fetch new tokens. */ |
| 55 |
virtual Parser::token_type lex(Parser::semantic_type *yylval); |
| 56 |
|
| 57 |
char *rescan(char *string); |
| 58 |
char *execute(char *string); |
| 59 |
char *import_handler(char *string); |
| 60 |
char *if_handler(double x); |
| 61 |
char *elseif_handler(double x); |
| 62 |
char *switch_handler(double x); |
| 63 |
char *case_handler(double x); |
| 64 |
|
| 65 |
/** Enable debug output (via arg_yyout) if compiled into the scanner. */ |
| 66 |
void set_debug(bool b); |
| 67 |
|
| 68 |
/* User arguments. */ |
| 69 |
class Aprepro &aprepro; |
| 70 |
|
| 71 |
/* save the original string for substitution history */ |
| 72 |
void save_history_string(); |
| 73 |
}; |
| 74 |
|
| 75 |
} // namespace SEAMS |
| 76 |
|
| 77 |
#endif // APR_SCANNER_H |