Search in sources :

Example 1 with IRStatement

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement in project yangtools by opendaylight.

the class YangModelDependencyInfo method forIR.

/**
 * Extracts {@link YangModelDependencyInfo} from an intermediate representation root statement of a YANG model.
 *
 * @param source Source identifier
 * @param rootStatement root statement
 * @return {@link YangModelDependencyInfo}
 * @throws IllegalArgumentException If the root statement is not a valid YANG module/submodule
 */
@NonNull
static YangModelDependencyInfo forIR(final IRStatement rootStatement, final SourceIdentifier source) {
    final IRKeyword keyword = rootStatement.keyword();
    checkArgument(keyword instanceof Unqualified, "Invalid root statement %s", keyword);
    final String arg = keyword.identifier();
    if (MODULE.equals(arg)) {
        return parseModuleContext(rootStatement, source);
    }
    if (SUBMODULE.equals(arg)) {
        return parseSubmoduleContext(rootStatement, source);
    }
    throw new IllegalArgumentException("Root of parsed AST must be either module or submodule");
}
Also used : IRKeyword(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword) Unqualified(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword.Unqualified) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with IRStatement

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement in project yangtools by opendaylight.

the class YangModelDependencyInfo method parseImports.

private static ImmutableSet<ModuleImport> parseImports(final IRStatement module, final SourceIdentifier source) {
    final Set<ModuleImport> result = new HashSet<>();
    for (final IRStatement substatement : module.statements()) {
        if (isBuiltin(substatement, IMPORT)) {
            final String importedModuleName = safeStringArgument(source, substatement, "imported module name");
            final String revisionDateStr = getRevisionDateString(substatement, source);
            final Revision revisionDate = Revision.ofNullable(revisionDateStr).orElse(null);
            final SemVer importSemVer = findSemanticVersion(substatement, source);
            result.add(new ModuleImportImpl(importedModuleName, revisionDate, importSemVer));
        }
    }
    return ImmutableSet.copyOf(result);
}
Also used : IRStatement(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement) Revision(org.opendaylight.yangtools.yang.common.Revision) ModuleImport(org.opendaylight.yangtools.yang.model.api.ModuleImport) SemVer(org.opendaylight.yangtools.concepts.SemVer) HashSet(java.util.HashSet)

Example 3 with IRStatement

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement in project yangtools by opendaylight.

the class YangModelDependencyInfo method parseIncludes.

private static ImmutableSet<ModuleImport> parseIncludes(final IRStatement module, final SourceIdentifier source) {
    final Set<ModuleImport> result = new HashSet<>();
    for (final IRStatement substatement : module.statements()) {
        if (isBuiltin(substatement, INCLUDE)) {
            final String revisionDateStr = getRevisionDateString(substatement, source);
            final String IncludeModuleName = safeStringArgument(source, substatement, "included submodule name");
            final Revision revisionDate = Revision.ofNullable(revisionDateStr).orElse(null);
            result.add(new ModuleImportImpl(IncludeModuleName, revisionDate));
        }
    }
    return ImmutableSet.copyOf(result);
}
Also used : IRStatement(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement) Revision(org.opendaylight.yangtools.yang.common.Revision) ModuleImport(org.opendaylight.yangtools.yang.model.api.ModuleImport) HashSet(java.util.HashSet)

Example 4 with IRStatement

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement in project yangtools by opendaylight.

the class StatementContextVisitor method doProcessStatement.

// Actual processing
private boolean doProcessStatement(final IRStatement stmt, final StatementSourceReference ref) {
    int childOffset = 0;
    boolean fullyDefined = true;
    for (IRStatement substatement : stmt.statements()) {
        if (!processStatement(childOffset++, substatement)) {
            fullyDefined = false;
        }
    }
    writer.storeStatement(childOffset, fullyDefined);
    writer.endStatement(ref);
    return fullyDefined;
}
Also used : IRStatement(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement)

Example 5 with IRStatement

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement in project yangtools by opendaylight.

the class StatementContextVisitor method processNewStatement.

// Slow-path allocation of a new statement
private boolean processNewStatement(final int myOffset, final IRStatement stmt) {
    final StatementSourceReference ref = ExplicitStatement.atPosition(sourceName, stmt.startLine(), stmt.startColumn() + 1);
    final QName def = getValidStatementDefinition(stmt.keyword(), ref);
    if (def == null) {
        return false;
    }
    final IRArgument argumentCtx = stmt.argument();
    final String argument = argumentCtx == null ? null : utils.stringFromStringContext(argumentCtx, ref);
    writer.startStatement(myOffset, def, argument, ref);
    return doProcessStatement(stmt, ref);
}
Also used : IRArgument(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRArgument) StatementSourceReference(org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference) QName(org.opendaylight.yangtools.yang.common.QName)

Aggregations

IRStatement (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement)4 NonNull (org.eclipse.jdt.annotation.NonNull)3 HashSet (java.util.HashSet)2 Revision (org.opendaylight.yangtools.yang.common.Revision)2 ModuleImport (org.opendaylight.yangtools.yang.model.api.ModuleImport)2 IRArgument (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRArgument)2 Unqualified (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword.Unqualified)2 StatementSourceReference (org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference)2 Beta (com.google.common.annotations.Beta)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CharMatcher (com.google.common.base.CharMatcher)1 Verify.verify (com.google.common.base.Verify.verify)1 VerifyException (com.google.common.base.VerifyException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1