Exemplo n.º 1
0
		public void SetContext(SnippetType type)
		{
			switch (type) {
				case SnippetType.Expression:
					currentState = startOfExpression;
					break;
			}
			
			Advance();
		}
Exemplo n.º 2
0
 public static Snippet Create(SnippetType type, string code, int offset = 0, int startIndex = -1, int endIndex = -1, int internalOffset = 0)
 {
     return new Snippet
     {
         Type = type,
         Code = code,
         Length = code.Length,
         StartIndex = startIndex,
         EndIndex = endIndex,
         Offset = offset,
         InternalOffset = internalOffset
     };
 }
		/// <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;
		}
Exemplo n.º 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;
		}
Exemplo n.º 5
0
		VBLexer GenerateLexerForSnippet(StringReader sr, SnippetType type)
		{
			var lexer = new VBLexer(sr);
			lexer.SetInitialContext(type);
			return lexer;
		}
Exemplo n.º 6
0
		public void SetInitialContext(SnippetType type)
		{
			ef.SetContext(type);
		}
Exemplo n.º 7
0
		ILexer GenerateLexerForSnippet(StringReader sr, SnippetType type)
		{
			var lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, sr);
			lexer.SetInitialContext(type);
			return lexer;
		}
Exemplo n.º 8
0
		public virtual void SetInitialContext(SnippetType context)
		{
			throw new NotSupportedException();
		}
Exemplo n.º 9
0
		public static string GetSnippet(Type typeClass,SnippetType snipType,bool isMobile){
			//bool isMobile=CrudGenHelper.IsMobile(typeClass);
			string Sname=GetSname(typeClass.Name);
			FieldInfo[] fields=typeClass.GetFields();//We can't assume they are in the correct order.
			FieldInfo priKey=null;
			FieldInfo priKey1=null;
			FieldInfo priKey2=null;
			if(isMobile) {
				priKey1=CrudGenHelper.GetPriKeyMobile1(fields,typeClass.Name);
				priKey2=CrudGenHelper.GetPriKeyMobile2(fields,typeClass.Name);
			}
			else {
				priKey=CrudGenHelper.GetPriKey(fields,typeClass.Name);
			}
			string priKeyParam=null;
			string priKeyParam1=null;
			string priKeyParam2=null;
			if(isMobile) {
				priKeyParam1=priKey1.Name.Substring(0,1).ToLower()+priKey1.Name.Substring(1);//lowercase initial letter.  Example customerNum
				priKeyParam2=priKey2.Name.Substring(0,1).ToLower()+priKey2.Name.Substring(1);//lowercase initial letter.  Example patNum
			}
			else {
				priKeyParam=priKey.Name.Substring(0,1).ToLower()+priKey.Name.Substring(1);//lowercase initial letter.  Example patNum
			}
			string obj=typeClass.Name.Substring(0,1).ToLower()+typeClass.Name.Substring(1);//lowercase initial letter.  Example feeSched
			string tablename=CrudGenHelper.GetTableName(typeClass);//in lowercase now.  Example feesched
			List<FieldInfo> fieldsExceptPri=null;
			if(isMobile) {
				fieldsExceptPri=CrudGenHelper.GetFieldsExceptPriKey(fields,priKey2);//for mobile, only excludes PK2
			}
			else {
				fieldsExceptPri=CrudGenHelper.GetFieldsExceptPriKey(fields,priKey);
			}
			switch(snipType){
				default:
					return "snippet type not found.";
				case SnippetType.Insert:
					if(isMobile) {
						return GetInsert(typeClass.Name,obj,null,true);
					}
					else {
						return GetInsert(typeClass.Name,obj,priKey.Name,false);
					}
				case SnippetType.Update:
					return GetUpdate(typeClass.Name,obj,isMobile);
				case SnippetType.EntireSclass:
					if(isMobile) {
						return GetEntireSclassMobile(typeClass.Name,obj,priKey1.Name,priKey2.Name,Sname,tablename,priKeyParam1,priKeyParam2);
					}
					else {
						return GetEntireSclass(typeClass.Name,obj,priKey.Name,Sname,tablename,priKeyParam);
					}
				case SnippetType.CreateTable:
					return "Currently unavailable.";
					/*
					if(isMobile) {
						return GetCreateTable(tablename,priKey1.Name,priKey2.Name,fieldsExceptPri);
					}
					else {
						return GetCreateTable(tablename,priKey.Name,null,fieldsExceptPri);
					}*/
			}
		}