示例#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();
            this.Errors      = parser.Errors;
            this.Specials    = parser.Lexer.SpecialTracker.RetrieveSpecials();
            this.SnippetType = SnippetType.CompilationUnit;
            INode result = parser.CompilationUnit;

            if (this.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 < this.Errors.Count)
                {
                    this.Errors      = parser.Errors;
                    this.Specials    = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    this.SnippetType = SnippetType.Expression;
                    result           = expression;
                }
            }
            if (this.Errors.Count > 0)
            {
                parser = ParserFactory.CreateParser(language, new StringReader(code));
                BlockStatement block = parser.ParseBlock();
                if (block != null && parser.Errors.Count < this.Errors.Count)
                {
                    this.Errors      = parser.Errors;
                    this.Specials    = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    this.SnippetType = SnippetType.Statements;
                    result           = block;
                }
            }
            if (this.Errors.Count > 0)
            {
                parser = ParserFactory.CreateParser(language, new StringReader(code));
                List <INode> members = parser.ParseTypeMembers();
                if (members != null && members.Count > 0 && parser.Errors.Count < this.Errors.Count)
                {
                    this.Errors          = parser.Errors;
                    this.Specials        = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    this.SnippetType     = SnippetType.TypeMembers;
                    result               = new NodeListNode(members);
                    result.StartLocation = members[0].StartLocation;
                    result.EndLocation   = members[members.Count - 1].EndLocation;
                }
            }
            Debug.Assert(result is CompilationUnit || !result.StartLocation.IsEmpty);
            Debug.Assert(result is CompilationUnit || !result.EndLocation.IsEmpty);
            return(result);
        }
示例#2
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));
                List <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);
        }
示例#3
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(new StringReader(code));

            parser.Parse();
            this.Errors      = parser.Errors;
            this.Specials    = parser.Lexer.SpecialTracker.RetrieveSpecials();
            this.SnippetType = SnippetType.CompilationUnit;
            INode result = parser.CompilationUnit;

            if (this.Errors.Count > 0)
            {
                parser = ParserFactory.CreateParser(new StringReader(code));
                Expression expression = parser.ParseExpression();
                if (expression != null && parser.Errors.Count < this.Errors.Count)
                {
                    this.Errors      = parser.Errors;
                    this.Specials    = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    this.SnippetType = SnippetType.Expression;
                    result           = expression;
                }
            }
            if (this.Errors.Count > 0)
            {
                parser = ParserFactory.CreateParser(new StringReader(code));
                BlockStatement block = parser.ParseBlock();
                if (block != null && parser.Errors.Count < this.Errors.Count)
                {
                    this.Errors      = parser.Errors;
                    this.Specials    = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    this.SnippetType = SnippetType.Statements;
                    result           = block;
                }
            }
            if (this.Errors.Count > 0)
            {
                parser = ParserFactory.CreateParser(new StringReader(code));
                List <INode> members = parser.ParseTypeMembers();
                if (members != null && members.Count > 0 && parser.Errors.Count < this.Errors.Count)
                {
                    this.Errors          = parser.Errors;
                    this.Specials        = parser.Lexer.SpecialTracker.RetrieveSpecials();
                    this.SnippetType     = SnippetType.TypeMembers;
                    result               = new NodeListNode(members);
                    result.StartLocation = members[0].StartLocation;
                    result.EndLocation   = members[members.Count - 1].EndLocation;
                }
            }
            Debug.Assert(result is CompilationUnit || !result.StartLocation.IsEmpty);
            Debug.Assert(result is CompilationUnit || !result.EndLocation.IsEmpty);
            return(result);
        }
示例#4
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)
		{
			VBParser parser = ParserFactory.CreateParser(new StringReader(code));
			parser.Parse();
			this.Errors = parser.Errors;
			this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
			this.SnippetType = SnippetType.CompilationUnit;
			INode result = parser.CompilationUnit;
			
			if (this.Errors.Count > 0) {
				parser = ParserFactory.CreateParser(new StringReader(code));
				Expression expression = parser.ParseExpression();
				if (expression != null && parser.Errors.Count < this.Errors.Count) {
					this.Errors = parser.Errors;
					this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
					this.SnippetType = SnippetType.Expression;
					result = expression;
				}
			}
			if (this.Errors.Count > 0) {
				parser = ParserFactory.CreateParser(new StringReader(code));
				BlockStatement block = parser.ParseBlock();
				if (block != null && parser.Errors.Count < this.Errors.Count) {
					this.Errors = parser.Errors;
					this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
					this.SnippetType = SnippetType.Statements;
					result = block;
				}
			}
			if (this.Errors.Count > 0) {
				parser = ParserFactory.CreateParser(new StringReader(code));
				List<INode> members = parser.ParseTypeMembers();
				if (members != null && members.Count > 0 && parser.Errors.Count < this.Errors.Count) {
					this.Errors = parser.Errors;
					this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
					this.SnippetType = SnippetType.TypeMembers;
					result = new NodeListNode(members);
					result.StartLocation = members[0].StartLocation;
					result.EndLocation = members[members.Count - 1].EndLocation;
				}
			}
			Debug.Assert(result is CompilationUnit || !result.StartLocation.IsEmpty);
			Debug.Assert(result is CompilationUnit || !result.EndLocation.IsEmpty);
			return result;
		}
		/// <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();
			this.Errors = parser.Errors;
			this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
			this.SnippetType = SnippetType.CompilationUnit;
			INode result = parser.CompilationUnit;
			
			if (this.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 < this.Errors.Count) {
					this.Errors = parser.Errors;
					this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
					this.SnippetType = SnippetType.Expression;
					result = expression;
				}
			}
			if (this.Errors.Count > 0) {
				parser = ParserFactory.CreateParser(language, new StringReader(code));
				BlockStatement block = parser.ParseBlock();
				if (block != null && parser.Errors.Count < this.Errors.Count) {
					this.Errors = parser.Errors;
					this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
					this.SnippetType = SnippetType.Statements;
					result = block;
				}
			}
			if (this.Errors.Count > 0) {
				parser = ParserFactory.CreateParser(language, new StringReader(code));
				List<INode> members = parser.ParseTypeMembers();
				if (members != null && members.Count > 0 && parser.Errors.Count < this.Errors.Count) {
					this.Errors = parser.Errors;
					this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
					this.SnippetType = SnippetType.TypeMembers;
					result = new NodeListNode(members);
					result.StartLocation = members[0].StartLocation;
					result.EndLocation = members[members.Count - 1].EndLocation;
				}
			}
			Debug.Assert(result is CompilationUnit || !result.StartLocation.IsEmpty);
			Debug.Assert(result is CompilationUnit || !result.EndLocation.IsEmpty);
			return result;
		}
示例#6
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;
        }