| 1 | /* |
| 2 | www.sourceforge.net/projects/tinyxpath |
| 3 | Copyright (c) 2002-2004 Yves Berquin ([email protected]) |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any |
| 7 | damages arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any |
| 10 | purpose, including commercial applications, and to alter it and |
| 11 | redistribute it freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must |
| 14 | not claim that you wrote the original software. If you use this |
| 15 | software in a product, an acknowledgment in the product documentation |
| 16 | would be appreciated but is not required. |
| 17 | |
| 18 | 2. Altered source versions must be plainly marked as such, and |
| 19 | must not be misrepresented as being the original software. |
| 20 | |
| 21 | 3. This notice may not be removed or altered from any source |
| 22 | distribution. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | \file xpath_syntax.h |
| 27 | \author Yves Berquin |
| 28 | XPath Syntax analyzer for TinyXPath project |
| 29 | */ |
| 30 | |
| 31 | #ifndef __TINYSYNTAX_H |
| 32 | #define __TINYSYNTAX_H |
| 33 | |
| 34 | #include <cassert> |
| 35 | #include <cstdio> |
| 36 | #include "tokenlist.h" |
| 37 | |
| 38 | namespace TinyXPath |
| 39 | { |
| 40 | |
| 41 | /// Exception class for a syntax error |
| 42 | class syntax_error |
| 43 | { |
| 44 | public : |
| 45 | syntax_error (const char * cp_mess = NULL) |
| 46 | { |
| 47 | if (cp_mess && strlen (cp_mess) < sizeof (ca_mess) - 1) |
| 48 | strcpy (ca_mess, cp_mess); |
| 49 | else |
| 50 | ca_mess [0] = 0; |
| 51 | } |
| 52 | char ca_mess [200]; |
| 53 | } ; |
| 54 | |
| 55 | /// Exception class for an overflow in syntax decoding |
| 56 | class syntax_overflow {} ; |
| 57 | |
| 58 | /// XPath syntax decoder class. Pure virtual : |
| 59 | /// one need to redefine v_action and i_get_action_counter |
| 60 | class token_syntax_decoder : public token_list |
| 61 | { |
| 62 | protected : |
| 63 | /// Nb of recursions |
| 64 | unsigned u_nb_recurs; |
| 65 | bool o_recognize (xpath_construct xc_current, bool o_final); |
| 66 | public : |
| 67 | token_syntax_decoder () : token_list () {} |
| 68 | virtual ~ token_syntax_decoder () {} |
| 69 | void v_syntax_decode (); |
| 70 | /// Pure virtual : action taken when processing the rule |
| 71 | virtual void v_action (xpath_construct xc_rule, unsigned u_sub, |
| 72 | unsigned u_variable = 0, const char * cp_literal = "") = 0; |
| 73 | virtual int i_get_action_counter () = 0; |
| 74 | } ; |
| 75 | |
| 76 | } |
| 77 | |
| 78 | #endif |