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");
}
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);
}
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);
}
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;
}
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);
}
Aggregations