1 /* A Bison parser, made by GNU Bison 2.7. */ 2 3 /* Skeleton interface for Bison LALR(1) parsers in C++ 4 5 Copyright (C) 2002-2012 Free Software Foundation, Inc. 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 /* As a special exception, you may create a larger work that contains 21 part or all of the Bison parser skeleton and distribute that work 22 under terms of your choice, so long as that work isn't itself a 23 parser generator using the skeleton or a modified version thereof 24 as a parser skeleton. Alternatively, if you modify or redistribute 25 the parser skeleton itself, you may (at your option) remove this 26 special exception, which will cause the skeleton and the resulting 27 Bison output files to be licensed under the GNU General Public 28 License without this special exception. 29 30 This special exception was added by the Free Software Foundation in 31 version 2.2 of Bison. */ 32 33 /** 34 ** \file json_parser.hh 35 ** Define the yy::parser class. 36 */ 37 38 /* C++ LALR(1) parser skeleton written by Akim Demaille. */ 39 40 #ifndef YY_YY_JSON_PARSER_HH_INCLUDED 41 # define YY_YY_JSON_PARSER_HH_INCLUDED 42 43 /* "%code requires" blocks. */ 44 /* Line 33 of lalr1.cc */ 45 #line 26 "json_parser.yy" 46 47 #include "parser_p.h" 48 #include "json_scanner.h" 49 #include "qjson_debug.h" 50 51 #include <QtCore/QByteArray> 52 #include <QtCore/QMap> 53 #include <QtCore/QString> 54 #include <QtCore/QVariant> 55 56 #include <limits> 57 58 class JSonScanner; 59 60 namespace QJson { 61 class Parser; 62 } 63 64 #define YYERROR_VERBOSE 1 65 66 Q_DECLARE_METATYPE(QVector<QVariant>*) 67 Q_DECLARE_METATYPE(QVariantMap*) 68 69 70 /* Line 33 of lalr1.cc */ 71 #line 72 "json_parser.hh" 72 73 74 #include <string> 75 #include <iostream> 76 #include "stack.hh" 77 #include "location.hh" 78 79 /* Enabling traces. */ 80 #ifndef YYDEBUG 81 # define YYDEBUG 1 82 #endif 83 84 85 namespace yy { 86 /* Line 33 of lalr1.cc */ 87 #line 88 "json_parser.hh" 88 89 /// A Bison parser. 90 class json_parser 91 { 92 public: 93 /// Symbol semantic values. 94 #ifndef YYSTYPE 95 typedef int semantic_type; 96 #else 97 typedef YYSTYPE semantic_type; 98 #endif 99 /// Symbol locations. 100 typedef location location_type; 101 /// Tokens. 102 struct token 103 { 104 /* Tokens. */ 105 enum yytokentype { 106 END = 0, 107 CURLY_BRACKET_OPEN = 1, 108 CURLY_BRACKET_CLOSE = 2, 109 SQUARE_BRACKET_OPEN = 3, 110 SQUARE_BRACKET_CLOSE = 4, 111 COLON = 5, 112 COMMA = 6, 113 NUMBER = 7, 114 TRUE_VAL = 8, 115 FALSE_VAL = 9, 116 NULL_VAL = 10, 117 STRING = 11, 118 INVALID = 12 119 }; 120 121 }; 122 /// Token type. 123 typedef token::yytokentype token_type; 124 125 /// Build a parser object. 126 json_parser (QJson::ParserPrivate* driver_yyarg); 127 virtual ~json_parser (); 128 129 /// Parse. 130 /// \returns 0 iff parsing succeeded. 131 virtual int parse (); 132 133 #if YYDEBUG 134 /// The current debugging stream. 135 std::ostream& debug_stream () const; 136 /// Set the current debugging stream. 137 void set_debug_stream (std::ostream &); 138 139 /// Type for debugging levels. 140 typedef int debug_level_type; 141 /// The current debugging level. 142 debug_level_type debug_level () const; 143 /// Set the current debugging level. 144 void set_debug_level (debug_level_type l); 145 #endif 146 147 private: 148 /// Report a syntax error. 149 /// \param loc where the syntax error is found. 150 /// \param msg a description of the syntax error. 151 virtual void error (const location_type& loc, const std::string& msg); 152 153 /// Generate an error message. 154 /// \param state the state where the error occurred. 155 /// \param tok the lookahead token. 156 virtual std::string yysyntax_error_ (int yystate, int tok); 157 158 #if YYDEBUG 159 /// \brief Report a symbol value on the debug stream. 160 /// \param yytype The token type. 161 /// \param yyvaluep Its semantic value. 162 /// \param yylocationp Its location. 163 virtual void yy_symbol_value_print_ (int yytype, 164 const semantic_type* yyvaluep, 165 const location_type* yylocationp); 166 /// \brief Report a symbol on the debug stream. 167 /// \param yytype The token type. 168 /// \param yyvaluep Its semantic value. 169 /// \param yylocationp Its location. 170 virtual void yy_symbol_print_ (int yytype, 171 const semantic_type* yyvaluep, 172 const location_type* yylocationp); 173 #endif 174 175 176 /// State numbers. 177 typedef int state_type; 178 /// State stack type. 179 typedef stack<state_type> state_stack_type; 180 /// Semantic value stack type. 181 typedef stack<semantic_type> semantic_stack_type; 182 /// location stack type. 183 typedef stack<location_type> location_stack_type; 184 185 /// The state stack. 186 state_stack_type yystate_stack_; 187 /// The semantic value stack. 188 semantic_stack_type yysemantic_stack_; 189 /// The location stack. 190 location_stack_type yylocation_stack_; 191 192 /// Whether the given \c yypact_ value indicates a defaulted state. 193 /// \param yyvalue the value to check 194 static bool yy_pact_value_is_default_ (int yyvalue); 195 196 /// Whether the given \c yytable_ value indicates a syntax error. 197 /// \param yyvalue the value to check 198 static bool yy_table_value_is_error_ (int yyvalue); 199 200 /// Internal symbol numbers. 201 typedef unsigned char token_number_type; 202 /* Tables. */ 203 /// For a state, the index in \a yytable_ of its portion. 204 static const signed char yypact_[]; 205 static const signed char yypact_ninf_; 206 207 /// For a state, default reduction number. 208 /// Unless\a yytable_ specifies something else to do. 209 /// Zero means the default is an error. 210 static const unsigned char yydefact_[]; 211 212 static const signed char yypgoto_[]; 213 static const signed char yydefgoto_[]; 214 215 /// What to do in a state. 216 /// \a yytable_[yypact_[s]]: what to do in state \a s. 217 /// - if positive, shift that token. 218 /// - if negative, reduce the rule which number is the opposite. 219 /// - if zero, do what YYDEFACT says. 220 static const unsigned char yytable_[]; 221 static const signed char yytable_ninf_; 222 223 static const signed char yycheck_[]; 224 225 /// For a state, its accessing symbol. 226 static const unsigned char yystos_[]; 227 228 /// For a rule, its LHS. 229 static const unsigned char yyr1_[]; 230 /// For a rule, its RHS length. 231 static const unsigned char yyr2_[]; 232 233 /// Convert the symbol name \a n to a form suitable for a diagnostic. 234 static std::string yytnamerr_ (const char *n); 235 236 237 /// For a symbol, its name in clear. 238 static const char* const yytname_[]; 239 #if YYDEBUG 240 /// A type to store symbol numbers and -1. 241 typedef signed char rhs_number_type; 242 /// A `-1'-separated list of the rules' RHS. 243 static const rhs_number_type yyrhs_[]; 244 /// For each rule, the index of the first RHS symbol in \a yyrhs_. 245 static const unsigned char yyprhs_[]; 246 /// For each rule, its source line number. 247 static const unsigned char yyrline_[]; 248 /// For each scanner token number, its symbol number. 249 static const unsigned short int yytoken_number_[]; 250 /// Report on the debug stream that the rule \a r is going to be reduced. 251 virtual void yy_reduce_print_ (int r); 252 /// Print the state stack on the debug stream. 253 virtual void yystack_print_ (); 254 255 /* Debugging. */ 256 int yydebug_; 257 std::ostream* yycdebug_; 258 #endif 259 260 /// Convert a scanner token number \a t to a symbol number. 261 token_number_type yytranslate_ (int t); 262 263 /// \brief Reclaim the memory associated to a symbol. 264 /// \param yymsg Why this token is reclaimed. 265 /// If null, do not display the symbol, just free it. 266 /// \param yytype The symbol type. 267 /// \param yyvaluep Its semantic value. 268 /// \param yylocationp Its location. 269 inline void yydestruct_ (const char* yymsg, 270 int yytype, 271 semantic_type* yyvaluep, 272 location_type* yylocationp); 273 274 /// Pop \a n symbols the three stacks. 275 inline void yypop_ (unsigned int n = 1); 276 277 /* Constants. */ 278 static const int yyeof_; 279 /* LAST_ -- Last index in TABLE_. */ 280 static const int yylast_; 281 static const int yynnts_; 282 static const int yyempty_; 283 static const int yyfinal_; 284 static const int yyterror_; 285 static const int yyerrcode_; 286 static const int yyntokens_; 287 static const unsigned int yyuser_token_number_max_; 288 static const token_number_type yyundef_token_; 289 290 /* User arguments. */ 291 QJson::ParserPrivate* driver; 292 }; 293 294 } // yy 295 /* Line 33 of lalr1.cc */ 296 #line 297 "json_parser.hh" 297 298 299 300 #endif /* !YY_YY_JSON_PARSER_HH_INCLUDED */ 301