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&);
cadabra::Parser::current_bracket
std::vector< str_node::bracket_t > current_bracket
Definition: Parser.hh:74
Storage.hh
cadabra::Parser::m_findchildren
Definition: Parser.hh:61
cadabra::Parser
Definition: Parser.hh:40
cadabra::Parser::string2tree
bool string2tree(const std::string &inp)
Definition: Parser.cc:163
cadabra::Parser::current_parent_rel
std::vector< str_node::parent_rel_t > current_parent_rel
Definition: Parser.hh:75
cadabra::Parser::Parser
Parser()
Definition: Parser.cc:91
cadabra::Parser::m_property
Definition: Parser.hh:63
cadabra::Parser::is_link
str_node::parent_rel_t is_link(const char32_t &ln) const
Definition: Parser.cc:82
cadabra::Parser::mode_t
mode_t
Definition: Parser.hh:61
cadabra::Parser::m_childgroup
Definition: Parser.hh:63
cadabra::Parser::str
std::u32string str
Definition: Parser.hh:59
cadabra::Parser::parts
Ex::iterator parts
Definition: Parser.hh:58
cadabra::Parser::remove_empty_nodes
void remove_empty_nodes()
Definition: Parser.cc:127
operator>>
std::istream & operator>>(std::istream &, cadabra::Parser &)
Definition: Parser.cc:31
cadabra::Parser::m_singlecharname
Definition: Parser.hh:62
cadabra::Parser::m_backslashname
Definition: Parser.hh:62
cadabra::Parser::is_number
bool is_number(const std::u32string &str) const
Definition: Parser.cc:396
cadabra::Parser::is_closing_bracket
str_node::bracket_t is_closing_bracket(const char32_t &br) const
Definition: Parser.cc:62
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:80
cadabra::str_node::bracket_t
bracket_t
Definition: Storage.hh:57
cadabra::Parser::m_skipwhite
Definition: Parser.hh:61
cadabra::Parser::advance
void advance(unsigned int &i)
Definition: Parser.cc:149
cadabra::Parser::m_initialgroup
Definition: Parser.hh:63
cadabra::Parser::tree
std::shared_ptr< Ex > tree
Definition: Parser.hh:56
cadabra::Parser::current_mode
std::vector< mode_t > current_mode
Definition: Parser.hh:73
cadabra::Parser::m_name
Definition: Parser.hh:61
cadabra::Parser::erase
void erase()
Definition: Parser.cc:116
cadabra::str_node::parent_rel_t
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
cadabra::Parser::is_opening_bracket
str_node::bracket_t is_opening_bracket(const char32_t &br) const
Definition: Parser.cc:72
cadabra::Parser::m_verbatim
Definition: Parser.hh:63
cadabra::Parser::get_token
char32_t get_token(unsigned int i)
Definition: Parser.cc:155
cadabra::Parser::finalise
void finalise()
Definition: Parser.cc:139