public CtfMetadataDeclaration(CtfDeclarationTypes declaration, CtfPropertyBag bag, string name, string text) { Definition = declaration; Properties = bag; Name = name; RawText = text; Debug.Assert(name == null || name == name.Trim()); }
public CtfMetadataDeclaration(CtfDeclarationTypes declaration, CtfMetadataType type, string name, string text) { Definition = declaration; Type = type; Name = name; RawText = text; Debug.Assert(name == null || name == name.Trim()); }
private CtfMetadataDeclaration ParseOneDeclaration(string metadata, int index, out int end) { end = -1; int open = metadata.IndexOf('{', index); if (open == -1) { return(null); } int start = metadata.Substring(0, open).LastIndexOf('\n') + 1; if (start == 0) { return(null); } CtfDeclarationTypes directive = CtfDeclarationTypes.Unknown; string[] directiveElements = metadata.Substring(start, open - start).Trim().Split(' '); string directiveString = directiveElements[0]; string name = null; switch (directiveString) { case "trace": directive = CtfDeclarationTypes.Trace; break; case "typealias": directive = CtfDeclarationTypes.TypeAlias; int closeBrace = FindCloseBrace(metadata, open) + 1; CtfPropertyBag bag = GetPropertyBag(metadata, open, closeBrace); CtfMetadataType t = null; switch (directiveElements[1]) { case "integer": t = new CtfInteger(bag); break; default: throw new IOException(); } int colonEquals = metadata.IndexOf(":=", closeBrace) + 2; int semi = colonEquals; while (metadata[++semi] != ';') { ; } name = metadata.Substring(colonEquals, semi - colonEquals).Trim(); end = semi + 1; return(new CtfMetadataDeclaration(CtfDeclarationTypes.TypeAlias, t, name, directiveElements[1])); case "env": directive = CtfDeclarationTypes.Environment; break; case "clock": directive = CtfDeclarationTypes.Clock; break; case "struct": directive = CtfDeclarationTypes.Struct; name = directiveElements[1]; break; case "stream": directive = CtfDeclarationTypes.Stream; break; case "event": directive = CtfDeclarationTypes.Event; break; default: break; } int close = FindCloseBrace(metadata, open); int curr = close; while (metadata[curr++] != ';') { ; } int nameStart = metadata.IndexOf(":=", close); if (name == null && nameStart != -1 && nameStart < curr) { nameStart += 2; // move past := name = metadata.Substring(nameStart, curr - nameStart - 1).Trim(); } Debug.Assert(metadata[open] == '{'); Debug.Assert(metadata[close] == '}'); end = curr; if (directive == CtfDeclarationTypes.Struct) { CtfPropertyBag bag = null; Match match = s_align.Match(metadata, close, end - close); if (match.Success) { bag = new CtfPropertyBag(); bag.AddValue("align", match.Groups[1].ToString()); } CtfField[] fields = ParseStructFields(metadata, open, close).ToArray(); return(new CtfMetadataDeclaration(directive, bag, fields, name, metadata.Substring(index, curr - index))); } else { CtfPropertyBag properties = GetPropertyBag(metadata, open, close); return(new CtfMetadataDeclaration(directive, properties, name, metadata.Substring(index, curr - index))); } }