Mercurial > octave
annotate libinterp/parse-tree/pt-delimiter-list.h @ 33308:9d7e418f0121
new delimiter_list functions
* pt-delilmiter-list.h (tree_delimiter_list::empty,
tree_delimiter_list::beg_pos, tree_delimiter_list::end_pos):
New functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 04 Apr 2024 00:52:49 -0400 |
parents | 979a51024c94 |
children |
rev | line source |
---|---|
33295
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 // |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 // Copyright (C) 2024 The Octave Project Developers |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 // |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 // |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 // This file is part of Octave. |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 // |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 // (at your option) any later version. |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 // |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 // GNU General Public License for more details. |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 // |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 // |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if ! defined (octave_tree_delimiter_list_h) |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #define octave_tree_delimiter_list_h 1 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 #include "octave-config.h" |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <stack> |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
33308
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
33 #include "filepos.h" |
33295
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include "token.h" |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 OCTAVE_BEGIN_NAMESPACE(octave) |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 class tree_delimiter_list |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 { |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 public: |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 typedef std::pair<token, token> element_type; |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (tree_delimiter_list) |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
33308
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
46 size_t count () const { return m_delimiters.size (); } |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
47 |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
48 bool empty () const { return m_delimiters.empty (); } |
33295
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 void push (const token& open_delim, const token& close_delim) |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 { |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 m_delimiters.push (element_type (open_delim, close_delim)); |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 } |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 |
33308
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
55 filepos beg_pos () const |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
56 { |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
57 if (m_delimiters.empty ()) |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
58 return filepos (); |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
59 |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
60 const element_type& elt = m_delimiters.top (); |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
61 return elt.first.beg_pos (); |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
62 } |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
63 |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
64 filepos end_pos () const |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
65 { |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
66 if (m_delimiters.empty ()) |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
67 return filepos (); |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
68 |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
69 const element_type& elt = m_delimiters.top (); |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
70 return elt.second.end_pos (); |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
71 } |
9d7e418f0121
new delimiter_list functions
John W. Eaton <jwe@octave.org>
parents:
33295
diff
changeset
|
72 |
33295
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 private: |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 std::stack<element_type> m_delimiters; |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 }; |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 OCTAVE_END_NAMESPACE(octave) |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 |
979a51024c94
new class to store delimiters surrounding parse tree elements
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 #endif |