public interface YangParser {
/**
* Return enumeration of concrete types of {@link SchemaSourceRepresentation} parsers created from this factory
- * support. Users can use this
+ * support. Users can use this information prepare the source they have to a representation which will be accepted
+ * by this parser.
*
* @return Enumeration of supported schema source representations.
*/
import org.opendaylight.yangtools.yang.model.repo.api.YinDomSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YinXmlSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinTextToDomTransformer;
final class YangParserImpl implements YangParser {
private static final Collection<Class<? extends SchemaSourceRepresentation>> REPRESENTATIONS = ImmutableList.of(
- YangTextSchemaSource.class, YinDomSchemaSource.class, YinXmlSchemaSource.class, YinTextSchemaSource.class);
+ ASTSchemaSource.class, YangTextSchemaSource.class, YinDomSchemaSource.class, YinXmlSchemaSource.class,
+ YinTextSchemaSource.class);
private final BuildAction buildAction;
private static StatementStreamSource sourceToStatementStream(final SchemaSourceRepresentation source)
throws IOException, YangSyntaxErrorException {
requireNonNull(source);
- if (source instanceof YangTextSchemaSource) {
+ if (source instanceof ASTSchemaSource) {
+ return YangStatementStreamSource.create((ASTSchemaSource) source);
+ } else if (source instanceof YangTextSchemaSource) {
return YangStatementStreamSource.create((YangTextSchemaSource) source);
} else if (source instanceof YinDomSchemaSource) {
return YinStatementStreamSource.create((YinDomSchemaSource) source);
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class ASTSchemaSource implements SchemaSourceRepresentation {
private final YangModelDependencyInfo depInfo;
private final SemVerSourceIdentifier semVerId;
+ private final SourceIdentifier identifier;
private final ParserRuleContext tree;
- private final SourceIdentifier id;
private final String symbolicName;
- private ASTSchemaSource(@Nonnull final SourceIdentifier id, @Nonnull final SemVerSourceIdentifier semVerId,
+ private ASTSchemaSource(@Nonnull final SourceIdentifier identifier, @Nonnull final SemVerSourceIdentifier semVerId,
@Nonnull final ParserRuleContext tree, @Nonnull final YangModelDependencyInfo depInfo,
@Nullable final String symbolicName) {
this.depInfo = requireNonNull(depInfo);
this.tree = requireNonNull(tree);
- this.id = requireNonNull(id);
+ this.identifier = requireNonNull(identifier);
this.semVerId = requireNonNull(semVerId);
this.symbolicName = symbolicName;
}
@Override
public SourceIdentifier getIdentifier() {
- return id;
+ return identifier;
}
@Override
return depInfo;
}
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this).add("identifier", identifier).toString();
+ }
+
private static SourceIdentifier getSourceId(final YangModelDependencyInfo depInfo) {
final String name = depInfo.getName();
return depInfo.getFormattedRevision() == null ? RevisionSourceIdentifier.create(name)
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.repo;
+import static com.google.common.base.Preconditions.checkArgument;
+
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
this.context = Preconditions.checkNotNull(context);
}
+ /**
+ * Create a {@link YangStatementStreamSource} for a {@link YangTextSchemaSource}.
+ *
+ * @param source YangTextSchemaSource, must not be null
+ * @return A new {@link YangStatementStreamSource}
+ * @throws IOException When we fail to read the source
+ * @throws YangSyntaxErrorException If the source fails basic parsing
+ */
public static YangStatementStreamSource create(final YangTextSchemaSource source) throws IOException,
YangSyntaxErrorException {
final StatementContext context;
return new YangStatementStreamSource(source.getIdentifier(), parser, context);
}
+ /**
+ * Create a {@link YangStatementStreamSource} for a {@link ASTSchemaSource}.
+ *
+ * @param source YangTextSchemaSource, must not be null
+ * @return A new {@link YangStatementStreamSource}
+ */
+ public static YangStatementStreamSource create(final ASTSchemaSource source) {
+ final ParserRuleContext ast = source.getAST();
+ checkArgument(ast instanceof StatementContext,
+ "Unsupported context class %s for source %s", ast.getClass(), source.getIdentifier());
+ return create(source.getIdentifier(), (StatementContext) ast, source.getSymbolicName().orElse(null));
+ }
+
public static YangStatementStreamSource create(final SourceIdentifier identifier, final StatementContext context,
final String symbolicName) {
return new YangStatementStreamSource(identifier, new YangStatementParserListenerImpl(symbolicName), context);