blob: 92ba306c609c61c8b23de455a9c8d00916116604 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package org.zwobble.couscous.interpreter.values;
import java.util.Optional;
import org.zwobble.couscous.values.IntegerValue;
import org.zwobble.couscous.values.PrimitiveValue;
import org.zwobble.couscous.values.PrimitiveValues;
import org.zwobble.couscous.values.StringValue;
import static java.util.Arrays.asList;
import lombok.Value;
import lombok.val;
@Value
public class IntegerInterpreterValue implements InterpreterValue {
public static final ConcreteType TYPE = ConcreteType.builder(IntegerInterpreterValue.class, IntegerValue.REF)
.staticMethod("parseInt", asList(StringValue.REF),
(environment, arguments) -> {
val value = (StringInterpreterValue)arguments.get(0);
return new IntegerInterpreterValue(Integer.parseInt(value.getValue()));
})
.build();
int value;
@Override
public ConcreteType getType() {
return TYPE;
}
@Override
public Optional<PrimitiveValue> toPrimitiveValue() {
return Optional.of(PrimitiveValues.value(value));
}
}
|