当前位置: 首页>>代码示例>>C#>>正文


C# CstNode类代码示例

本文整理汇总了C#中CstNode的典型用法代码示例。如果您正苦于以下问题:C# CstNode类的具体用法?C# CstNode怎么用?C# CstNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CstNode类属于命名空间,在下文中一共展示了CstNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConstructAcceptingFragments

        /// <summary>
        /// Update SurroundingRange, TargetRange, and Node properties then return the last index of the code processed.
        /// </summary>
        /// <param name="structuredCode">The structured code processed</param>
        /// <param name="cst">The concrete syntax tree</param>
        /// <param name="fragments"></param>
        /// <returns>The updated last index of the code processed</returns>
        public static List<SeedNode> ConstructAcceptingFragments(StructuredCode structuredCode, CstNode cst, IList<SelectedFragment> fragments) {
            var seedNodes = CreateSeedNodes(structuredCode, cst, fragments);

            var uppermostSeedAcceptedNodes = seedNodes
                    .Select(node => node.Node.AncestorWithSingleChild())
                    .ToImmutableHashSet();
            // We can select multiple nodes in corresponding to a fragment selected by a user
            // and it means that we have multiple choices for selecting node names to filter nodes
            // This code tries to select good node names to not filter nodes wanted by a user
            var selectedNodeNames = LearningExperimentUtil.FindGoodNodeNames(uppermostSeedAcceptedNodes)
                    .ToImmutableHashSet();
            foreach (var seedNode in seedNodes) {
                // Update the node in corresponding to the selected node names keeping the code range of the node
                seedNode.Node = seedNode.Node.DescendantsOfSingleAndSelf()
                        .First(e => selectedNodeNames.Contains(e.Name));
                var rootNode = seedNode.SurroundingRange.FindInnermostNode(cst);
                var node = seedNode.Node;
                var path = node.Name;
                while ((node = node.Parent) != rootNode) {
                    path = path + "<" + node.Name + node.RuleId;
                }
                seedNode.Path = path;
            }
            return seedNodes;
        }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:32,代码来源:SelectedFragment.cs

示例2: Create

 public void Create(CstNode parent, IToken token, string id) {
     if (token != null) {
         var count = token.TokenIndex;
         var tokenName = DetermineElementName(token, Code2XmlConstants.TokenSetElementName);
         var node = CreateTerminalNode(tokenName, token, token.Text, count, id);
         parent.AddLast(node);
         _nextTokenIndex = count + 1;
     }
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:9,代码来源:CstBuilderForAntlr3.cs

示例3: ExtractRange2Elements

 public Dictionary<CodeRange, CstNode> ExtractRange2Elements(CstNode ast) {
     var elements = ExtractElements(ast);
     // Elements having the same range can appear so can't use ToDictiornary
     var ret = new Dictionary<CodeRange, CstNode>();
     foreach (var element in elements) {
         var range = CodeRange.Locate(element);
         ret[range] = element;
     }
     return ret;
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:10,代码来源:ExtractingRule.cs

示例4: ExtractElements

 public IEnumerable<CstNode> ExtractElements(CstNode ast) {
     foreach (var nameAndRules in FilterDictionary) {
         var elements = ast.DescendantsAndSelf(nameAndRules.Key);
         var rules = nameAndRules.Value;
         var results = elements.Where(e => rules.All(rule => rule.IsAcceptable(e)));
         foreach (var result in results) {
             yield return result;
         }
     }
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:10,代码来源:ExtractingRule.cs

示例5: FinishParsing

 public CstNode FinishParsing(CstNode root) {
     var count = _stream.Count - 1; // Avoid writing "<EOF>"
     while (count > 0 && _stream.Get(count - 1).Type < 0) {
         count--;
     }
     var antlrToken = _stream.Get(count);
     var token = CreateTerminalNode(
             Code2XmlConstants.EofTokenName, antlrToken, string.Empty, count,
             Code2XmlConstants.EofRuleId);
     root.AddLast(token);
     return root;
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:12,代码来源:CstBuilderForAntlr3.cs

示例6: CreateSeedNodes

 private static List<SeedNode> CreateSeedNodes(StructuredCode structuredCode, CstNode cst, IEnumerable<SelectedFragment> fragments) {
     var lastIndex = -1;
     return fragments.Select(fragment => {
         var startLineIndex = Math.Max(lastIndex + 1, structuredCode.GetIndex(fragment.StartLine, 0));
         var surroundingIndex = structuredCode.Code.IndexOf(fragment.SurroundingText, startLineIndex);
         var targetIndex = structuredCode.Code.IndexOf(fragment.TargetText, surroundingIndex);
         if (surroundingIndex < 0 || targetIndex < 0) {
             throw new Exception("The selected code fragment is invalid.");
         }
         var surroundingRange = structuredCode.GetRange(surroundingIndex,
                 surroundingIndex + fragment.SurroundingText.Length);
         var targetRange = structuredCode.GetRange(targetIndex,
                 targetIndex + fragment.TargetText.Length);
         var node = targetRange.FindOutermostNode(cst);
         lastIndex = surroundingIndex;
         return new SeedNode(node, targetRange, surroundingRange);
     }).ToList();
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:18,代码来源:SelectedFragment.cs

示例7: ProtectedIsAcceptedUsingOracle

 public override bool ProtectedIsAcceptedUsingOracle(CstNode node) {
     var p = node.Parent;
     var pp = p.Parent;
     var isPar = p.SafeName() == "parExpression";
     var isStmt = pp.SafeName() == "statement";
     if (isStmt && isPar && pp.FirstChild.SafeTokenText() == "if") {
         return node.TokenText != "true";
     }
     if (isStmt && isPar && pp.FirstChild.SafeTokenText() == "while") {
         return node.TokenText != "true";
     }
     if (isStmt && isPar && pp.FirstChild.SafeTokenText() == "do") {
         return node.TokenText != "true";
     }
     if (p.SafeName() == "forstatement"
         && p.Children().Count(e2 => e2.TokenText == ";") >= 2) {
         return node.TokenText != "true";
     }
     if (isStmt && isPar && pp.FirstChild.SafeTokenText() == "switch") {
         return true;
     }
     if (node.Name == "switchLabel") {
         return true;
     }
     {
         var primary = node.SafeParent().SafeParent().SafeParent().SafeParent();
         if (primary.SafeName() != "primary") {
             return false;
         }
         if (primary.Children().All(e2 => e2.TokenText != "checkArgument")) {
             return false;
         }
         if (node.PrevsFromFirst().Any()) {
             return false;
         }
         return node.TokenText != "true";
     }
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:38,代码来源:JavaExperiment.cs

示例8: IsLabeledStatement

 public bool IsLabeledStatement(CstNode e) {
     // LABEL: should_be_ignored();
     return e.FirstChild.Name == "IDENTIFIER";
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:4,代码来源:JavaExperiment.cs

示例9: IsBlockStatement

 public bool IsBlockStatement(CstNode e) {
     // { int value = 0; }
     return e.FirstChild.Name == "block";
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:4,代码来源:JavaExperiment.cs

示例10: IsVariableDeclaration

 public bool IsVariableDeclaration(CstNode e) {
     // int value = 0;
     return e.FirstChild.Name == "localVariableDeclarationStatement";
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:4,代码来源:JavaExperiment.cs

示例11: ConvertIndiciesToRange

        private static void ConvertIndiciesToRange(
                CstNode node, string code, int inclusiveStart, int exclusiveEnd, CodeRange range) {
            var newRange = CodeRange.ConvertFromIndicies(code, inclusiveStart, exclusiveEnd);
            var newInclusiveStart = char.IsWhiteSpace(code[inclusiveStart - 1])
                    ? inclusiveStart - 1 : inclusiveStart;
            var newExclusiveEnd = char.IsWhiteSpace(code[exclusiveEnd])
                    ? exclusiveEnd + 1 : exclusiveEnd;
            var elem = CodeRange.ConvertFromIndiciesSkippingWhitespaces(
                    code, ref newInclusiveStart, ref newExclusiveEnd)
                    .FindInnermostNode(node);
            Assert.That(CodeRange.Locate(elem), Is.EqualTo(newRange));

            newRange.ConvertToIndicies(code, out newInclusiveStart, out newExclusiveEnd);
            Assert.That(newRange, Is.EqualTo(range));
            Assert.That(newInclusiveStart, Is.EqualTo(inclusiveStart));
            Assert.That(newExclusiveEnd, Is.EqualTo(exclusiveEnd));

            var scode = new StructuredCode(code);
            Assert.That(
                    CodeRange.ConvertFromIndicies(scode, inclusiveStart, exclusiveEnd),
                    Is.EqualTo(range));
            newRange.ConvertToIndicies(scode, out newInclusiveStart, out newExclusiveEnd);
            Assert.That(newInclusiveStart, Is.EqualTo(inclusiveStart));
            Assert.That(newExclusiveEnd, Is.EqualTo(exclusiveEnd));
        }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:25,代码来源:CodeRangeTest.cs

示例12: ConvertRangeToIndicies

        private static CodeRange ConvertRangeToIndicies(
                string code, CstNode node, out int inclusiveStart, out int exclusiveEnd) {
            var range = CodeRange.Locate(node);
            range.ConvertToIndicies(code, out inclusiveStart, out exclusiveEnd);
            Assert.That(
                    code.Substring(inclusiveStart, exclusiveEnd - inclusiveStart),
                    Is.EqualTo(node.Code.Trim()));

            range.ConvertToIndicies(new StructuredCode(code), out inclusiveStart, out exclusiveEnd);
            Assert.That(
                    code.Substring(inclusiveStart, exclusiveEnd - inclusiveStart),
                    Is.EqualTo(node.Code.Trim()));
            return range;
        }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:14,代码来源:CodeRangeTest.cs

示例13: listVariables

	private CstNode listVariables()
	{
		EnterRule_listVariables();
		EnterRule("listVariables", 43);
		var retval = new CstNode("listVariables");
		
		var retval_Start = (IToken)input.LT(1);
		int listVariables_StartIndex = input.Index;

		object root_0 = default(object);

		IToken List299 = default(IToken);
		IToken OpenRoundBracket300 = default(IToken);
		IToken char_literal302 = default(IToken);
		IToken CloseRoundBracket304 = default(IToken);
		CstNode name301 = default(CstNode);
		CstNode name303 = default(CstNode);
		CstNode name305 = default(CstNode);

		object List299_tree = default(object);
		object OpenRoundBracket300_tree = default(object);
		object char_literal302_tree = default(object);
		object CloseRoundBracket304_tree = default(object);
		try { DebugEnterRule(GrammarFileName, "listVariables");
		DebugLocation(305, 1);
		try
		{
			if (state.backtracking > 0 && AlreadyParsedRule(input, 43)) { return retval; }

			// C:\\Users\\exKAZUu\\Projects\\Code2Xml\\Code2Xml.Core\\Generators\\ANTLRv3\\Php\\Php.g:306:2: ( List OpenRoundBracket ( name )? ( ',' ( name )? )* CloseRoundBracket | name )
			int alt86=2;
			try { DebugEnterDecision(86, false);
			int LA86_1 = input.LA(1);

			if ((LA86_1==List))
			{
				int LA86_2 = input.LA(2);

				if ((EvaluatePredicate(synpred125_Php_fragment)))
				{
					alt86 = 1;
				}
				else if ((true))
				{
					alt86 = 2;
				}
				else
				{
					if (state.backtracking>0) {state.failed=true; return retval;}
					NoViableAltException nvae = new NoViableAltException("", 86, 1, input, 2);
					DebugRecognitionException(nvae);
					throw nvae;
				}
			}
			else if ((LA86_1==Abstract||LA86_1==And||LA86_1==As||(LA86_1>=BoolType && LA86_1<=Class)||LA86_1==Clone||(LA86_1>=Const && LA86_1<=Continue)||(LA86_1>=Default && LA86_1<=Die)||LA86_1==Do||(LA86_1>=DoubleType && LA86_1<=Empty)||(LA86_1>=Eval && LA86_1<=Exit)||(LA86_1>=Extends && LA86_1<=Foreach)||(LA86_1>=Function && LA86_1<=HaltCompiler)||(LA86_1>=If && LA86_1<=IncludeOnce)||(LA86_1>=Instanceof && LA86_1<=IntType)||(LA86_1>=IntegerType && LA86_1<=Isset)||(LA86_1>=Namespace && LA86_1<=Null)||LA86_1==ObjectType||LA86_1==Or||(LA86_1>=Print && LA86_1<=Public)||(LA86_1>=RealType && LA86_1<=Return)||(LA86_1>=Static && LA86_1<=StringType)||(LA86_1>=Switch && LA86_1<=Throw)||(LA86_1>=True && LA86_1<=Try)||LA86_1==UnquotedString||(LA86_1>=Use && LA86_1<=While)||(LA86_1>=Xor && LA86_1<=131)))
			{
				alt86 = 2;
			}
			else
			{
				if (state.backtracking>0) {state.failed=true; return retval;}
				NoViableAltException nvae = new NoViableAltException("", 86, 0, input, 1);
				DebugRecognitionException(nvae);
				throw nvae;
			}
			} finally { DebugExitDecision(86); }
			switch (alt86)
			{
			case 1:
				DebugEnterAlt(1);
				// C:\\Users\\exKAZUu\\Projects\\Code2Xml\\Code2Xml.Core\\Generators\\ANTLRv3\\Php\\Php.g:306:4: List OpenRoundBracket ( name )? ( ',' ( name )? )* CloseRoundBracket
				{
				

				DebugLocation(306, 4);
				List299=(IToken)Match(input,List,Follow._List_in_listVariables1648); if (state.failed) return retval;
				if (state.backtracking == 0) {
adaptor.Create(retval, List299, "List299");
				
				}
				DebugLocation(306, 9);
				OpenRoundBracket300=(IToken)Match(input,OpenRoundBracket,Follow._OpenRoundBracket_in_listVariables1650); if (state.failed) return retval;
				if (state.backtracking == 0) {
adaptor.Create(retval, OpenRoundBracket300, "OpenRoundBracket300");
				
				}
				DebugLocation(306, 26);
				// C:\\Users\\exKAZUu\\Projects\\Code2Xml\\Code2Xml.Core\\Generators\\ANTLRv3\\Php\\Php.g:306:26: ( name )?
				int alt83=2;
				try { DebugEnterSubRule(83);
				try { DebugEnterDecision(83, false);
				int LA83_1 = input.LA(1);

				if ((LA83_1==Abstract||LA83_1==And||LA83_1==As||(LA83_1>=BoolType && LA83_1<=Class)||LA83_1==Clone||(LA83_1>=Const && LA83_1<=Continue)||(LA83_1>=Default && LA83_1<=Die)||LA83_1==Do||(LA83_1>=DoubleType && LA83_1<=Empty)||(LA83_1>=Eval && LA83_1<=Exit)||(LA83_1>=Extends && LA83_1<=Foreach)||(LA83_1>=Function && LA83_1<=HaltCompiler)||(LA83_1>=If && LA83_1<=IncludeOnce)||(LA83_1>=Instanceof && LA83_1<=IntType)||(LA83_1>=IntegerType && LA83_1<=List)||(LA83_1>=Namespace && LA83_1<=Null)||LA83_1==ObjectType||LA83_1==Or||(LA83_1>=Print && LA83_1<=Public)||(LA83_1>=RealType && LA83_1<=Return)||(LA83_1>=Static && LA83_1<=StringType)||(LA83_1>=Switch && LA83_1<=Throw)||(LA83_1>=True && LA83_1<=Try)||LA83_1==UnquotedString||(LA83_1>=Use && LA83_1<=While)||(LA83_1>=Xor && LA83_1<=131)))
				{
					alt83 = 1;
				}
				} finally { DebugExitDecision(83); }
				switch (alt83)
				{
//.........这里部分代码省略.........
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:101,代码来源:PhpParser.cs

示例14: IsCheckArgument

 public bool IsCheckArgument(CstNode e) {
     // Preconditions.checkArgument(cond, msg);
     var primary = e.Parent.Parent.Parent.Parent;
     return primary.Name == "primary"
            && primary.Children().Any(e2 => e2.TokenText == "checkArgument")
            && !e.PrevsFromFirst().Any();
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:7,代码来源:JavaExperiment.cs

示例15: SelectStatements

        /*
blockStatement 
    : localVariableDeclarationStatement
    | classOrInterfaceDeclaration
    | statement
    ;
statement 
    : block
    | ';'
    | IDENTIFIER ':' statement
	| expression ';'
    | ... (snip) ...
	;
		 */

        public IEnumerable<CstNode> SelectStatements(CstNode e) {
            var blockStatements = e.Descendants("blockStatement")
                    .Where(e_ => IsVariableDeclaration(e_) || IsClassDeclaration(e_));
            var statements = e.Descendants("statement")
                    .Where(
                            e_ =>
                                    !IsBlockStatement(e_) && !IsEmptyStatement(e_)
                                    && !IsLabeledStatement(e_));
            return blockStatements.Concat(statements);
        }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:25,代码来源:JavaExperiment.cs


注:本文中的CstNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。