本文整理汇总了C#中IParseTree类的典型用法代码示例。如果您正苦于以下问题:C# IParseTree类的具体用法?C# IParseTree怎么用?C# IParseTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IParseTree类属于命名空间,在下文中一共展示了IParseTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseTreePattern
/// <summary>
/// Construct a new instance of the
/// <see cref="ParseTreePattern"/>
/// class.
/// </summary>
/// <param name="matcher">
/// The
/// <see cref="ParseTreePatternMatcher"/>
/// which created this
/// tree pattern.
/// </param>
/// <param name="pattern">The tree pattern in concrete syntax form.</param>
/// <param name="patternRuleIndex">
/// The parser rule which serves as the root of the
/// tree pattern.
/// </param>
/// <param name="patternTree">
/// The tree pattern in
/// <see cref="Antlr4.Runtime.Tree.IParseTree"/>
/// form.
/// </param>
public ParseTreePattern(ParseTreePatternMatcher matcher, string pattern, int patternRuleIndex, IParseTree patternTree)
{
this.matcher = matcher;
this.patternRuleIndex = patternRuleIndex;
this.pattern = pattern;
this.patternTree = patternTree;
}
示例2: Evaluate
public override ICollection<IParseTree> Evaluate(IParseTree t)
{
if (invert)
{
return new List<IParseTree>();
}
// !* is weird but valid (empty)
return Trees.Descendants(t);
}
示例3: Descendants
public static IList<IParseTree> Descendants(IParseTree t)
{
List<IParseTree> nodes = new List<IParseTree>();
nodes.Add(t);
int n = t.ChildCount;
for (int i = 0; i < n; i++)
{
nodes.AddRange(Descendants(t.GetChild(i)));
}
return nodes;
}
示例4: Same
/// <summary>
/// Проверяет два синтаксических дерева на сходство, игнорируя вертикальные "цепочки" и скобки.
/// </summary>
public static bool Same(this IParseTree tree1, IParseTree tree2)
{
tree1 = tree1.Collapse();
tree2 = tree2.Collapse();
if (tree1.ChildCount == 0 || tree2.ChildCount == 0) return tree1.GetText() == tree2.GetText();
if (tree1.ChildCount != tree2.ChildCount) return false;
for (int i = 0; i < tree1.ChildCount; i++)
{
if (!tree1.GetChild(i).Same(tree2.GetChild(i))) return false;
}
return true;
}
示例5: Evaluate
public override ICollection<IParseTree> Evaluate(IParseTree t)
{
if (invert)
{
return new List<IParseTree>();
}
// !* is weird but valid (empty)
IList<IParseTree> kids = new List<IParseTree>();
foreach (ITree c in Trees.GetChildren(t))
{
kids.Add((IParseTree)c);
}
return kids;
}
示例6: VBComponentParseResult
public VBComponentParseResult(VBComponent component, IParseTree parseTree, IEnumerable<CommentNode> comments, ITokenStream tokenStream)
{
_component = component;
_qualifiedName = new QualifiedModuleName(component);
_parseTree = parseTree;
_comments = comments;
_tokenStream = tokenStream;
var listener = new DeclarationSymbolsListener(_qualifiedName, Accessibility.Implicit, _component.Type);
var walker = new ParseTreeWalker();
walker.Walk(listener, _parseTree);
_declarations.AddRange(listener.Declarations.Items);
}
示例7: GetFirstTerminalNode
// --- Get tokens in terminal nodes ---
public static ITerminalNode GetFirstTerminalNode(IParseTree node)
{
while (!(node is ITerminalNode))
{
if (node.ChildCount == 0)
{
return null;
}
else
{
node = node.GetChild(0);
}
}
return (ITerminalNode)node;
}
示例8: GetIntegerLiteral
public static long? GetIntegerLiteral(IParseTree node)
{
if (node != null)
{
ITerminalNode terminalNode = GetFirstTerminalNode(node);
if (terminalNode != null)
{
Token integerLiteralToken = GetTokenFromTerminalNode(terminalNode);
if (integerLiteralToken.TokenType == TokenType.IntegerLiteral)
{
return ((IntegerLiteralTokenValue)integerLiteralToken.LiteralValue).Number;
}
}
}
return null;
}
示例9: GetAlphanumericLiteral
public static string GetAlphanumericLiteral(IParseTree node)
{
if (node != null)
{
ITerminalNode terminalNode = GetFirstTerminalNode(node);
if (terminalNode != null)
{
Token alphaNumericLiteralToken = GetTokenFromTerminalNode(terminalNode);
if (alphaNumericLiteralToken.TokenFamily == TokenFamily.AlphanumericLiteral)
{
return ((AlphanumericLiteralTokenValue)alphaNumericLiteralToken.LiteralValue).Text;
}
}
}
return null;
}
示例10: Semantic
public Semantic(IParseTree root)
{
_root = root;
_listener = new DefinitionListener();
ParseTreeWalker.Default.Walk(_listener, root);
_errors.AddRange(_listener.Errors);
var resolvingListener = new ResolvingListener(this);
ParseTreeWalker.Default.Walk(resolvingListener, root);
_errors.AddRange(resolvingListener.Errors);
}
示例11: Evaluate
public override ICollection<IParseTree> Evaluate(IParseTree t)
{
// return all children of t that match nodeName
IList<IParseTree> nodes = new List<IParseTree>();
foreach (ITree c in Trees.GetChildren(t))
{
if (c is ParserRuleContext)
{
ParserRuleContext ctx = (ParserRuleContext)c;
if ((ctx.RuleIndex == ruleIndex && !invert) || (ctx.RuleIndex != ruleIndex && invert))
{
nodes.Add(ctx);
}
}
}
return nodes;
}
示例12: Evaluate
public override ICollection<IParseTree> Evaluate(IParseTree t)
{
// return all children of t that match nodeName
IList<IParseTree> nodes = new List<IParseTree>();
foreach (ITree c in Trees.GetChildren(t))
{
if (c is ITerminalNode)
{
ITerminalNode tnode = (ITerminalNode)c;
if ((tnode.Symbol.Type == tokenType && !invert) || (tnode.Symbol.Type != tokenType && invert))
{
nodes.Add(tnode);
}
}
}
return nodes;
}
示例13: MapToMessage
/// <summary>
/// Mapira na Message
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public static Message MapToMessage(IParseTree node)
{
log.Debug("Mapper:MapToMessage");
try
{
MessageId message_id = node.GetNodes()[0].GetNodes()[10].GetValue();
if (message_id != "None")
{
Message message = Message.Create(message_id);
int i = 0;
bool result_record_processing = false;
foreach (IParseTree item in node.GetNodes())
{
Record record = MapToRecord(item);
if (record.Type == RecordId.ResultRecord)
{
result_record_processing = true;
((Results)message[i]).ResultComment.Add(new ResultCommentPair() { Result = (ResultRecord)record });
}
else if (record.Type == RecordId.CommentRecord)
{
result_record_processing = true;
((Results)message[i]).ResultComment[((Results)message[i]).ResultComment.Count - 1].Comment = (CommentRecord)record;
}
else
{
if (result_record_processing == true)
i++;
message[i++] = record;
result_record_processing = false;
}
}
return message;
}
return null;
}
catch (Exception ex)
{
log.Error(ex.ToString());
throw;
}
}
示例14: Populate
public static void Populate(TreeView treeview, IParseTree parsetree)
{
treeview.Visible = false;
treeview.SuspendLayout();
treeview.Nodes.Clear();
treeview.Tag = parsetree;
IParseNode start = parsetree.INodes[0];
TreeNode node = new TreeNode(start.Text);
node.Tag = start;
node.ForeColor = Color.SteelBlue;
treeview.Nodes.Add(node);
PopulateNode(node, start);
treeview.ExpandAll();
treeview.ResumeLayout();
treeview.Visible = true;
}
示例15: GetFirstToken
public static Token GetFirstToken(IParseTree node)
{
if (node != null)
{
ITerminalNode terminalNode = GetFirstTerminalNode(node);
if (terminalNode != null)
{
return GetTokenFromTerminalNode(terminalNode);
}
else
{
return null;
}
}
else
{
return null;
}
}