示例#1
0
        public static string FormatError(Flag f, CommandLineOptions Options)
        {
            string programName = "?";

            if (f.ProgramName != null)
            {
                bool shortFileNames = Options.shortFileNames;
                if (shortFileNames)
                {
                    var envParams = new EnvParams(
                        new Tuple <EnvParamKind, object>(EnvParamKind.Msgs_SuppressPaths, true));
                    programName = f.ProgramName.ToString(envParams);
                }
                else
                {
                    programName = (f.ProgramName.Uri.IsFile ? f.ProgramName.Uri.LocalPath : f.ProgramName.ToString());
                }
            }

            string errorNumber = "PC1001"; // todo: invent meaningful error numbers to go with P documentation...

            return
                // this format causes VS to put the errors in the error list window.
                (string.Format("{0}({1},{2},{3},{4}): error {5}: {6}",
                               programName,
                               f.Span.StartLine,
                               f.Span.StartCol,
                               f.Span.EndLine,
                               f.Span.EndCol,
                               errorNumber,
                               f.Message));
        }
示例#2
0
文件: Term.cs 项目: thisiscam/formula
 /// <summary>
 /// Expects this to be a type term. If not an InvalidOperationException will be thrown.
 /// </summary>
 public void PrintTypeTerm(
     TextWriter wr,
     System.Threading.CancellationToken cancel = default(System.Threading.CancellationToken),
     EnvParams envParams = null)
 {
     TermPrinting.PrintTypeTerm(this, wr, cancel, envParams);
 }
示例#3
0
文件: Term.cs 项目: thisiscam/formula
        /// <summary>
        /// Expects this to be a type term. If not an InvalidOperationException will be thrown.
        /// </summary>
        public string PrintTypeTerm(
            System.Threading.CancellationToken cancel = default(System.Threading.CancellationToken),
            EnvParams envParams = null)
        {
            var sw = new StringWriter();

            TermPrinting.PrintTypeTerm(this, sw, cancel, envParams);
            return(sw.ToString());
        }
示例#4
0
        public string GetFileLocationString(EnvParams envParams)
        {
            if (ast == null)
            {
                return("unknown program (?, ?)");
            }

            return(string.Format(
                       "{0} ({1}, {2})",
                       ((Program)ast.Root).Name.ToString(envParams),
                       ast.Node.Span.StartLine,
                       ast.Node.Span.StartCol));
        }
示例#5
0
 internal static void PrintTerm(
     Term t,
     TextWriter wr,
     System.Threading.CancellationToken cancel = default(System.Threading.CancellationToken),
     EnvParams envParams = null)
 {
     t.Compute <Unit>(
         (x, s) =>
     {
         wr.Write(x.Symbol.PrintableName);
         return(PrintTerm_Unfold(x, wr));
     },
         (x, ch, s) =>
     {
         return(default(Unit));
     });
 }
示例#6
0
        internal static string GetCodeLocationString(this object obj, EnvParams envParams, ProgramName progName = null)
        {
            if (obj is Location)
            {
                return(((Location)obj).GetFileLocationString(envParams));
            }

            Span span;

            if (obj is Node)
            {
                span = ((Node)obj).Span;
            }
            else if (obj is AST <Node> )
            {
                span = ((AST <Node>)obj).Node.Span;
            }
            else if (obj is Tuple <ProgramName, Node> )
            {
                var tup = (Tuple <ProgramName, Node>)obj;
                return(GetCodeLocationString(tup.Item2, envParams, tup.Item1));
            }
            else
            {
                if (progName == null)
                {
                    return("(?,?)");
                }
                else
                {
                    return(progName.ToString(envParams) + " (?,?)");
                }
            }

            if (progName == null)
            {
                return(string.Format("({0}, {1})", span.StartLine, span.StartCol));
            }
            else
            {
                return(string.Format("{0}({1}, {2})", progName.ToString(envParams), span.StartLine, span.StartCol));
            }
        }
示例#7
0
        public static void Main(string[] args)
        {
            var sink      = new ConsoleSink();
            var chooser   = new ConsoleChooser();
            var envParams = new EnvParams();

            using (var ci = new CommandInterface(sink, chooser, envParams))
            {
                Console.CancelKeyPress += (x, y) =>
                {
                    y.Cancel = true;
                    ci.Cancel();
                };

                //// If errors occured while parsing switches
                //// then treat this an exit condition.
                bool isExit;
                ci.DoOptions(out isExit);
                if (isExit || sink.PrintedError)
                {
                    Environment.ExitCode = sink.PrintedError ? 1 : 0;
                    return;
                }

                string line;
                while (true)
                {
                    //// Because pressing CTRL-C may return a null line
                    line = Console.ReadLine();
                    line = line == null ? string.Empty : line.Trim();
                    if (line == CommandInterface.ExitCommand ||
                        line == CommandInterface.ExitShortCommand)
                    {
                        Environment.ExitCode = sink.PrintedError ? 1 : 0;
                        return;
                    }

                    ci.DoCommand(line);
                }
            }
        }
示例#8
0
 internal static string MkDupErrMsg(string item, object offDef1, object offDef2, EnvParams envParams)
 {
     return(Constants.DuplicateDefs.ToString(
                item,
                GetCodeLocationString(offDef1, envParams),
                GetCodeLocationString(offDef2, envParams)));
 }
示例#9
0
        internal static void PrintTypeTerm(
            Term t,
            TextWriter wr,
            System.Threading.CancellationToken cancel = default(System.Threading.CancellationToken),
            EnvParams envParams = null)
        {
            Contract.Requires(t != null && wr != null);
            bool         success;
            string       name;
            bool         isFirstComponent = true;
            var          enumState = TypeEnumState.None;
            BaseCnstSymb bcs1, bcs2;

            t.Visit(
                x => x.Symbol == t.Owner.TypeUnionSymbol ? x.Args : null,
                x =>
            {
                if (x.Symbol == t.Owner.TypeUnionSymbol)
                {
                    return;
                }

                switch (x.Symbol.Kind)
                {
                case SymbolKind.BaseCnstSymb:
                    OpenEnum(wr, isFirstComponent, ref enumState);
                    bcs1 = (BaseCnstSymb)x.Symbol;
                    switch (bcs1.CnstKind)
                    {
                    case CnstKind.Numeric:
                        wr.Write(((Rational)bcs1.Raw).ToString());
                        break;

                    case CnstKind.String:
                        wr.Write(ASTSchema.Instance.Encode((string)bcs1.Raw));
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    break;

                case SymbolKind.BaseOpSymb:
                    if (x.Symbol != t.Owner.RangeSymbol)
                    {
                        throw new InvalidOperationException("Not a type term");
                    }

                    OpenEnum(wr, isFirstComponent, ref enumState);
                    if (x.Args[0] == x.Args[1])
                    {
                        bcs1 = (BaseCnstSymb)x.Args[0].Symbol;
                        wr.Write(((Rational)bcs1.Raw).ToString());
                    }
                    else
                    {
                        bcs1 = (BaseCnstSymb)x.Args[0].Symbol;
                        bcs2 = (BaseCnstSymb)x.Args[1].Symbol;
                        wr.Write(string.Format("{0}..{1}", (Rational)bcs1.Raw, (Rational)bcs2.Raw));
                    }

                    break;

                case SymbolKind.BaseSortSymb:
                    CloseEnum(wr, isFirstComponent, ref enumState);
                    success = ASTSchema.Instance.TryGetSortName(((BaseSortSymb)x.Symbol).SortKind, out name);
                    Contract.Assert(success);
                    wr.Write(name);
                    break;

                case SymbolKind.ConSymb:
                case SymbolKind.MapSymb:
                    CloseEnum(wr, isFirstComponent, ref enumState);
                    for (int i = 0; i < x.Symbol.Arity; ++i)
                    {
                        if (i == 0)
                        {
                            wr.Write(string.Format("{0}(", ((UserSymbol)x.Symbol).FullName));
                        }

                        PrintTypeTerm(x.Args[i], wr, cancel, envParams);
                        wr.Write(i == x.Symbol.Arity - 1 ? ")" : ", ");
                    }

                    break;

                case SymbolKind.UnnSymb:
                    CloseEnum(wr, isFirstComponent, ref enumState);
                    wr.Write(((UnnSymb)x.Symbol).FullName);
                    break;

                case SymbolKind.UserCnstSymb:
                    OpenEnum(wr, isFirstComponent, ref enumState);
                    if (x.Groundness != Groundness.Ground)
                    {
                        throw new InvalidOperationException("Not a type term");
                    }

                    wr.Write(((UserCnstSymb)x.Symbol).FullName);
                    break;

                case SymbolKind.UserSortSymb:
                    CloseEnum(wr, isFirstComponent, ref enumState);
                    wr.Write(((UserSortSymb)x.Symbol).DataSymbol.FullName);
                    break;

                default:
                    throw new NotImplementedException();
                }

                isFirstComponent = false;
            });

            if (enumState != TypeEnumState.None)
            {
                wr.Write("}");
            }
        }