summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/indentation.hpp
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-03-22 18:34:29 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-03-26 16:42:18 -0300
commit2b86e84b5660245b394b4ca1c02b73a8d1989265 (patch)
tree0768dcd23cdf2624356cfe316686ee7015c364ad /src/lib/eolian_cxx/grammar/indentation.hpp
parenta4ae92d8dd2d937f5242ed85d8a8fda4912e1a34 (diff)
eolian_cxx: rework context code, also more flexible scope indentation generator
Summary: Context management classes now store constant copies of the tags they are supposed to hold. So, they are immutable objects now. Functions that manipulate context create new object copies as needed. `constexpr` was added for class constructor and functions. Indentation generator now used four space by default. Also, the amount of desired spaces can now be specified at call site. Added helper methods to return 'indented' and 'unindented' version of a given indentation generator object. Test Plan: ninja test Reviewers: felipealmeida, lauromoura Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8467
Diffstat (limited to '')
-rw-r--r--src/lib/eolian_cxx/grammar/indentation.hpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/lib/eolian_cxx/grammar/indentation.hpp b/src/lib/eolian_cxx/grammar/indentation.hpp
index 897be03c3b..347974fa01 100644
--- a/src/lib/eolian_cxx/grammar/indentation.hpp
+++ b/src/lib/eolian_cxx/grammar/indentation.hpp
@@ -8,22 +8,36 @@ namespace efl { namespace eolian { namespace grammar {
8 8
9struct scope_tab_generator 9struct scope_tab_generator
10{ 10{
11 scope_tab_generator(int n) 11 constexpr scope_tab_generator(int n, int m = 4)
12 : n(n) {} 12 : n(n)
13 13 , m(m)
14 {}
15 constexpr scope_tab_generator(scope_tab_generator const&) = default;
16 scope_tab_generator& operator=(scope_tab_generator const&) = default;
17
14 template <typename OutputIterator, typename Context> 18 template <typename OutputIterator, typename Context>
15 bool generate(OutputIterator sink, attributes::unused_type, Context const&) const 19 bool generate(OutputIterator sink, attributes::unused_type, Context const&) const
16 { 20 {
17 for(int i = 0; i != n; ++i) 21 for(int i = 0; i != n; ++i)
18 { 22 {
19 *sink++ = ' '; 23 for(int j = 0; j != m; ++j)
20 *sink++ = ' '; 24 *sink++ = ' ';
21 *sink++ = ' ';
22 } 25 }
23 return true; 26 return true;
24 } 27 }
25 28
29 constexpr scope_tab_generator inc(int nplus = 1) const
30 {
31 return {n+nplus, m};
32 }
33
34 constexpr scope_tab_generator dec(int nminus = 1) const
35 {
36 return {n-nminus, m};
37 }
38
26 int n; 39 int n;
40 int m;
27}; 41};
28 42
29template <> 43template <>
@@ -33,9 +47,14 @@ struct is_generator<scope_tab_generator> : std::true_type {};
33 47
34struct scope_tab_terminal 48struct scope_tab_terminal
35{ 49{
36 scope_tab_generator operator()(int n) const 50 scope_tab_generator operator()(int n, int m = 4) const
51 {
52 return {n, m};
53 }
54
55 operator scope_tab_generator() const
37 { 56 {
38 return scope_tab_generator(n); 57 return {1};
39 } 58 }
40} const scope_tab = {}; 59} const scope_tab = {};
41 60