use of com.yahoo.vespa.indexinglanguage.parser.ParseException in project vespa by vespa-engine.
the class SDField method parseIndexingScript.
public void parseIndexingScript(String script, Linguistics linguistics) {
try {
ScriptParserContext config = new ScriptParserContext(linguistics);
config.setInputStream(new IndexingInput(script));
setIndexingScript(ScriptExpression.newInstance(config));
} catch (ParseException e) {
throw new RuntimeException("Failed to parser script '" + script + "'.", e);
}
}
use of com.yahoo.vespa.indexinglanguage.parser.ParseException in project vespa by vespa-engine.
the class ScriptParserTestCase method requireThatExpressionParserCanBeInvoked.
@Test
public void requireThatExpressionParserCanBeInvoked() throws ParseException {
try {
ScriptParser.parseExpression(newContext("foo"));
} catch (ParseException e) {
assertException(e, "Encountered \" <IDENTIFIER> \"foo \"\" at line 1, column 1.");
}
assertEquals(new InputExpression("foo"), ScriptParser.parseExpression(newContext("input foo")));
assertEquals(new StatementExpression(new InputExpression("foo"), new EchoExpression()), ScriptParser.parseExpression(newContext("input foo | echo")));
assertEquals(new ScriptExpression(new StatementExpression(new InputExpression("foo")), new StatementExpression(new EchoExpression())), ScriptParser.parseExpression(newContext("{ input foo; echo }")));
}
use of com.yahoo.vespa.indexinglanguage.parser.ParseException in project vespa by vespa-engine.
the class ScriptParser method parse.
private static <T extends Expression> T parse(ScriptParserContext config, ParserMethod<T> method) throws ParseException {
CharStream input = config.getInputStream();
IndexingParser parser = new IndexingParser(input);
parser.setAnnotatorConfig(config.getAnnotatorConfig());
parser.setDefaultFieldName(config.getDefaultFieldName());
parser.setLinguistics(config.getLinguistcs());
try {
return method.call(parser);
} catch (ParseException e) {
if (!(input instanceof FastCharStream)) {
throw e;
}
throw new ParseException(((FastCharStream) input).formatException(e.getMessage()));
} finally {
if (parser.token != null && parser.token.next != null) {
input.backup(parser.token.next.image.length());
}
}
}
use of com.yahoo.vespa.indexinglanguage.parser.ParseException in project vespa by vespa-engine.
the class AssertIndexingScript method assertIndexing.
public static void assertIndexing(List<String> expected, Iterable<Expression> actual) {
List<String> parsedExpected = new LinkedList<>();
for (String str : expected) {
try {
parsedExpected.add(Expression.fromString(str).toString());
} catch (ParseException e) {
fail(e.getMessage());
}
}
for (Expression actualExp : actual) {
String str = actualExp.toString();
assertTrue("Unexpected: " + str, parsedExpected.remove(str));
}
assertTrue("Missing: " + parsedExpected.toString(), parsedExpected.isEmpty());
}
use of com.yahoo.vespa.indexinglanguage.parser.ParseException in project vespa by vespa-engine.
the class ScriptParserTestCase method requireThatStatementParserCanBeInvoked.
@Test
public void requireThatStatementParserCanBeInvoked() throws ParseException {
try {
ScriptParser.parseStatement(newContext("foo"));
} catch (ParseException e) {
assertException(e, "Encountered \" <IDENTIFIER> \"foo \"\" at line 1, column 1.");
}
assertEquals(new StatementExpression(new InputExpression("foo")), ScriptParser.parseStatement(newContext("input foo")));
assertEquals(new StatementExpression(new InputExpression("foo"), new EchoExpression()), ScriptParser.parseStatement(newContext("input foo | echo")));
assertEquals(new StatementExpression(new ScriptExpression(new StatementExpression(new InputExpression("foo")), new StatementExpression(new EchoExpression()))), ScriptParser.parseStatement(newContext("{ input foo; echo }")));
}
Aggregations