Example #1
0
        public Parser(Scanner scanner, IErrorLogger errorLogger)
        {
            this.scanner     = Utilities.ThrowIfNull(scanner, "scanner");
            this.errorLogger = Utilities.ThrowIfNull(errorLogger, "errorLogger");

            Consume();
        }
Example #2
0
        public Scanner(string input, IErrorLogger errorLogger)
        {
            this.input       = Utilities.ThrowIfNull(input, "input");
            this.errorLogger = Utilities.ThrowIfNull(errorLogger, "errorLogger");

            State = ScannerState.ScanningText;
        }
Example #3
0
 public string Evaluate(IFormatProvider formatProvider, ArgumentCollection arguments)
 {
     return
         (new Interpreter(
              formatProvider, Utilities.ThrowIfNull(arguments, "arguments"), SimpleErrorLogger.Instance).Evaluate(
              ast));
 }
Example #4
0
 public ArgumentCollection(IEnumerable <Argument> arguments)
 {
     foreach (Argument argument in Utilities.ThrowIfNull(arguments, "arguments"))
     {
         Add(argument);
     }
 }
Example #5
0
 public static Format Parse(string format)
 {
     return
         (new Format(
              new Parser(
                  new Scanner(Utilities.ThrowIfNull(format, "format"), SimpleErrorLogger.Instance),
                  SimpleErrorLogger.Instance).Parse()));
 }
        public int Compare(Location x, Location y)
        {
            Utilities.ThrowIfNull(x, "x");
            Utilities.ThrowIfNull(y, "y");

            if (x.Start < y.Start)
            {
                return(-1);
            }

            if (x.Start > y.Start)
            {
                return(1);
            }

            if (x.End < y.End)
            {
                return(-1);
            }

            return(x.End > y.End ? 1 : 0);
        }
Example #7
0
        public static bool IsValidIdentifier(string text)
        {
            Utilities.ThrowIfNull(text, "text");

            if (text.Length == 0)
            {
                return(false);
            }

            if (!IsValidIdentifierStartCharacter(text[0]))
            {
                return(false);
            }

            for (int i = 1; i < text.Length; ++i)
            {
                if (!IsValidIdentifierCharacter(text, i))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #8
0
        public static Location FromRange(IEnumerable <ILocated> items)
        {
            // ReSharper disable PossibleMultipleEnumeration
            Utilities.ThrowIfNull(items, "items");
            // ReSharper restore PossibleMultipleEnumeration

            bool hasSomeItem = false;

            int start = int.MaxValue;
            int end   = int.MinValue;

            // ReSharper disable PossibleMultipleEnumeration
            // ReSharper disable PossibleUnintendedReferenceComparison
            foreach (ILocated item in items.Where(x => x != null && x.Location != Unknown))
            {
                hasSomeItem = true;
                start       = Math.Min(start, item.Location.Start);
                end         = Math.Max(end, item.Location.End);
            }
            // ReSharper restore PossibleUnintendedReferenceComparison
            // ReSharper restore PossibleMultipleEnumeration

            return(hasSomeItem ? new Location(start, end) : Unknown);
        }
Example #9
0
 public FormattingException(IEnumerable <Error> errors)
     : base("Format is invalid.")
 {
     Errors = new ReadOnlyCollection <Error>(new List <Error>(Utilities.ThrowIfNull(errors, "errors")));
 }
Example #10
0
 public FormattingException(Error error)
     : this(Enumerable.Repeat(Utilities.ThrowIfNull(error, "error"), 1))
 {
 }
Example #11
0
 public FormattingException(Location location, string description)
     : this(
         new Error(
             Utilities.ThrowIfNull(location, "location"), Utilities.ThrowIfNull(description, "description")))
 {
 }
 public int Compare(ILocated x, ILocated y)
 {
     return(Compare(Utilities.ThrowIfNull(x, "x").Location, Utilities.ThrowIfNull(y, "y").Location));
 }
Example #13
0
 public void Add(string name, object value)
 {
     base.Add(new Argument(Utilities.ThrowIfNull(name, "name"), value));
 }
Example #14
0
 public bool Remove(string name)
 {
     return(Remove(this[Utilities.ThrowIfNull(name, "name")]));
 }
Example #15
0
 public bool Contains(string name)
 {
     return(this[Utilities.ThrowIfNull(name, "name")] != null);
 }
Example #16
0
 public TokenInfo(Location location, int token, string text)
 {
     Location = Utilities.ThrowIfNull(location, "location");
     Token    = token;
     Text     = Utilities.ThrowIfNull(text, "text");
 }
Example #17
0
 public Interpreter(IFormatProvider formatProvider, ArgumentCollection arguments, IErrorLogger errorLogger)
 {
     this.formatProvider = formatProvider;
     this.arguments      = Utilities.ThrowIfNull(arguments, "arguments");
     this.errorLogger    = Utilities.ThrowIfNull(errorLogger, "errorLogger");
 }