BioInfWeb - TreeGraph / Version 1 / Show File - tgf-parser.h

TreeGraph subversion repository

sventon subversion web client - http://www.sventon.org
[show recent changes]
 
  Help
Rev: HEAD (2) - https://secure.bioinfweb.info/Code/svn/TreeGraph / trunk / main / tgf-parser.h
Show File - tgf-parser.h  [show properties]
spinner
/*
 tgf-parser.h, part of
 treegraph
 Tree formatting program
 Generates vector graphics (SVG,EPS) from .tgf-tree description files.
10   Copyright (c) 2003-04 by Joern Mueller
11 
12 
13   This program is free software; you can redistribute it and/or
14   modify it under the terms of the GNU General Public License
15   as published by the Free Software Foundation; either version 2
16   of the License, or (at your option) any later version.
17 
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21   GNU General Public License for more details.
22 
23   You should have received a copy of the GNU General Public License
24   along with this program (GPL.html); if not, write to the Free Software
25   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26   (also: http://www.gnu.org)
27  */
28 
29 
30 
31 
32 
33 
34 
35  #ifndef __TGF_PARSER_H__
36  #define __TGF_PARSER_H__
37 
38  #include <string>
39  #include <iostream>
40  #include <vector>
41 
42  class macro
43  {
44  public:
45   std::string mname;
46   std::string makro;
47   int nargs;
48  };
49 
50 
51  class parser
52  {
53   long line;
54   std::istream& strom;
55   char *buf;
56   long bfsize;
57   long bfresv;
58   std::string echo;
59   bool echoing;
60   std::vector<macro> defs;
61 
62   int find_macro(const std::string& s);
63   void insert_macro(const macro& m);
64 
65  public:
66   parser(std::istream& s1);
67   ~parser();
68 
69 
70  enum ttoken
71  {
72   kInit=0,
73   kOpenTree,
74   kCloseTree,
75   kNextTree,
76   kText, // "...Text.." wird zu U1 oder R
77   kTextU1,//\u1{...}
78   kTextU2,
79   kTextU3,
80   kTextU4,
81   kTextD1,//\d1{...}
82   kTextD2,
83   kTextD3,
84   kTextD4,
85   kTextR, //\r{...}
86   kLength, // \len{<float>}
87   kLabel, //\label{<name>}
88   kPruned, //\prune{<ersatztext>}
89   kMinLength,//\min_length{<float>}
90   kSpaceAbove,//\space_above{<float>}
91   kSpaceBelow,// \space_below{<float>}
92   kEOF,
93   kErr
94  };
95 
96   long curline(void) const {return line;}
97   bool eof(void) const {return bfsize==0 && strom.eof();}
98   bool good(void) const {return strom.good();}
99 
100   bool expand(const std::string&); //ggf. Makro expandieren
101 
102   int get(void) {
103    if(bfsize<=0){
104     int ch=strom.get();
105     if(ch==EOF) return EOF;
106     if(echoing) echo+=ch;
107     return static_cast<char>(ch);
108    }
109    return buf[--bfsize];
110   }
111   void unget(char ch);
112   void unget(const std::string& s);
113 
114   float readbracefloat(void);
115   void readbracestring(std::string&);
116   void readcommand(std::string& cmd);
117   void skipcomment(void);
118   bool skipbracestring(void);
119   void skipspaces(void);
120   void readdefinition(void);
121   ttoken readnextword(std::string&, float&);
122 
123   void startecho(void){echoing=true; echo="";}
124   void stopecho(void){echoing=false;}
125   void readecho(std::string& s)const{s=echo;}
126  };
127 
128  class syntax {
129  public:
130   syntax(long a){std::cout << "Error in line Nr."<< a << ".\n";}
131  };
132 
133 
134  const float millimeter=2.8346457;
135 
136 
137  #endif /* __TGF_PARSER_H__ */


feed icon

sventon 2.5.1

Valid XHTML 1.0 Strict   CSS ist valide!
TreeGraph icon
bioinfweb RSS feed TreeGraph 2 on ResearchGate bioinfweb on twitter TreeGraph 2 on GitHub
bioinfweb - Biology & Informatics Website