simple_parser.hh

00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2008, 2009 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_SIMPLE_PARSER_HH
00021 #define PALUDIS_GUARD_PALUDIS_UTIL_SIMPLE_PARSER_HH 1
00022 
00023 #include <paludis/util/attributes.hh>
00024 #include <paludis/util/private_implementation_pattern.hh>
00025 #include <paludis/util/simple_parser-fwd.hh>
00026 #include <tr1/functional>
00027 #include <string>
00028 
00029 namespace paludis
00030 {
00031     namespace simple_parser
00032     {
00033         typedef std::tr1::function<std::string::size_type (const std::string &, const std::string::size_type)> SimpleParserMatchFunction;
00034 
00035         class PALUDIS_VISIBLE SimpleParserExpression
00036         {
00037             private:
00038                 const SimpleParserMatchFunction _match;
00039 
00040             public:
00041                 SimpleParserExpression(const SimpleParserMatchFunction &);
00042 
00043                 std::string::size_type match(const std::string &, const std::string::size_type) const
00044                     PALUDIS_ATTRIBUTE((warn_unused_result));
00045         };
00046 
00047         SimpleParserExpression operator& (const SimpleParserExpression &, const SimpleParserExpression &)
00048             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00049 
00050         SimpleParserExpression operator>> (const SimpleParserExpression &, std::string &)
00051             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00052 
00053         SimpleParserExpression operator* (const SimpleParserExpression &)
00054             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00055 
00056         SimpleParserExpression operator+ (const SimpleParserExpression &)
00057             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00058 
00059         SimpleParserExpression operator- (const SimpleParserExpression &)
00060             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00061 
00062         SimpleParserExpression exact(const std::string &)
00063             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00064 
00065         SimpleParserExpression exact_ignoring_case(const std::string &)
00066             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00067 
00068         SimpleParserExpression any_of(const std::string &)
00069             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00070 
00071         SimpleParserExpression any_except(const std::string &)
00072             PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
00073     }
00074 
00075     class PALUDIS_VISIBLE SimpleParser :
00076         private PrivateImplementationPattern<SimpleParser>
00077     {
00078         public:
00079             SimpleParser(const std::string &);
00080             ~SimpleParser();
00081 
00082             bool consume(const simple_parser::SimpleParserExpression &) PALUDIS_ATTRIBUTE((warn_unused_result));
00083             bool lookahead(const simple_parser::SimpleParserExpression &) const PALUDIS_ATTRIBUTE((warn_unused_result));
00084             bool eof() const PALUDIS_ATTRIBUTE((warn_unused_result));
00085 
00086             std::string::size_type offset() const PALUDIS_ATTRIBUTE((warn_unused_result));
00087             unsigned current_line_number() const PALUDIS_ATTRIBUTE((warn_unused_result));
00088             const std::string text() const PALUDIS_ATTRIBUTE((warn_unused_result));
00089     };
00090 
00091 #ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
00092     extern template struct PrivateImplementationPattern<SimpleParser>;
00093 #endif
00094 }
00095 
00096 #endif

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4