use of com.google.template.soy.base.SourceLocation in project closure-templates by google.
the class ParseErrors method reportTokenMgrError.
static void reportTokenMgrError(ErrorReporter reporter, String filePath, TokenMgrError exception) {
int errorCode = exception.errorCode;
String message = exception.getMessage();
SourceLocation location;
Matcher loc = EXTRACT_LOCATION.matcher(message);
if (loc.find()) {
int line = Integer.parseInt(loc.group(1));
// javacc's column numbers are 0-based, while Soy's are 1-based
int column = Integer.parseInt(loc.group(2)) + 1;
location = new SourceLocation(filePath, line, column, line, column);
} else {
location = new SourceLocation(filePath);
}
// also allow us to avoid using a regex to extract line number information.
if (exception.errorCode == TokenMgrError.LEXICAL_ERROR && message.contains("<EOF>")) {
reporter.report(location, UNEXPECTED_EOF);
} else {
reporter.report(location, UNEXPECTED_TOKEN_MGR_ERROR, errorCode, message);
}
}
use of com.google.template.soy.base.SourceLocation in project closure-templates by google.
the class ParseExpressionTest method testParseDataReference.
@Test
public void testParseDataReference() throws Exception {
SourceLocation loc = SourceLocation.UNKNOWN;
ExprNode dataRef = assertThatExpression("$boo").isValidExpression();
assertNodeEquals(new VarRefNode("boo", loc, false, null), dataRef);
dataRef = assertThatExpression("$boo.foo").isValidExpression();
assertNodeEquals(new FieldAccessNode(new VarRefNode("boo", loc, false, null), "foo", loc, false), dataRef);
dataRef = assertThatExpression("$boo[0][$foo]").isValidExpression();
assertNodeEquals(new ItemAccessNode(new ItemAccessNode(new VarRefNode("boo", loc, false, null), new IntegerNode(0, loc), loc, false), new VarRefNode("foo", loc, false, null), loc, false), dataRef);
dataRef = assertThatExpression("$boo?[0]?[$foo]").isValidExpression();
assertNodeEquals(new ItemAccessNode(new ItemAccessNode(new VarRefNode("boo", loc, false, null), new IntegerNode(0, loc), loc, true), new VarRefNode("foo", loc, false, null), loc, true), dataRef);
dataRef = assertThatExpression("$ij.boo?[0][$ij.foo]").isValidExpression();
assertNodeEquals(new ItemAccessNode(new ItemAccessNode(new VarRefNode("boo", loc, true, null), new IntegerNode(0, loc), loc, true), new VarRefNode("foo", loc, true, null), loc, false), dataRef);
}
use of com.google.template.soy.base.SourceLocation in project closure-templates by google.
the class TemplateRegistryTest method testBasicTemplatesWithSameNamesInDifferentFiles.
@Test
public void testBasicTemplatesWithSameNamesInDifferentFiles() {
TemplateRegistry registry = SoyFileSetParserBuilder.forSuppliers(SoyFileSupplier.Factory.create("{namespace ns}\n" + "/** Template. */\n" + "{template .foo}\n" + "{/template}\n", SoyFileKind.SRC, "bar.soy"), SoyFileSupplier.Factory.create("{namespace ns2}\n" + "/** Template. */\n" + "{template .foo}\n" + "{/template}\n", SoyFileKind.SRC, "baz.soy")).parse().registry();
assertThatRegistry(registry).containsBasicTemplate("ns.foo").definedAt(new SourceLocation("bar.soy", 3, 1, 3, 15));
assertThatRegistry(registry).containsBasicTemplate("ns2.foo").definedAt(new SourceLocation("baz.soy", 3, 1, 3, 15));
}
Aggregations