OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
expression.hpp
Go to the documentation of this file.
1//
2// Namespace parser expression
3//
4// Copyright (c) 2026, Paul Scherrer Institute, Villigen PSI, Switzerland
5// All rights reserved
6//
7// This file is part of OPAL.
8//
9// OPAL is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// You should have received a copy of the GNU General Public License
15// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16//
17#ifndef EXPRESSION_HPP
18#define EXPRESSION_HPP
19
20#include "annotation.hpp"
21#include "ast.hpp"
22#include "error_handler.hpp"
23
24#include <list>
25#include <string>
26
27namespace client { namespace parser
28{
30 // The expression grammar
31 //
32 // This is a hand-written recursive-descent parser (replacing the former
33 // Boost.Spirit Qi grammar) that builds the same ast::expression tree.
35 template <typename Iterator>
37 {
39
43 bool parse(Iterator& first, Iterator last, ast::expression& attr);
44
45 private:
48
49 void skip_ws(Iterator& it, Iterator last) const;
50 bool match(Iterator& it, Iterator last, char c) const;
51 bool match_word(Iterator& it, Iterator last, char const* word) const;
52 bool match_op_token(Iterator& it, Iterator last, char const* token) const;
53 bool try_identifier_token(Iterator& it, Iterator last, std::string& word) const;
54
55 template <typename NextLevel, typename OpMatcher>
56 bool parse_level(Iterator& it, Iterator last, ast::expression& out,
57 NextLevel next, OpMatcher match_op);
58
59 bool parse_expr(Iterator& it, Iterator last, ast::expression& out);
60 bool parse_logical_or(Iterator& it, Iterator last, ast::expression& out);
61 bool parse_logical_and(Iterator& it, Iterator last, ast::expression& out);
62 bool parse_equality(Iterator& it, Iterator last, ast::expression& out);
63 bool parse_relational(Iterator& it, Iterator last, ast::expression& out);
64 bool parse_additive(Iterator& it, Iterator last, ast::expression& out);
65 bool parse_multiplicative(Iterator& it, Iterator last, ast::expression& out);
66
67 bool parse_unary(Iterator& it, Iterator last, ast::operand& out);
68 bool parse_primary(Iterator& it, Iterator last, ast::operand& out);
69 bool parse_constant(Iterator& it, Iterator last, ast::operand& out);
70
71 bool parse_argument_list(Iterator& it, Iterator last, std::list<ast::function_call_argument>& out);
72 bool parse_call_argument(Iterator& it, Iterator last, ast::function_call_argument& out);
73 bool parse_quoted_string(Iterator& it, Iterator last, std::string& out);
74
76 };
77}}
78
79#endif
std::variant< expression, quoted_string > function_call_argument
Definition ast.hpp:130
std::variant< nil, bool, unsigned int, double, identifier, recursive_wrapper< unary >, recursive_wrapper< function_call >, recursive_wrapper< expression > > operand
Definition ast.hpp:124
bool parse_logical_and(Iterator &it, Iterator last, ast::expression &out)
bool parse_primary(Iterator &it, Iterator last, ast::operand &out)
bool parse_multiplicative(Iterator &it, Iterator last, ast::expression &out)
annotation< Iterator > annotation_
bool parse_argument_list(Iterator &it, Iterator last, std::list< ast::function_call_argument > &out)
bool parse_quoted_string(Iterator &it, Iterator last, std::string &out)
bool parse_call_argument(Iterator &it, Iterator last, ast::function_call_argument &out)
bool match_word(Iterator &it, Iterator last, char const *word) const
bool parse_constant(Iterator &it, Iterator last, ast::operand &out)
bool parse_relational(Iterator &it, Iterator last, ast::expression &out)
bool parse_level(Iterator &it, Iterator last, ast::expression &out, NextLevel next, OpMatcher match_op)
bool match_op_token(Iterator &it, Iterator last, char const *token) const
bool parse(Iterator &first, Iterator last, ast::expression &attr)
bool parse_expr(Iterator &it, Iterator last, ast::expression &out)
static ast::operand to_operand(ast::expression &&e)
void skip_ws(Iterator &it, Iterator last) const
bool parse_logical_or(Iterator &it, Iterator last, ast::expression &out)
bool parse_unary(Iterator &it, Iterator last, ast::operand &out)
bool parse_equality(Iterator &it, Iterator last, ast::expression &out)
bool try_identifier_token(Iterator &it, Iterator last, std::string &word) const
bool match(Iterator &it, Iterator last, char c) const
error_handler< Iterator > & error_handler_
bool parse_additive(Iterator &it, Iterator last, ast::expression &out)