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 
35 
36 
37 
38 namespace cadabra {
39 
40  class Parser {
41  public:
42  Parser();
43  Parser(std::shared_ptr<Ex>);
44  Parser(std::shared_ptr<Ex>, const std::string&);
45 
46  void erase();
47 
48  void remove_empty_nodes();
49 
50  // Finalise the parsed expression. This function should be
51  // called when no further operator>> calls are going to be made,
52  // and is necessary to ensure that the tree is consistent.
53  void finalise();
54  bool string2tree(const std::string& inp);
55 
56  std::shared_ptr<Ex> tree;
57  private:
58  Ex::iterator parts;
59  std::u32string str;
60 
64  };
65 
66  void advance(unsigned int& i);
67  char32_t get_token(unsigned int i);
68  bool is_number(const std::u32string& str) const;
69  str_node::bracket_t is_closing_bracket(const char32_t& br) const;
70  str_node::bracket_t is_opening_bracket(const char32_t& br) const;
71  str_node::parent_rel_t is_link(const char32_t& ln) const;
72 
73  std::vector<mode_t> current_mode;
74  std::vector<str_node::bracket_t> current_bracket;
75  std::vector<str_node::parent_rel_t> current_parent_rel;
76  };
77 
78  }
79 
80 std::istream& operator>>(std::istream&, cadabra::Parser&);
81 
82 
83 //std::ostream& operator<<(std::ostream&, Parser&);
Definition: Parser.hh:63
void finalise()
Definition: Parser.cc:139
Definition: Parser.hh:63
mode_t
Definition: Parser.hh:61
std::vector< str_node::parent_rel_t > current_parent_rel
Definition: Parser.hh:75
Parser()
Definition: Parser.cc:91
str_node::parent_rel_t is_link(const char32_t &ln) const
Definition: Parser.cc:82
Definition: Parser.hh:61
bool string2tree(const std::string &inp)
Definition: Parser.cc:163
Ex::iterator parts
Definition: Parser.hh:58
Definition: Parser.hh:62
std::u32string str
Definition: Parser.hh:59
std::istream & operator>>(std::istream &, cadabra::Parser &)
Definition: Parser.cc:31
Definition: Parser.hh:63
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Algorithm.cc:1045
Definition: Parser.hh:63
str_node::bracket_t is_closing_bracket(const char32_t &br) const
Definition: Parser.cc:62
Definition: Parser.hh:40
Definition: Parser.hh:62
Definition: Parser.hh:61
bool is_number(const std::u32string &str) const
Definition: Parser.cc:396
void remove_empty_nodes()
Definition: Parser.cc:127
std::shared_ptr< Ex > tree
Definition: Parser.hh:56
std::vector< mode_t > current_mode
Definition: Parser.hh:73
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:61
void erase()
Definition: Parser.cc:116
bracket_t
Definition: Storage.hh:57
str_node::bracket_t is_opening_bracket(const char32_t &br) const
Definition: Parser.cc:72
char32_t get_token(unsigned int i)
Definition: Parser.cc:155
void advance(unsigned int &i)
Definition: Parser.cc:149
std::vector< str_node::bracket_t > current_bracket
Definition: Parser.hh:74
Definition: Parser.hh:61