mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
Add support for chained dot calls.
This commit is contained in:
parent
4a61d1e511
commit
be5709ab5c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
Loading…
x
Reference in New Issue
Block a user