Ejemplo n.º 1
0
        /// <summary>
        /// Parses the given format and returns the IDice object that
        /// represents that data or throws a DiceException if it
        /// cannot be parsed.
        /// </summary>
        public static IDice Parse(string format)
        {
            // Create the scanner and parser
            byte [] bytes = Encoding.UTF8.GetBytes(format);
            MemoryStream stream = new MemoryStream(bytes);
            Scanner scanner = new Scanner(stream);
            scanner.Format = format;
            Parser parser = new Parser(scanner);

            // Parse the results
            IDice dice = parser.Parse();

            // Check for errors
            if (parser.Errors.Count > 0)
            {
                throw new DiceException("Cannot parse: " + format);
            }

            // Return the dice
            return dice;
        }
Ejemplo n.º 2
0
 public Parser(Scanner scanner)
 {
     this.scanner = scanner;
     errors = new Errors();
     errors.Format = scanner.Format;
 }