Merge pull request #420 from StanEpp/c++17

Add support for chained dot calls.
This commit is contained in:
Jason Turner 2018-06-03 15:47:05 -06:00 committed by GitHub
commit aa61df941b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -2278,6 +2278,16 @@ namespace chaiscript
} }
build_match<eval::Dot_Access_AST_Node<Tracer>>(prev_stack_top); build_match<eval::Dot_Access_AST_Node<Tracer>>(prev_stack_top);
} }
else if (Eol()) {
auto start = --m_position;
while (Eol()) {}
if (Symbol(".")) {
has_more = true;
--m_position;
} else {
m_position = start;
}
}
} }
} }

View File

@ -1,3 +1,14 @@
class MyClass {
var value;
def MyClass(v) { this.value = v; }
def getWrappedIncrement() { return MyClass(this.value + 1); }
def getValue { return this.value; }
};
def foo(x) {
return MyClass(x+1);
}
auto x = [1, 2, auto x = [1, 2,
3, 4] 3, 4]
@ -7,3 +18,21 @@ auto y = map(x,
fun(x) { x + 1 }) fun(x) { x + 1 })
assert_equal(2, y[0]) assert_equal(2, y[0])
auto z = foo(1)
.value
assert_equal(2, z)
auto v = foo(2)
.getValue()
assert_equal(3, v)
auto u = MyClass(3)
.getWrappedIncrement()
.getWrappedIncrement()
.getValue()
assert_equal(5, u)