Example #1
0
        /// <summary>
        /// Parses the file.
        /// </summary>
        public void Parse()
        {
            try
            {
                ANTLRFileStream inputStream = new ANTLRFileStream(FileName);

                CpsLexer          lexer  = new CpsLexer(inputStream);
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                CpsParser         parser = new CpsParser(tokens);

                // Parse the file
                ITree ct = (ITree)parser.concern().Tree;

                if (ct != null)
                {
                    Walk(ct);
                }
            }
            catch (IOException ex)
            {
                throw new CpsParserException(String.Format(CultureInfo.CurrentCulture,
                                                           Resources.ConcernNotFound, FileName), FileName, ex);
            }
            catch (RecognitionException ex)
            {
                throw new CpsParserException(String.Format(CultureInfo.CurrentCulture,
                                                           Resources.UnableToParseConcern, FileName, ex.Message), FileName, ex);
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        private EmbeddedCode ExtractEmbeddedCode(CpsParser parser)
        {
            if (parser.startPos == -1)
            {
                return(null);
            }

            EmbeddedCode ec = new EmbeddedCode();

            ec.Language = parser.sourceLang;
            ec.FileName = parser.sourceFile;
            ec.Code     = ExtractEmbeddedSource(FileName, parser.startPos);

            return(ec);
        }
Example #3
0
        /// <summary>
        /// Parses the file.
        /// </summary>
        public void Parse()
        {
            try
            {
                using (FileStream inputStream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    // Create a new ANTLR Lexer for the filestream
                    CpsLexer lexer = new CpsPosLexer(inputStream);

                    // Create a new ANTLR Parser for the ANTLR Lexer
                    CpsParser parser = new CpsParser(lexer);

                    // Parse the file
                    parser.concern();

                    // Embedded code?
                    _embeddedCode = ExtractEmbeddedCode(parser);

                    if (parser.getAST() != null)
                    {
                        AST root = parser.getAST();

                        if (root != null)
                        {
                            Walk(root, false, null);
                        }
                    }
                }
            }
            catch (IOException ex)
            {
                throw new CpsParserException(String.Format(CultureInfo.CurrentCulture,
                                                           Resources.ConcernNotFound, FileName), FileName, ex);
            }
            catch (antlr.ANTLRException ex)
            {
                throw new CpsParserException(String.Format(CultureInfo.CurrentCulture,
                                                           Resources.UnableToParseConcern, FileName, ex.Message), FileName, ex);
            }
        }