File indexing completed on 2024-05-19 15:27:46
0001 /* This file is part of KGraphViewer. 0002 Copyright (C) 2006-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KGraphViewer is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; if not, write to the Free Software 0015 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0016 02110-1301, USA 0017 */ 0018 0019 /* 0020 * Graphviz DOT graph parsing grammar implemented with boost Spirit 0021 */ 0022 0023 #ifndef DOT_GRAMMAR_H 0024 #define DOT_GRAMMAR_H 0025 0026 #include "dotrenderop.h" 0027 0028 #include <boost/spirit/include/classic_core.hpp> 0029 #include <boost/spirit/include/classic_distinct.hpp> 0030 #include <boost/spirit/include/classic_loops.hpp> 0031 #include <boost/throw_exception.hpp> 0032 0033 #include <QColor> 0034 #include <QPair> 0035 #include <QPoint> 0036 #include <QVector> 0037 0038 #include <list> 0039 #include <map> 0040 #include <sstream> 0041 #include <string> 0042 0043 bool parse(const std::string &str); 0044 0045 void gotid(char const *first, char const *last); 0046 void dump(char const *first, char const *last); 0047 void strict(char const *first, char const *last); 0048 void undigraph(char const *first, char const *last); 0049 void digraph(char const *first, char const *last); 0050 void graphid(char const *first, char const *last); 0051 void attrid(char const *first, char const *last); 0052 void subgraphid(char const *first, char const *last); 0053 void valid(char const *first, char const *last); 0054 void addattr(char const *first, char const *last); 0055 void pushAttrListC(char const c); 0056 void popAttrListC(char const c); 0057 void pushAttrList(char const *first, char const *last); 0058 void popAttrList(char const *first, char const *last); 0059 void createsubgraph(char const); 0060 void createnode(char const *first, char const *last); 0061 void setgraphattributes(char const *first, char const *last); 0062 void setsubgraphattributes(char const *first, char const *last); 0063 void setnodeattributes(char const *first, char const *last); 0064 void setattributedlist(char const *first, char const *last); 0065 void checkedgeop(char const *first, char const *last); 0066 void edgebound(char const *first, char const *last); 0067 void createedges(char const *first, char const *last); 0068 void incrz(char const); 0069 void decrz(char const); 0070 void finalactions(char const *first, char const *last); 0071 0072 bool parse_point(char const *str, QPoint &p); 0073 bool parse_real(char const *str, double &d); 0074 bool parse_integers(char const *str, std::vector<int> &v); 0075 bool parse_spline(char const *str, QVector<QPair<float, float>> &points); 0076 void init_op(); 0077 void valid_op(char const *first, char const *last); 0078 bool parse_renderop(const std::string &str, DotRenderOpVec &arenderopvec); 0079 bool parse_numeric_color(char const *str, QColor &c); 0080 0081 struct DotGrammar : public boost::spirit::classic::grammar<DotGrammar> { 0082 template<typename ScannerT> struct definition { 0083 definition(DotGrammar const &self); 0084 0085 boost::spirit::classic::rule<ScannerT> graph, ID, tag, stmt_list, stmt, attr_stmt, attr_list, a_list, edge_stmt, edgeop, edgeRHS, node_stmt, node_id, port, subgraph, compass_pt; 0086 0087 boost::spirit::classic::rule<ScannerT> const &start() const 0088 { 0089 return graph; 0090 } 0091 }; 0092 }; 0093 0094 #endif