Switch vectors and maps over to curly braces from square braces to line up with C++11.
This commit is contained in:
parent
425ca59a34
commit
784ca41270
@ -1597,10 +1597,10 @@ namespace chaiscript
|
||||
|
||||
size_t prev_stack_top = m_match_stack.size();
|
||||
|
||||
if (Char('[')) {
|
||||
if (Char('{')) {
|
||||
retval = true;
|
||||
Container_Arg_List();
|
||||
if (!Char(']')) {
|
||||
if (!Char('}')) {
|
||||
throw exception::eval_error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) {
|
||||
|
@ -7,7 +7,7 @@
|
||||
#ifndef CHAISCRIPT_PRELUDE_HPP_
|
||||
#define CHAISCRIPT_PRELUDE_HPP_
|
||||
|
||||
//Note, the expression "[x,y]" in "collate" is parsed as two separate expressions
|
||||
//Note, the expression "{x,y}" in "collate" is parsed as two separate expressions
|
||||
//by C++, so CODE_STRING, takes two expressions and adds in the missing comma
|
||||
#define CODE_STRING(x, y) #x ", " #y
|
||||
|
||||
@ -23,7 +23,7 @@ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\
|
||||
}\n\
|
||||
# to_string for containers\n\
|
||||
def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\
|
||||
"[" + x.join(", ") + "]"; \n\
|
||||
"{" + x.join(", ") + "}"; \n\
|
||||
}\n\
|
||||
# Basic to_string function\n\
|
||||
def to_string(x) { \n\
|
||||
@ -259,7 +259,7 @@ def generate_range(x, y) { \n\
|
||||
}\n\
|
||||
# Returns a new Vector with the first value to the second value as its elements\n\
|
||||
def collate(x, y) { \n\
|
||||
[x, y]; \n\
|
||||
{x, y}; \n\
|
||||
} \n\
|
||||
def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\
|
||||
auto r_x = range(x); \n\
|
||||
|
@ -1,2 +1,2 @@
|
||||
auto prod = bind(foldl, _, `*`, 1.0)
|
||||
assert_equal(60, prod([3, 4, 5]))
|
||||
assert_equal(60, prod({3, 4, 5}))
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto v = concat([1, 2], [3, 4]);
|
||||
auto v = concat({1, 2}, {3, 4});
|
||||
|
||||
assert_equal(4, v.size());
|
||||
assert_equal(1, v[0]);
|
||||
|
@ -1,9 +1,9 @@
|
||||
auto a = [1,2,3, [4,5,6] ]
|
||||
auto a = {1,2,3, {4,5,6} }
|
||||
|
||||
assert_equal(a[3][0], 4)
|
||||
|
||||
|
||||
def Test::Test() { this.a = [1,2,3]; }
|
||||
def Test::Test() { this.a = {1,2,3}; }
|
||||
attr Test::a;
|
||||
|
||||
auto t = Test();
|
||||
|
@ -1 +1 @@
|
||||
assert_equal([3,4], drop([1, 2, 3, 4], 2))
|
||||
assert_equal({3,4}, drop({1, 2, 3, 4}, 2))
|
||||
|
@ -1 +1 @@
|
||||
assert_equal([2, 3], drop_while([1, 2, 3], odd))
|
||||
assert_equal({2, 3}, drop_while({1, 2, 3}, odd))
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto results = [];
|
||||
auto results = {};
|
||||
|
||||
for (auto i = 2; i < 6; ++i) {
|
||||
try {
|
||||
@ -31,4 +31,4 @@ catch {
|
||||
results.push_back("defaultcatch");
|
||||
}
|
||||
|
||||
assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results);
|
||||
assert_equal({"c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"}, results);
|
||||
|
@ -1 +1 @@
|
||||
assert_equal([1,3], filter([1, 2, 3, 4], odd))
|
||||
assert_equal({1,3}, filter({1, 2, 3, 4}, odd))
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(10, foldl([1, 2, 3, 4], `+`, 0))
|
||||
assert_equal(10, foldl({1, 2, 3, 4}, `+`, 0))
|
||||
|
@ -1,7 +1,7 @@
|
||||
auto ret = []
|
||||
auto ret = {}
|
||||
|
||||
for (auto i = 0; i < 5; ++i) {
|
||||
ret.push_back(i);
|
||||
}
|
||||
|
||||
assert_equal([0,1,2,3,4], ret);
|
||||
assert_equal({0,1,2,3,4}, ret);
|
||||
|
@ -1 +1 @@
|
||||
for_each([1, 2, 3], print)
|
||||
for_each({1, 2, 3}, print)
|
||||
|
@ -1,3 +1,3 @@
|
||||
auto v = [1,2,3];
|
||||
auto v = {1,2,3};
|
||||
auto r = range(v);
|
||||
for_each(r, fun(x) { assert_equal(true, x>0); } )
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Don't bother checking the output from this one, just makes sure it executes
|
||||
auto v = [1,2,3];
|
||||
auto v = {1,2,3};
|
||||
auto r = retro(range(v));
|
||||
for_each(r, print)
|
||||
|
@ -18,7 +18,7 @@ assert_equal(test_function, test_function);
|
||||
|
||||
assert_not_equal(test_function, `+`);
|
||||
|
||||
assert_equal(test_function.call([1]), 1);
|
||||
assert_equal(test_function.call({1}), 1);
|
||||
|
||||
// dynamic object function tests
|
||||
|
||||
|
@ -1 +1 @@
|
||||
assert_equal([1,2,3,4,5,6,7,8,9,10], generate_range(1, 10))
|
||||
assert_equal({1,2,3,4,5,6,7,8,9,10}, generate_range(1, 10))
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
// tests more complex parses of the index operator
|
||||
|
||||
def Bob::bob3() { return [1,2,3]; }
|
||||
def Bob::bob3() { return {1,2,3}; }
|
||||
def Bob::Bob() {}
|
||||
auto b = Bob();
|
||||
|
||||
|
@ -1 +1 @@
|
||||
assert_equal("1*2*3", join([1, 2, 3], "*"))
|
||||
assert_equal("1*2*3", join({1, 2, 3}, "*"))
|
||||
|
@ -1,2 +1,2 @@
|
||||
|
||||
assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } );
|
||||
assert_throws("Parse failure", fun() { eval("{\"hello\":5,\"j\",\"k\"}") } );
|
||||
|
@ -1 +1 @@
|
||||
assert_equal([true, false, true], map([1,2,3], odd))
|
||||
assert_equal({true, false, true}, map({1,2,3}, odd))
|
||||
|
@ -1,2 +1,2 @@
|
||||
auto x = ["bob":2, "fred":3]
|
||||
auto x = {"bob":2, "fred":3}
|
||||
assert_equal(3, x["fred"])
|
||||
|
@ -1,3 +1,3 @@
|
||||
auto x = ["bob":1, "fred":2]
|
||||
auto x = {"bob":1, "fred":2}
|
||||
|
||||
assert_equal(2, x.size());
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(6, [1, 2, 3].sum())
|
||||
assert_equal(6, {1, 2, 3}.sum())
|
||||
|
@ -1,5 +1,5 @@
|
||||
auto x = [1, 2,
|
||||
3, 4]
|
||||
auto x = {1, 2,
|
||||
3, 4}
|
||||
|
||||
assert_equal(1, x[0])
|
||||
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(24, product([1, 2, 3, 4]))
|
||||
assert_equal(24, product({1, 2, 3, 4}))
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto x = [1, 2, 3, 4]
|
||||
auto x = {1, 2, 3, 4}
|
||||
auto r = range(x)
|
||||
r.pop_front()
|
||||
assert_equal(2, r.front());
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto x = [1, 2, 3, 4]
|
||||
auto x = {1, 2, 3, 4}
|
||||
auto r = range(x)
|
||||
r.pop_back()
|
||||
assert_equal(3, r.back())
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto v = [1,2,"hi", "world", 5.5]
|
||||
auto v = {1,2,"hi", "world", 5.5}
|
||||
assert_equal(true, v.contains(5.5))
|
||||
assert_equal(false, v.contains(0))
|
||||
assert_equal(false, v.contains(1, lt))
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto v = [2, 1, "Hi", 5.5]
|
||||
auto v = {2, 1, "Hi", 5.5}
|
||||
auto r = v.find("Hi");
|
||||
|
||||
assert_equal("Hi", r.front())
|
||||
|
@ -1 +1 @@
|
||||
assert_equal([3,4,5,6], [3..6])
|
||||
assert_equal({3,4,5,6}, {3..6})
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(10, reduce([1, 2, 3, 4], `+`))
|
||||
assert_equal(10, reduce({1, 2, 3, 4}, `+`))
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto x = [1, 2, 3, 4]
|
||||
auto x = {1, 2, 3, 4}
|
||||
auto r = retro(range(x))
|
||||
r.pop_front()
|
||||
assert_equal(3, r.front())
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto x = [1, 2, 3, 4]
|
||||
auto x = {1, 2, 3, 4}
|
||||
auto r = retro(range(x))
|
||||
r.pop_back()
|
||||
auto r2 = retro(r)
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(10, sum([1, 2, 3, 4]))
|
||||
assert_equal(10, sum({1, 2, 3, 4}))
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(2, take([1, 2, 3, 4], 2).back())
|
||||
assert_equal(2, take({1, 2, 3, 4}, 2).back())
|
||||
|
@ -1 +1 @@
|
||||
assert_equal([1], take_while([1, 2, 3, 4], odd))
|
||||
assert_equal({1}, take_while({1, 2, 3, 4}, odd))
|
||||
|
@ -1,2 +1,2 @@
|
||||
auto x = [1, 2, 3]
|
||||
auto x = {1, 2, 3}
|
||||
assert_equal(3, x[2])
|
||||
|
@ -1,3 +1,3 @@
|
||||
auto x = [1, 2, 3]
|
||||
auto x = {1, 2, 3}
|
||||
x.erase_at(1)
|
||||
assert_equal([1,3], x);
|
||||
assert_equal({1,3}, x);
|
||||
|
@ -1,2 +1,2 @@
|
||||
auto x = [1, 2, 3]
|
||||
auto x = {1, 2, 3}
|
||||
assert_equal(3, x.size())
|
||||
|
@ -1,3 +1,3 @@
|
||||
auto x = [1, 2, 3]
|
||||
auto x = {1, 2, 3}
|
||||
x.insert_at(1, 6)
|
||||
assert_equal([1,6,2,3], x);
|
||||
assert_equal({1,6,2,3}, x);
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(1, [1,2,3][0])
|
||||
assert_equal(1, {1,2,3}[0])
|
||||
|
@ -1,2 +1,2 @@
|
||||
auto x = [1]
|
||||
auto x = {1}
|
||||
assert_equal(1, x[0])
|
||||
|
@ -1 +1 @@
|
||||
assert_equal(1, ([1,2,3])[0])
|
||||
assert_equal(1, ({1,2,3})[0])
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto x = [1, 2]
|
||||
auto x = {1, 2}
|
||||
x.push_back(3)
|
||||
assert_equal(3, x.size())
|
||||
assert_equal(3, x.back())
|
||||
|
@ -1,4 +1,4 @@
|
||||
auto bob = []
|
||||
auto bob = {}
|
||||
bob.push_back(3)
|
||||
assert_equal(1, bob.size())
|
||||
assert_equal(3, bob.front())
|
||||
|
@ -1,5 +1,5 @@
|
||||
auto z = zip([1, 2, 3], [4, 5, 6])
|
||||
auto z = zip({1, 2, 3}, {4, 5, 6})
|
||||
|
||||
assert_equal([1,4], z[0])
|
||||
assert_equal([2,5], z[1])
|
||||
assert_equal([3,6], z[2])
|
||||
assert_equal({1,4}, z[0])
|
||||
assert_equal({2,5}, z[1])
|
||||
assert_equal({3,6}, z[2])
|
||||
|
@ -1,3 +1,3 @@
|
||||
auto z = zip_with(`+`, [1, 2, 3], [4, 5, 6])
|
||||
auto z = zip_with(`+`, {1, 2, 3}, {4, 5, 6})
|
||||
|
||||
assert_equal([5,7,9], z)
|
||||
assert_equal({5,7,9}, z)
|
||||
|
Loading…
x
Reference in New Issue
Block a user