plang_scanner.h
1 // This code is based on http://www.jonathanbeard.io/tutorials/FlexBisonC++
2 
3 #ifndef _PLANG_SCANNER_H
4 #define _PLANG_SCANNER_H
5 
6 #if ! defined(yyFlexLexerOnce)
7 #include <FlexLexer.h>
8 #endif
9 
10 namespace plang {
11 class Scanner;
12 class Driver;
13 }
14 #include "util/plang/plang.h"
15 #include "util/plang/plang_parser.hh"
16 
17 namespace plang {
18 class Scanner : public yyFlexLexer {
19  public:
20  Scanner(std::istream *in) : yyFlexLexer(in) {
21  loc_.reset(new plang::Parser::location_type());
22  }
23 
24  int lex() {
25  Parser::semantic_type lval;
26  Parser::location_type location;
27  return parser_lex(&lval, &location);
28  }
29 
30  int parser_lex( Parser::semantic_type * const lval,
31  Parser::location_type *location);
32 
33  std::string matched() { return yytext; }
34 
35  Parser::location_type *loc() { return &*loc_; }
36 
37  private:
38  std::unique_ptr<plang::Parser::location_type> loc_;
39 };
40 };
41 
42 #endif