Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
expression_parser.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_EXPRESSION_PARSER_HPP
9#define ADOBE_EXPRESSION_PARSER_HPP
10
11#include <adobe/config.hpp>
12
13#include <adobe/array_fwd.hpp>
15#include <adobe/implementation/lex_stream_fwd.hpp>
16#include <adobe/istream.hpp>
17
18#include <boost/noncopyable.hpp>
19
20/**************************************************************************************************/
21
22namespace adobe {
23
24/**************************************************************************************************/
25
71
72/**************************************************************************************************/
73
74class expression_parser : public boost::noncopyable {
75public:
76 expression_parser(std::istream& in, const line_position_t& position);
77
79
81
82 void set_keyword_extension_lookup(const keyword_extension_lookup_proc_t& proc);
83
84 void set_comment_bypass(bool bypass);
85
86 // expression = or_expression ["?" expression ":" expression].
89
90 // or_expression = and_expression { "||" and_expression }.
92
93 // and_expression = bitwise_or_expression { "&&" bitwise_or_expression }.
95
96 // bitwise_or_expression = bitwise_xor_expression { "|" bitwise_xor_expression }.
98
99 // bitwise_xor_expression = bitwise_and_expression { "^" bitwise_and_expression }.
101
102 // bitwise_and_expression = equality_expression { "&" equality_expression }.
104
105 // equality_expression = relational_expression { ("==" | "!=") relational_expression }.
107
108 // relational_expression = bitshift_expression { ("<" | ">" | "<=" | ">=") bitshift_expression
109 // }.
111
112 // bitshift_expression = additive_expression { ("<<" | ">>") additive_expression }.
114
115 // additive_expression = multiplicative_expression { ("+" | "-") multiplicative_expression }.
117
118 // multiplicative_expression = unary_expression { ("*" | "/" | "%" | "div") unary_expression }.
120
121 // unary_expression = postfix_expression | (unary_operator unary_expression).
123
124 // unary_operator = "+" | "-" | "!" | "~".
126
127 // postfix_expression = primary_expression { ("[" expression "]") | ("." identifier) }.
129
130 // primary_expression = name | number | boolean | string | "empty" | array | dictionary
131 // | variable_or_function | ( "(" expression ")" ).
133
134 // variable_or_function = identifier ["(" [argument_expression_list] ")"].
136
137 // argument_expression_list = named_argument_list | argument_list.
139
140 // array = "[" [argument_list] "]".
142
143 // dictionary = "{" [named_argument_list] "}".
145
146 // argument_list = expression { "," expression }.
148
149 // named_argument_list = named_argument { "," named_argument }.
151
152 // named_argument = ident ":" expression.
154
155 // name = "@" (identifier | keyword).
157
158 // boolean = "true" | "false".
160
161 // lexical tokens:
162
164 bool is_lead_comment(std::string&);
165 bool is_trail_comment(std::string&);
166
167 /*
168 REVISIT (sparent) : We should provide a protected call to get the token stream and allow
169 subclasses to access it directly - but for now we'll stick with the law of Demiter.
170 */
171
172 void throw_exception(const char* errorString);
173 void throw_exception(const name_t& found, const name_t& expected);
174 bool is_token(name_t tokenName);
175
176protected:
177 const stream_lex_token_t& get_token();
178 void putback();
179
180 bool is_token(name_t tokenName, any_regular_t& tokenValue);
181 void require_token(name_t tokenName, any_regular_t& tokenValue);
182 void require_token(name_t tokenName);
183 bool is_keyword(name_t keywordName);
184 void require_keyword(name_t keywordName);
185
186
187private:
188 class implementation;
189 implementation* object;
190};
191
192/**************************************************************************************************/
193
194} // namespace adobe
195
196/**************************************************************************************************/
197
198#endif
199
200/**************************************************************************************************/
void require_expression(array_t &)
bool is_token(name_t tokenName)
bool is_variable_or_function(array_t &)
bool is_or_expression(array_t &)
bool is_trail_comment(std::string &)
expression_parser(std::istream &in, const line_position_t &position)
bool is_lead_comment(std::string &)
bool is_primary_expression(array_t &)
void throw_exception(const name_t &found, const name_t &expected)
void set_keyword_extension_lookup(const keyword_extension_lookup_proc_t &proc)
bool is_named_argument_list(array_t &)
void set_comment_bypass(bool bypass)
bool is_bitwise_or_expression(array_t &)
bool is_multiplicative_expression(array_t &)
bool is_identifier(name_t &)
bool is_argument_list(array_t &)
bool is_unary_operator(name_t &)
bool is_array(array_t &)
bool is_named_argument(array_t &)
bool is_keyword(name_t keywordName)
void throw_exception(const char *errorString)
const stream_lex_token_t & get_token()
bool is_argument_expression_list(array_t &)
bool is_bitwise_xor_expression(array_t &)
void require_token(name_t tokenName, any_regular_t &tokenValue)
void require_token(name_t tokenName)
bool is_bitwise_and_expression(array_t &)
bool is_relational_expression(array_t &)
bool is_equality_expression(array_t &)
bool is_bitshift_expression(array_t &)
bool is_token(name_t tokenName, any_regular_t &tokenValue)
bool is_unary_expression(array_t &)
bool is_expression(array_t &)
bool is_boolean(any_regular_t &)
void require_keyword(name_t keywordName)
bool is_postfix_expression(array_t &)
bool is_name(any_regular_t &)
const line_position_t & next_position()
bool is_additive_expression(array_t &)
bool is_and_expression(array_t &)
bool is_dictionary(array_t &)
A runtime polymorphic type similar to boost::any which can hold any type which models Regular.
std::vector< any_regular_t > array_t
Definition array_fwd.hpp:23
A type detailing parser position information.
Definition istream.hpp:127
A character string class for immutable strings.
Definition name.hpp:220