Skip to content

Commit a4ea8b5

Browse files
authored
cparse namespace added (cparse#82)
1 parent aed8ce0 commit a4ea8b5

11 files changed

+42
-2
lines changed

builtin-features.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "./shunting-yard.h"
1111
#include "./shunting-yard-exceptions.h"
1212

13+
using namespace cparse;
14+
1315
/* * * * * Built-in Features: * * * * */
1416

1517
/**

containers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "./containers.h"
66
#include "./functions.h"
77

8+
using namespace cparse;
9+
810
/* * * * * Initialize TokenMap * * * * */
911

1012
// Using the "Construct On First Use Idiom"

containers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <string>
99
#include <memory>
1010

11+
namespace cparse {
12+
1113
template <typename T>
1214
class Container {
1315
protected:
@@ -241,4 +243,6 @@ class STuple : public Tuple {
241243
}
242244
};
243245

246+
}
247+
244248
#endif // CONTAINERS_H_

functions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "./functions.h"
55
#include "./shunting-yard-exceptions.h"
66

7+
using namespace cparse;
8+
79
/* * * * * class Function * * * * */
810
packToken Function::call(packToken _this, const Function* func,
911
TokenList* args, TokenMap scope) {

functions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <string>
66
#include<functional>
77

8+
namespace cparse {
9+
810
typedef std::list<std::string> args_t;
911

1012
class Function : public TokenBase {
@@ -53,4 +55,6 @@ class CppFunction : public Function {
5355
}
5456
};
5557

58+
}
59+
5660
#endif // FUNCTIONS_H_

packToken.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "./packToken.h"
77
#include "./shunting-yard-exceptions.h"
88

9+
using namespace cparse;
10+
911
const packToken& packToken::None() {
1012
static packToken none = packToken(TokenNone());
1113
return none;
@@ -46,7 +48,7 @@ TokenBase* packToken::operator->() const {
4648
return base;
4749
}
4850

49-
std::ostream& operator<<(std::ostream &os, const packToken& t) {
51+
std::ostream& cparse::operator<<(std::ostream &os, const packToken& t) {
5052
return os << t.str();
5153
}
5254

packToken.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <string>
55

6+
namespace cparse {
7+
68
// Encapsulate TokenBase* into a friendlier interface
79
class packToken {
810
TokenBase* base;
@@ -86,6 +88,7 @@ class packToken {
8688
};
8789

8890
// To allow cout to print it:
89-
std::ostream& operator<<(std::ostream& os, const packToken& t);
91+
std::ostream& operator<<(std::ostream& os, const packToken& t);
92+
}
9093

9194
#endif // PACKTOKEN_H_

shunting-yard-exceptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <string>
88
#include <stdexcept>
99

10+
namespace cparse {
11+
1012
class msg_exception : public std::exception {
1113
protected:
1214
const std::string msg;
@@ -37,4 +39,6 @@ struct undefined_operation : public msg_exception {
3739
: msg_exception("Unexpected operation with operator '" + op + "' and operands: " + left.str() + " and " + right.str() + ".") {}
3840
};
3941

42+
}
43+
4044
#endif // SHUNTING_YARD_EXCEPTIONS_H_

shunting-yard.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <utility> // For std::pair
1212
#include <cstring> // For strchr()
1313

14+
using namespace cparse;
15+
1416
/* * * * * Operation class: * * * * */
1517

1618
// Convert a type into an unique mask for bit wise operations:

shunting-yard.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <memory>
1414
#include <utility>
1515

16+
namespace cparse {
17+
1618
/*
1719
* About tokType enum:
1820
*
@@ -145,11 +147,18 @@ class OppMap_t {
145147
bool exists(const std::string& op) const { return pr_map.count(op); }
146148
};
147149

150+
}
151+
152+
namespace cparse {
153+
148154
class TokenMap;
149155
class TokenList;
150156
class Tuple;
151157
class STuple;
152158
class Function;
159+
160+
}
161+
153162
#include "./packToken.h"
154163

155164
// Define the Tuple, TokenMap and TokenList classes:
@@ -159,6 +168,8 @@ class Function;
159168
// as well as some built-in functions:
160169
#include "./functions.h"
161170

171+
namespace cparse {
172+
162173
// This struct was created to expose internal toRPN() variables
163174
// to custom parsers, in special to the rWordParser_t functions.
164175
struct rpnBuilder {
@@ -420,4 +431,6 @@ class calculator {
420431
calculator& operator=(const calculator& calc);
421432
};
422433

434+
}
435+
423436
#endif // SHUNTING_YARD_H_

test-shunting-yard.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "./shunting-yard.h"
77

8+
using namespace cparse;
9+
810
TokenMap vars, emap, tmap, key3;
911

1012
void PREPARE_ENVIRONMENT() {

0 commit comments

Comments
 (0)