Skip to content

Field Scraping support #936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/generators/Silk.NET.SilkTouch.Scraper/XmlVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,37 @@ public IEnumerable<Symbol> Visit(XmlNode node)
return VisitNamespace(@namespace);
case XmlElement { Name: "struct" } @struct:
return VisitStruct(@struct);
case XmlElement { Name: "field" } field:
return VisitField(field);
default:
{
throw new NotImplementedException();
}
}
}

private IEnumerable<Symbol> VisitField(XmlElement field)
{
var name = field.Attributes["name"]?.Value;
if (name is null)
{
throw new InvalidOperationException("Field requires a name");
}

var type = new StructSymbol
(
new IdentifierSymbol(
field.ChildNodes.Cast<XmlNode>().SingleOrDefault(x => x.Name == "type")?.InnerText ??
throw new InvalidOperationException("Could not decode Field Type")),
StructLayout.Empty
);

return new[]
{
new FieldSymbol(type, new IdentifierSymbol(name))
};
}

private IEnumerable<Symbol> VisitStruct(XmlElement @struct)
{
return new[]
Expand Down