Add support for chained dot calls.

This commit is contained in:
Stan 2018-03-04 22:49:36 +01:00
parent 4a61d1e511
commit be5709ab5c
2 changed files with 39 additions and 0 deletions

View File

@ -2188,6 +2188,16 @@ namespace chaiscript
}
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,
3, 4]
@ -7,3 +18,21 @@ auto y = map(x,
fun(x) { x + 1 })
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)