use of com.linkedin.data.grammar.PdlParser.TypeDeclarationContext in project rest.li by linkedin.
the class PdlSchemaParser method parse.
/**
* Parse list of Data objects.
*
* The {{DataSchema}'s parsed are in {{#topLevelDataSchemas}.
* Parse errors are in {{#errorMessageBuilder} and indicated
* by {{#hasError()}.
*
* @param document provides the source code in AST form
*/
private DataSchema parse(DocumentContext document) throws ParseException {
PdlParser.NamespaceDeclarationContext namespaceDecl = document.namespaceDeclaration();
if (namespaceDecl != null) {
setCurrentNamespace(namespaceDecl.qualifiedIdentifier().value);
} else {
setCurrentNamespace("");
}
if (document.packageDeclaration() != null) {
setCurrentPackage(document.packageDeclaration().qualifiedIdentifier().value);
} else {
setCurrentPackage(null);
}
setCurrentImports(document.importDeclarations());
TypeDeclarationContext typeDeclaration = document.typeDeclaration();
DataSchema schema;
if (typeDeclaration.namedTypeDeclaration() != null) {
NamedDataSchema namedSchema = parseNamedType(typeDeclaration.namedTypeDeclaration());
if (!namedSchema.getNamespace().equals(getCurrentNamespace())) {
throw new ParseException(typeDeclaration, "Top level type declaration may not be qualified with a namespace different than the file namespace: " + typeDeclaration.getText());
}
schema = namedSchema;
} else if (typeDeclaration.anonymousTypeDeclaration() != null) {
schema = parseAnonymousType(typeDeclaration.anonymousTypeDeclaration());
} else {
throw new ParseException(typeDeclaration, "Unrecognized type declaration: " + typeDeclaration.getText());
}
addTopLevelSchema(schema);
return schema;
}
Aggregations