本文整理汇总了C#中Irony.Ast.AstContext类的典型用法代码示例。如果您正苦于以下问题:C# AstContext类的具体用法?C# AstContext怎么用?C# AstContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AstContext类属于Irony.Ast命名空间,在下文中一共展示了AstContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitNode
/// <summary>
/// Converts identifiers to compound symbols (strings in double quotes),
/// expands character strings (in single quotes) to arrays of characters
/// </summary>
public static void InitNode(AstContext context, ParseTreeNode parseNode)
{
foreach (var node in parseNode.ChildNodes)
{
if (node.AstNode is LiteralValueNode)
{
if (node.Term.Name == "Char")
{
var literal = node.AstNode as LiteralValueNode;
literal.Value = literal.Value.ToString().ToCharArray();
}
parseNode.AstNode = node.AstNode;
}
else
{
// identifiers in expressions are treated as strings (True is same as "True")
parseNode.AstNode = new LiteralValueNode()
{
Value = node.FindTokenAndGetText(),
Span = node.Span
};
}
}
}
示例2: Init
/// <summary>Initializes the current AST node with the specified <paramref name="context" /> and <paramref name="treeNode" />.</summary>
/// <param name="context">The AST context.</param>
/// <param name="treeNode">The parse tree node associated with the current AST node.</param>
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
AsString=treeNode.ChildNodes[0].Token.Text;
_GeometryType=(GeometryType)Enum.Parse(typeof(GeometryType), AsString, true);
}
示例3: Init
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
Text = treeNode.Token.Text;
AsString = "StringValue";
}
示例4: Init
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
AstNode sn=AddChild("from", treeNode.ChildNodes[0]);
AstNode en=AddChild("to", treeNode.ChildNodes[2]);
var dtsn=sn as DateTimeLiteralNode;
var dten=en as DateTimeLiteralNode;
if (dtsn!=null)
{
_StartDate=dtsn.Value;
if (dten!=null)
_EndDate=dten.Value;
else
_EndDate=_StartDate+((DurationLiteralNode)en).Value;
} else
{
_EndDate=dten.Value;
_StartDate=_EndDate-((DurationLiteralNode)sn).Value;
}
AsString="period";
}
示例5: Init
// this is where data is initially passed to the item
public override void Init(AstContext context, ParseTreeNode treeNode)
{
string sVal = treeNode.FindTokenAndGetText();
base.Init(context, treeNode);
var nodes = treeNode.GetMappedChildNodes();
var functionOrProperty = AddChild("FunctionOrId", nodes[0]);
if (functionOrProperty is SelectFunctionNode)
{
_TheFunction = (SelectFunctionNode)functionOrProperty;
}
else if (functionOrProperty is SelectPropertyNode)
{
_PropNode = (SelectPropertyNode)functionOrProperty;
}
else
{
throw new Exception("Unmanaged type in selectmemberaccessnode");
}
if (nodes.Count > 1)
{
var child = AddChild("Queue", nodes[1]);
string sval = nodes[1].FindTokenAndGetText();
if (child is LeftObjectNode)
{
_queue = (LeftObjectNode)child;
}
}
}
示例6: Init
public override void Init(AstContext context, ParseTreeNode treeNode) {
base.Init(context, treeNode);
var nodes = treeNode.GetMappedChildNodes();
_target = AddChild("Target", nodes.First());
_index = AddChild("Index", nodes.Last());
AsString = "[" + _index + "]";
}
示例7: Init
public override void Init(AstContext context, ParseTreeNode treeNode) {
base.Init(context, treeNode);
foreach (var child in treeNode.ChildNodes) {
AddChild(NodeUseType.Parameter, "expr", child);
}
AsString = "Expression list";
}
示例8: Init
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
foreach (var node in treeNode.ChildNodes)
{
// linearize AuxiliaryNode children
if (node.AstNode is AuxiliaryNode)
{
var auxNode = node.AstNode as AuxiliaryNode;
foreach (var n in auxNode.ChildNodes)
ChildNodes.Add(n);
foreach (var n in auxNode.ChildParseNodes)
ChildParseNodes.Add(n);
continue;
}
// copy AstNode nodes
if (node.AstNode is AstNode)
{
ChildNodes.Add(node.AstNode as AstNode);
continue;
}
// otherwise, save parse nodes
ChildParseNodes.Add(node);
}
}
示例9: Init
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
var node = treeNode.GetMappedChildNodes()[0];
this.Label = node.Token.ValueString;
}
示例10: Init
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
var term = TerminalFactory.CreateCSharpIdentifier("text");
var tok = new Token(term, Location, "text", System.String.Join("_", treeNode.ChildNodes.Select(cn => cn.Term.Name)));
treeNode.Token = tok;
}
示例11: Init
public override void Init(AstContext context, ParseTreeNode parseNode)
{
base.Init(context, parseNode);
foreach (var node in parseNode.ChildNodes)
{
if (node.AstNode is Expression)
{
Expression = (node.AstNode as Expression);
}
else if (node.AstNode is AuxiliaryNode)
{
var nodes = (node.AstNode as AuxiliaryNode).ChildNodes;
Pattern = nodes.OfType<Pattern>().FirstOrDefault();
Block = nodes.OfType<Block>().FirstOrDefault();
MoreConditions = nodes.OfType<Conditions>().FirstOrDefault();
ResultExpression = nodes.OfType<Expression>().FirstOrDefault();
}
foreach (var astNode in new AstNode[] { Expression, Pattern, Block, MoreConditions, ResultExpression })
{
if (astNode != null)
astNode.Parent = this;
}
}
AsString = Block != null ? "with-clause" : "where-clause";
}
示例12: Init
public override void Init(AstContext context, ParseTreeNode parseNode)
{
base.Init(context, parseNode);
foreach (var node in parseNode.ChildNodes)
{
if (node.AstNode is Function)
{
AddFunction(node.AstNode as Function);
}
else if (node.AstNode is AuxiliaryNode)
{
var ids = (node.AstNode as AuxiliaryNode).ChildNodes.OfType<IdentifierNode>();
foreach (var id in ids)
{
ExternalFunction ef = new ExternalFunction();
ef.SetSpan(id.Span);
ef.Name = id.Symbol;
AddFunction(ef);
}
}
}
AsString = "Refal-5 program";
}
示例13: Init
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
foreach (var child in treeNode.ChildNodes)
AddChild(NodeUseType.Parameter, "param", child);
AsString = "param_list[" + ChildNodes.Count + "]";
}
示例14: Init
public override void Init(AstContext context, ParseTreeNode treeNode) {
base.Init(context, treeNode);
Value = treeNode.Token.Value;
AsString = Value == null ? "null" : Value.ToString();
if (Value is string)
AsString = "\"" + AsString + "\"";
}
示例15: InitImpl
private void InitImpl(AstContext context, ParseTreeNode parseNode, ParseTreeNode parametersNode, ParseTreeNode bodyNode) {
base.Init(context, parseNode);
Parameters = AddChild("Parameters", parametersNode);
Body = AddChild("Body", bodyNode);
AsString = "Lambda[" + Parameters.ChildNodes.Count + "]";
Body.SetIsTail(); //this will be propagated to the last statement
}