use of water.rapids.ast.AstFunction in project h2o-3 by h2oai.
the class Rapids method parseFunctionDefinition.
/**
* Parse and return a user defined function of the form "{arg1 arg2 . (expr)}"
*/
private AstFunction parseFunctionDefinition() {
eatChar('{');
// Parse the list of ids
ArrayList<String> ids = new ArrayList<>();
// 1-based ID list
ids.add("");
while (skipWS() != '.') {
String id = token();
if (!Character.isJavaIdentifierStart(id.charAt(0)))
throw new IllegalASTException("variable must be a valid Java identifier: " + id);
for (char c : id.toCharArray()) if (!Character.isJavaIdentifierPart(c))
throw new IllegalASTException("variable must be a valid Java identifier: " + id);
ids.add(id);
}
// Single dot separates the list of ids from the body of the function
eatChar('.');
// Parse the body
AstRoot body = parseNext();
if (skipWS() != '}')
throw new IllegalASTException("Expected the end of the function, but found '" + peek(0) + "'");
eatChar('}');
return new AstFunction(ids, body);
}
use of water.rapids.ast.AstFunction in project h2o-3 by h2oai.
the class TransformWrappedVecTest method testInversion.
@Test
public void testInversion() {
Vec v = null;
try {
v = Vec.makeZero(1 << 20);
AstFunction ast = (AstFunction) Rapids.parse("{ x . (- 1 x) }");
Vec iv = new TransformWrappedVec(v, ast);
new MRTask() {
@Override
public void map(Chunk c) {
for (int i = 0; i < c._len; ++i) if (c.atd(i) != 1)
throw new RuntimeException("moo");
}
}.doAll(iv);
iv.remove();
} finally {
if (null != v)
v.remove();
}
}
Aggregations