本文整理汇总了C#中ParseTreeNode.TryGetChild方法的典型用法代码示例。如果您正苦于以下问题:C# ParseTreeNode.TryGetChild方法的具体用法?C# ParseTreeNode.TryGetChild怎么用?C# ParseTreeNode.TryGetChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTreeNode
的用法示例。
在下文中一共展示了ParseTreeNode.TryGetChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseUpdateStatement
private void ParseUpdateStatement(ParsedRequest parsedRequest, ParseTreeNode updateStmt)
{
// get FROM entity name
var updateEntityClause = updateStmt.RequireChild("Id", 1);
parsedRequest.TargetEntity = GetTargetEntity(updateEntityClause);
// preprocess identifiers
m_preprocessor.ProcessIdentifierAliases(updateStmt, parsedRequest.TargetEntity);
var ctx = GetTreeIteratorContext(parsedRequest, m_containerDescriptor);
ctx.Functor = FieldExtractor;
var assignListClause = updateStmt.RequireChild("assignList", 3);
foreach (var assignClause in assignListClause.ChildNodes)
{
var field = TryGetFieldByIdentifierNode(assignClause.RequireChild("Id", 0), m_containerDescriptor, parsedRequest.TargetEntity.DocumentType);
if (field == null)
{
throw new CompilationException("Attempting to SET an unknown field", assignClause);
}
if (parsedRequest.Modify.ModifiedFields.Contains(field))
{
throw new CompilationException("A field can be assigned by UPDATE only once: " + field.Name, null);
}
var expressionClause = assignClause.RequireChild(null, 2);
parsedRequest.Modify.ModifiedFields.Add(field);
parsedRequest.Modify.InsertUpdateSetClauses.Add(expressionClause);
// iterator callback will place all referenced column IDs into "select" list
// later on, "select" list is used along with "where" list to create driver fetch list
ctx.Argument = 1;
IterateTree(expressionClause, 0, ctx);
}
// get field names for where clause
var whereClause = updateStmt.TryGetChild("whereClauseOpt", 4);
ParseWhereClause(whereClause, ctx);
// get field names for order clause
ctx.ParsedRequest.BaseDataset.OrderClause = updateStmt.TryGetChild("orderList", 5, 2);
ParseOrderClause(ctx);
}
示例2: ParseDeleteStatement
private void ParseDeleteStatement(ParsedRequest parsedRequest, ParseTreeNode deleteStmt)
{
// get FROM entity name
var deleteFromClause = deleteStmt.RequireChild("Id", 2);
parsedRequest.TargetEntity = GetTargetEntity(deleteFromClause);
// preprocess identifiers
m_preprocessor.ProcessIdentifierAliases(deleteStmt, parsedRequest.TargetEntity);
var ctx = GetTreeIteratorContext(parsedRequest, m_containerDescriptor);
ctx.Functor = FieldExtractor;
// get field names for where clause
var whereClause = deleteStmt.TryGetChild("whereClauseOpt", 3);
ParseWhereClause(whereClause, ctx);
// get field names for order clause
ctx.ParsedRequest.BaseDataset.OrderClause = deleteStmt.TryGetChild("orderList", 4, 2);
ParseOrderClause(ctx);
}
示例3: ParseSelectStatement
private void ParseSelectStatement(ParsedRequest parsedRequest, ParseTreeNode selectStmt)
{
// get FROM entity name
var fromClause = selectStmt.RequireChild("fromClauseOpt", 4);
var fromEntityNode = fromClause.RequireChild("Id", 1, 0);
parsedRequest.TargetEntity = GetTargetEntity(fromEntityNode);
var ctx = GetTreeIteratorContext(parsedRequest, m_containerDescriptor);
ctx.Functor = FieldExtractor;
// get field names for select clause
var selectColumnItemList = selectStmt.TryGetChild(null, 2, 0);
if (selectColumnItemList == null)
{
throw new CompilationException("Could not find select clause", selectStmt);
}
if (0 == StringComparer.Ordinal.Compare("columnItemList", selectColumnItemList.Term.Name))
{
// iterator callback will place all referenced column IDs into "select" list
// later on, "select" list is used along with "where" list to create driver fetch list
ctx.Argument = 1;
foreach (var columnItem in selectColumnItemList.ChildNodes)
{
// column or column with alias
columnItem.RequireChildren(1, 2);
var columnSource = columnItem.RequireChild("columnSource", 0);
// store a reference to every column item and its alias,
// since we may need to compile it into an expression or do something else later
parsedRequest.Select.SelectClauses.Add(columnItem);
// preprocess identifiers
m_preprocessor.ProcessIdentifierAliases(columnSource, parsedRequest.TargetEntity);
// extract field names from a regular select clause (but do not look into "as" alias)
IterateTree(columnSource, 0, ctx);
}
}
else if (selectColumnItemList.ChildNodes.Count == 0 && selectColumnItemList.Token != null && "*".Equals(selectColumnItemList.Token.Text))
{
// they ask for all fields (wildcard)
// let's extract only unpacked blobs
var docTypeDescriptor = parsedRequest.TargetEntity;
foreach (var field in m_containerDescriptor.EnumerateFields().Where(x => x.OwnerDocumentType == docTypeDescriptor.DocumentType))
{
ctx.ParsedRequest.Select.SelectFields.Add(field);
ctx.ParsedRequest.Select.SelectClauses.Add(m_simpleFieldAccessorNodes[field.FieldId]);
}
}
else
{
throw new CompilationException("Must have list of columns or an asterisk in select clause", selectColumnItemList);
}
// get field names for where clause
var whereClause = selectStmt.TryGetChild("whereClauseOpt", 5);
ParseWhereClause(whereClause, ctx);
// get field names for order clause
ctx.ParsedRequest.BaseDataset.OrderClause = selectStmt.TryGetChild("orderList", 8, 2);
ParseOrderClause(ctx);
ReadPagingOptions(selectStmt, ctx.ParsedRequest);
}
示例4: OrderFieldExtractor
private static bool OrderFieldExtractor(TreeIteratorContext ctx, ParseTreeNode node)
{
if (0 == StringComparer.Ordinal.Compare(node.Term.Name, "orderMember"))
{
var idsimple = node.RequireChild("Id", 0).RequireChild("id_simple", 0);
var fieldName = idsimple.Token.ValueString;
var field = ctx.ContainerDescriptor.TryGetField(ctx.ParsedRequest.TargetEntity.DocumentType, fieldName);
if (field == null)
{
throw new CompilationException("Unknown field: " + fieldName, node);
}
var descOpt = node.TryGetChild(null, 1, 0);
var descending = descOpt != null;
if (descending)
{
if (0 == StringComparer.Ordinal.Compare(descOpt.Term.Name, "ASC"))
{
descending = false;
}
else if (0 != StringComparer.Ordinal.Compare(descOpt.Term.Name, "DESC"))
{
throw new CompilationException("Invalid sort order option: " + descOpt.Token.Text, descOpt);
}
}
if (ctx.ParsedRequest.BaseDataset.OrderClauseFields.Count > 0)
{
throw new CompilationException("Cannot sort by more than one field at this time", node);
}
if (0 <= ctx.ParsedRequest.BaseDataset.OrderClauseFields.FindIndex(x => x.Item1 == field.FieldId))
{
throw new CompilationException("Duplicate order field: " + field.Name, node);
}
ctx.ParsedRequest.BaseDataset.OrderClauseFields.Add(new Tuple<int, bool>(field.FieldId, descending));
// no need to traverse deeper into the Id non-terminal
return false;
}
return true;
}