Пример #1
0
        public InterfaceData ExtractInterface(string code)
        {
            var lines = code
                        .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
                        .SelectMany(line => line.Split('\r', '\n'))
                        .ToList();

            while (lines.Count > 0 && !RE1.IsMatch(lines[0]))
            {
                lines.RemoveAt(0);
            }

            // count the { and } characters until they match
            int?balance = null;

            for (var i = 0; i < lines.Count; i++)
            {
                var openCount   = lines[i].Count(it => it == '{');
                var closedCount = lines[i].Count(it => it == '}');

                if (openCount > 0)
                {
                    balance = balance.GetValueOrDefault() + openCount;
                }
                if (closedCount > 0)
                {
                    balance = balance.GetValueOrDefault() - closedCount;
                }

                // if there's no { on the "interface ISomething" line, that doesn't mean they're balanced
                // we need to encounter at least one { or } before we can decide that
                if (balance.HasValue && balance.Value <= 0)
                {
                    lines = lines.Take(i + 1).ToList();
                }
            }

            var interfaceCode = string.Join(Environment.NewLine, lines);

            var match = RE2.Match(interfaceCode);
            var name  = match.Groups[1].Value;

            return(new InterfaceData {
                Name = name, Code = interfaceCode
            });
        }
Пример #2
0
        public List <Statement> Equivalences(Statement s)
        {
            List <Statement> list  = new List <Statement>();
            string           lisp  = s.Lisp;
            HashSet <string> atoms = GetAtomics(s);

            foreach (Match m in RE1.Matches(lisp))
            {
                GroupCollection gc = m.Groups;

                string[] lisps = new string[AMap2.Count];
                foreach (string k in AMap1.Keys)
                {
                    if (AMap2.ContainsKey(k))
                    {
                        lisps[AMap2[k]] = gc[AMap1[k] + 1].Value;
                    }
                }
                for (int i = 0; i < lisps.Length; ++i)
                {
                    if (lisps[i] == null)
                    {
                        char c = 'A';
                        while (atoms.Contains(c.ToString()))
                        {
                            ++c;
                        }
                        atoms.Add(c.ToString());
                        lisps[i] = c.ToString();
                    }
                }

                Statement n = Statement.NewParse(string.Format(FS2, lisps));
                if (n != null)
                {
                    list.Add(n);
                }
            }
            atoms = GetAtomics(s);
            foreach (Match m in RE2.Matches(lisp))
            {
                GroupCollection gc = m.Groups;

                string[] lisps = new string[AMap1.Count];
                foreach (string k in AMap2.Keys)
                {
                    if (AMap1.ContainsKey(k))
                    {
                        lisps[AMap1[k]] = gc[AMap2[k] + 1].Value;
                    }
                }
                for (int i = 0; i < lisps.Length; ++i)
                {
                    if (lisps[i] == null)
                    {
                        char c = 'A';
                        while (atoms.Contains(c.ToString()))
                        {
                            ++c;
                        }
                        atoms.Add(c.ToString());
                        lisps[i] = c.ToString();
                    }
                }

                Statement n = Statement.NewParse(string.Format(FS1, lisps));
                if (n != null)
                {
                    list.Add(n);
                }
            }

            return(list);
        }