Ejemplo n.º 1
0
        /// <summary>
        /// Parses input stream to tokens and then according to CSS grammar.
        /// </summary>
        /// <param name="inp">file name of input stream.</param>
        public void Parse(string inp)
        {
            string fullpath;
            if (Path.IsPathRooted(inp))
                fullpath = inp;
            else
                fullpath = Common.PathCombine(Environment.CurrentDirectory, inp);

            ICharStream input = new ANTLRFileStream(fullpath, Encoding.UTF8);
            csst3Lexer lex = new csst3Lexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lex);
            csst3Parser parser = new csst3Parser(tokens);

            // return results as parameters
            try
            {
                Root = (CommonTree)parser.stylesheet().Tree;
                Errors = parser.GetErrors();
            }
            catch (Exception)
            {
                Errors = parser.GetErrors();
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses input stream to tokens and then according to CSS grammar.
        /// </summary>
        /// <param name="inp">file name of input stream.</param>
        public void Parse(string inp)
        {
            if (String.IsNullOrEmpty(inp))
            {
                return;
            }

            string fullpath;

            if (Path.IsPathRooted(inp))
            {
                fullpath = inp;
            }
            else
            {
                fullpath = Path.Combine(Environment.CurrentDirectory, inp);
            }

            if (!File.Exists(fullpath))
            {
                throw new FileNotFoundException(fullpath);
            }

            ICharStream       input  = new ANTLRFileStream(fullpath, Encoding.UTF8);
            csst3Lexer        lex    = new csst3Lexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lex);
            csst3Parser       parser = new csst3Parser(tokens);

            // return results as parameters
            try
            {
                Root   = (CommonTree)parser.stylesheet().Tree;
                Errors = parser.GetErrors();
            }
            catch (Exception)
            {
                Errors = parser.GetErrors();
                throw;
            }
        }