Cadabra
Computer algebra system for field theory problems
Parser.hh
Go to the documentation of this file.
1 /*
2 
3 Cadabra: a field-theory motivated computer algebra system.
4 Copyright (C) 2001-2014 Kasper Peeters <kasper.peeters@phi-sci.com>
5 
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation, either version 3 of the
9 License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #pragma once
22 
23 #include <string>
24 #include <vector>
25 #include <iostream>
26 
27 #include "Storage.hh"
28 
29 namespace cadabra {
30 
37 
38  class Parser {
39  public:
40  Parser();
41  Parser(std::shared_ptr<Ex>);
42  Parser(std::shared_ptr<Ex>, const std::string&);
43 
44  void erase();
45 
46  void remove_empty_nodes();
47 
51  void finalise();
52  bool string2tree(const std::string& inp);
53 
54  std::shared_ptr<Ex> tree;
55  private:
56  Ex::iterator parts;
57  std::u32string str;
58 
62  };
63 
64  void advance(unsigned int& i);
65  char32_t get_token(unsigned int i);
66  bool is_number(const std::u32string& str) const;
67  str_node::bracket_t is_closing_bracket(const char32_t& br) const;
68  str_node::bracket_t is_opening_bracket(const char32_t& br) const;
69  str_node::parent_rel_t is_link(const char32_t& ln) const;
70 
71  std::vector<mode_t> current_mode;
72  std::vector<str_node::bracket_t> current_bracket;
73  std::vector<str_node::parent_rel_t> current_parent_rel;
74  };
75 
76  }
77 
78 std::istream& operator>>(std::istream&, cadabra::Parser&);
79 
80 
81 //std::ostream& operator<<(std::ostream&, Parser&);
std::istream & operator>>(std::istream &, cadabra::Parser &)
Definition: Parser.cc:32
Class which turns the string output of a preprocessor object and turns it into an Ex expression tree.
Definition: Parser.hh:38
Parser()
Definition: Parser.cc:92
void advance(unsigned int &i)
Definition: Parser.cc:150
char32_t get_token(unsigned int i)
Definition: Parser.cc:156
std::shared_ptr< Ex > tree
Definition: Parser.hh:54
void remove_empty_nodes()
Definition: Parser.cc:128
bool is_number(const std::u32string &str) const
Definition: Parser.cc:423
void erase()
Definition: Parser.cc:117
std::vector< str_node::bracket_t > current_bracket
Definition: Parser.hh:72
std::u32string str
Definition: Parser.hh:57
Ex::iterator parts
Definition: Parser.hh:56
void finalise()
Finalise the parsed expression.
Definition: Parser.cc:140
std::vector< mode_t > current_mode
Definition: Parser.hh:71
bool string2tree(const std::string &inp)
Definition: Parser.cc:164
str_node::bracket_t is_closing_bracket(const char32_t &br) const
Definition: Parser.cc:63
std::vector< str_node::parent_rel_t > current_parent_rel
Definition: Parser.hh:73
str_node::parent_rel_t is_link(const char32_t &ln) const
Definition: Parser.cc:83
str_node::bracket_t is_opening_bracket(const char32_t &br) const
Definition: Parser.cc:73
mode_t
Definition: Parser.hh:59
@ m_initialgroup
Definition: Parser.hh:61
@ m_property
Definition: Parser.hh:61
@ m_name
Definition: Parser.hh:59
@ m_verbatim
Definition: Parser.hh:61
@ m_childgroup
Definition: Parser.hh:61
@ m_findchildren
Definition: Parser.hh:59
@ m_backslashname
Definition: Parser.hh:60
@ m_skipwhite
Definition: Parser.hh:59
@ m_singlecharname
Definition: Parser.hh:60
bracket_t
Definition: Storage.hh:58
parent_rel_t
Child nodes are related to their parent node by a so-called parent relation, which can be one of thes...
Definition: Storage.hh:62
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83