Scope implements ValueExpression { public Scope(final ValueExpression scopedValueExpression, final SingleValueExpression scopeSize) { this.scopedValueExpression = checkNotNull(scopedValueExpression, "scopedValueExpression"); this.scopeSize = checkNotNull(scopeSize, "scopeSize"); } Scope(final ValueExpression scopedValueExpression, final SingleValueExpression scopeSize); @Override ImmutableList<Value> eval(final ParseState parseState, final Encoding encoding); @Override String toString(); @Override boolean equals(final Object obj); @Override int hashCode(); final ValueExpression scopedValueExpression; final SingleValueExpression scopeSize; }
@Test public void scopeSizes() { final Token scopesToken = seq(any("value"), repn(seq(any("value"), seq(any("value"), def("deepestValue", con(1), eq(first(scope(ref("value"), con(0))))), def("middleValue", con(1), eq(first(scope(ref("value"), con(1))))), def("stillMiddleValue", con(1), eq(first(scope(ref("value"), con(2))))), def("topValue", con(1), eq(first(scope(ref("value"), con(3))))), def("hugeScope", con(1), eq(first(scope(ref("value"), con(100))))) ) ), con(1) ) ); final Optional<ParseState> result = scopesToken.parse(env(stream(0, 1, 2, 2, 1, 1, 0, 0), enc())); assertTrue(result.isPresent()); }