public static MetadataNode TryParseNode(SourceToken[] Tokens, ref int Index) { MetadataNode Node = null; if (Tokens[Index].IsIdentifier) { int NewIndex = Index + 1; // Check whether it has a value if (Tokens[NewIndex].Text == "=" || Tokens[NewIndex].Text == "(") { if (Tokens[NewIndex].Text == "=") { NewIndex++; } List <MetadataNode> NodeList = TryParseNodeList(Tokens, ref NewIndex); if (NodeList != null) { Node = new MetadataNode(Tokens[Index], NodeList); Index = NewIndex; } else if (Tokens[NewIndex].IsIdentifier || Tokens[NewIndex].IsLiteral) { Node = new MetadataNode(Tokens[Index], Tokens[NewIndex]); Index = NewIndex + 1; } } else { Node = new MetadataNode(Tokens[Index]); Index = NewIndex; } } else if (Tokens[Index].IsLiteral) { Node = new MetadataNode(Tokens[Index]); Index++; } return(Node); }
public static List <MetadataNode> TryParseNodeList(SourceToken[] Tokens, ref int Index) { List <MetadataNode> Nodes = null; if (Tokens[Index].Text == "(") { Nodes = new List <MetadataNode>(); int NewIndex = Index + 1; if (Tokens[NewIndex].Text != ")") { for (; ;) { // Read the next node MetadataNode Node = TryParseNode(Tokens, ref NewIndex); if (Node == null) { throw new NotImplementedException(); } // Append it to the list Nodes.Add(Node); // Read the next delimiting comma if (Tokens[NewIndex].Text == ")") { break; } if (Tokens[NewIndex].Text != ",") { throw new NotImplementedException(); } NewIndex++; } } Index = NewIndex + 1; } return(Nodes); }
public static MetadataNode TryParseNode(SourceToken[] Tokens, ref int Index) { MetadataNode Node = null; if(Tokens[Index].IsIdentifier) { int NewIndex = Index + 1; // Check whether it has a value if (Tokens[NewIndex].Text == "=" || Tokens[NewIndex].Text == "(") { if(Tokens[NewIndex].Text == "=") NewIndex++; List<MetadataNode> NodeList = TryParseNodeList(Tokens, ref NewIndex); if (NodeList != null) { Node = new MetadataNode(Tokens[Index], NodeList); Index = NewIndex; } else if(Tokens[NewIndex].IsIdentifier || Tokens[NewIndex].IsLiteral) { Node = new MetadataNode(Tokens[Index], Tokens[NewIndex]); Index = NewIndex + 1; } } else { Node = new MetadataNode(Tokens[Index]); Index = NewIndex; } } else if (Tokens[Index].IsLiteral) { Node = new MetadataNode(Tokens[Index]); Index++; } return Node; }