Пример #1
0
        /// <summary>
        /// Parse the code. The result may be a CompilationUnit, an Expression, a list of statements or a list of class
        /// members.
        /// </summary>
        public INode Parse(string code)
        {
            IParser parser = ParserFactory.CreateParser(language, new StringReader(code));
            parser.Parse();
            errors = parser.Errors;
            specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
            INode result = parser.CompilationUnit;

            if (errors.Count > 0) {
                if (language == SupportedLanguage.CSharp) {
                    // SEMICOLON HACK : without a trailing semicolon, parsing expressions does not work correctly
                    parser = ParserFactory.CreateParser(language, new StringReader(code + ";"));
                } else {
                    parser = ParserFactory.CreateParser(language, new StringReader(code));
                }
                Expression expression = parser.ParseExpression();
                if (expression != null && parser.Errors.Count < errors.Count) {
                    errors = parser.Errors;
                    specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    result = expression;
                }
            }
            if (errors.Count > 0) {
                parser = ParserFactory.CreateParser(language, new StringReader(code));
                BlockStatement block = parser.ParseBlock();
                if (block != null && parser.Errors.Count < errors.Count) {
                    errors = parser.Errors;
                    specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    result = block;
                }
            }
            if (errors.Count > 0) {
                parser = ParserFactory.CreateParser(language, new StringReader(code));
                IList<INode> members = parser.ParseTypeMembers();
                if (members != null && members.Count > 0 && parser.Errors.Count < errors.Count) {
                    errors = parser.Errors;
                    specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    result = new NodeListNode(members);
                }
            }
            return result;
        }
Пример #2
0
		public virtual void Dispose()
		{
			reader.Close();
			reader = null;
			errors = null;
			lastToken = curToken = peekToken = null;
			specialCommentHash = null;
			tagComments = null;
			sb = originalValue = null;
		}
Пример #3
0
 public void Dispose()
 {
     errors = null;
     if (lexer != null) {
         lexer.Dispose();
     }
     lexer = null;
 }
Пример #4
0
 internal AbstractParser(ILexer lexer)
 {
     this.errors = lexer.Errors;
     this.lexer  = lexer;
     errors.SynErr = new ErrorCodeProc(SynErr);
 }
Пример #5
0
		public void Dispose()
		{
			errors = null;
			lexer.Dispose();
			lexer = null;
		}
Пример #6
0
 private static void PrintErrors(string AFileName, Errors AErrors)
 {
     Console.WriteLine("File: " + AFileName + "\n");
     Console.WriteLine(AErrors.ErrorOutput);
 }
Пример #7
0
 internal AbstractParser(ILexer lexer)
 {
     this.errors   = lexer.Errors;
     this.lexer    = lexer;
     errors.SynErr = new ErrorCodeProc(SynErr);
 }