// todo: this is realy curde ... rewrite this and do tests
        public static InternalGraph.AstGraph ParseGumTreeOutToGraph(string toParse)
        {
            var result = new InternalGraph.AstGraph();

            var lines = toParse.Split('\n');

            foreach (var l in lines)
            {
                if (String.IsNullOrWhiteSpace(l))
                {
                    continue;
                }
                var parts = l.Trim().Split(' ');
                if (parts[0] != "file")
                {
                    continue;
                }

                if (parts[1].Equals("n"))
                {
                    // node
                    // file n 63 51 - 355 class
                    int    id    = int.Parse(parts[2]);
                    int    start = int.Parse(parts[3]);
                    int    end   = int.Parse(parts[5]);
                    string type  = parts[6];

                    var node = new AstElement()
                    {
                        AstId = id, Start = start, End = end, Type = type
                    };
                    result.AddNode(node);
                    continue;
                }

                if (parts[1].Equals("e"))
                {
                    //file e 61 -> 34
                    int from = int.Parse(parts[2]);
                    int to   = int.Parse(parts[4]);

                    var edge = new Edge()
                    {
                        From = from, To = to
                    };
                    result.AddEdge(edge);
                    continue;
                }

                Console.WriteLine("could not pares line " + l);
            }

            return(result);
        }
Exemple #2
0
        /**
         * @param patternFile
         * @throws Exception
         */
        internal AstBuilder(string patternFile, string outputFile)
        {
            root = new AstDocumentElement(outputFile);

            string[] file = File.ReadAllLines(patternFile);

            foreach (string s in file)
            {
                String trimmed = s.Trim();

                if (trimmed.StartsWith("//"))               //Kommentar
                {
                    continue;
                }
                if (string.IsNullOrEmpty(trimmed))               //leere Zeilen ignorieren
                {
                    continue;
                }

                int deepness = countLeadingSpaces(s) / 4;

                AstElement l = getOfLine(deepness, trimmed);

                if (deepness == 0)
                {
                    root.addChild(l);
                }
                else
                {
                    AstElement step = root.getLastChild();
                    for (int i = 1; i < deepness; i++)
                    {
                        AstElement stepCheck = step.getLastChild();
                        if (stepCheck != null)
                        {
                            step = stepCheck;
                        }
                        else
                        {
                            Console.Error.WriteLine("Fehler bei Einrückung: " + s);
                        }
                    }
                    step.addChild(l);
                }
            }
        }
Exemple #3
0
 internal void AddNode(AstElement node)
 {
     this.nodes.Add(node);
 }
Exemple #4
0
 protected BridgeBase(IToken t, AstElement element)
     : base(t)
 {
     Element = element;
 }
Exemple #5
0
 private CodeDomArgs VisitChild(AstElement node)
 {
     return(VisitChild(node, new CodeDomArgs()));
 }
Exemple #6
0
 private CodeDomArgs VisitChild(AstElement node, CodeDomArgs arg)
 {
     _codeStack.Push(arg);
     node.Accept(this);
     return(_codeStack.Pop());
 }
Exemple #7
0
 public CodeGenVisitor(AstElement program)
 {
     _program   = program;
     _codeStack = new Stack <CodeDomArgs>();
     _unit      = new CodeCompileUnit();
 }
        public static ICypherFluentQuery MatchQuerry(this ICypherFluentQuery cypher, string varialbeName, AstElement node)
        {
            string matchClause = "(" + varialbeName + ":" + node.GetType().Name + ")";

            var wherClause = new List <String>();

            if (node.AstId > -1)
            {
                wherClause.Add(varialbeName + "." + nameof(node.AstId) + "=" + node.AstId);
            }

            if (!String.IsNullOrWhiteSpace(node.FilePath))
            {
                wherClause.Add(varialbeName + "." + nameof(node.FilePath) + "=\"" + node.FilePath + "\"");
            }

            if (!String.IsNullOrWhiteSpace(node.CommitSha))
            {
                wherClause.Add(varialbeName + "." + nameof(node.CommitSha) + "=\"" + node.CommitSha + "\"");
            }
            return(cypher.Match(matchClause).Where(String.Join(" and ", wherClause)));
        }