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