CUBRID Engine  latest
load_scanner.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * load_scanner.hpp - subclass of yyFlexLexer, provides the main scanner function.
21  */
22 
23 #ifndef _LOAD_SCANNER_HPP_
24 #define _LOAD_SCANNER_HPP_
25 
26 #include "load_error_handler.hpp"
27 #include "load_semantic_helper.hpp"
28 #include "load_grammar.hpp"
29 #include "utility.h"
30 
31 #if !defined (yyFlexLexerOnce)
32 #include <FlexLexer.h>
33 #endif
34 #include <istream>
35 
36 namespace cubload
37 {
38 
39  class scanner : public yyFlexLexer
40  {
41  public:
43  : yyFlexLexer ()
44  , m_semantic_helper (semantic_helper)
45  , m_error_handler (error_handler)
46  {
47  //
48  };
49 
50  ~scanner () override = default;
51 
52  void set_lineno (int line_offset)
53  {
54  yylineno = line_offset;
55  }
56 
57  /*
58  * The main scanner function.
59  * See load_lexer.l file for method declaration
60  */
61  virtual int yylex (parser::semantic_type *yylval, parser::location_type *yylloc);
62 
63  /*
64  * Lexer error function
65  * @param msg a description of the lexer error.
66  */
67  void LexerError (const char *msg) override
68  {
69  /*
70  * This approach must be done in order not to fail the whole session during any lexer errors
71  * encountered during parsing of the data file while the --data-check-only argument is enabled.
72  * This method will fail the session in case the lexer is jammed and the --data-check-only argument is not
73  * set, but it will not fail the session is --data-check-only is enabled, and it will just report the line
74  * where the parsing error occured.
75  */
77  m_error_handler.on_syntax_failure (true); // Use scanner line in this case.
78  }
79 
80  private:
83  };
84 
85 } // namespace cubload
86 
87 #endif /* _LOAD_SCANNER_HPP_ */
void on_syntax_failure(bool use_scanner_line=false)
void set_lineno(int line_offset)
~scanner() override=default
error_handler & m_error_handler
scanner(semantic_helper &semantic_helper, error_handler &error_handler)
virtual int yylex(parser::semantic_type *yylval, parser::location_type *yylloc)
semantic_helper & m_semantic_helper
void LexerError(const char *msg) override
void on_error_with_line(MSGCAT_LOADDB_MSG msg_id, Args &&...args)