Ejemplo n.º 1
0
        public static NSObjectTypeInfo ParseHeader(string headerFile)
        {
            var text    = System.IO.File.ReadAllText(headerFile);
            var matches = ibRegex.Matches(text);
            var type    = new NSObjectTypeInfo(System.IO.Path.GetFileNameWithoutExtension(headerFile), null, null, null, false);

            foreach (Match match in matches)
            {
                var kind = match.Groups[1].Value;
                var def  = match.Groups[2].Value;
                if (kind == "IBOutlet")
                {
                    var split = def.Split(whitespaceChars, StringSplitOptions.RemoveEmptyEntries);
                    if (split.Length != 2)
                    {
                        continue;
                    }
                    string objcType = split[1].TrimStart('*');
                    if (objcType == "id")
                    {
                        objcType = "NSObject";
                    }
                    type.Outlets.Add(new IBOutlet((objcType), null, split[0].TrimEnd('*'), null));
                }
                else
                {
                    string[] split  = def.Split(colonChar);
                    var      action = new IBAction(split[0].Trim(), null);
                    string   label  = null;
                    for (int i = 1; i < split.Length; i++)
                    {
                        var    s        = split[i].Split(splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries);
                        string objcType = s[0];
                        if (objcType == "id")
                        {
                            objcType = "NSObject";
                        }
                        var par = new IBActionParameter(label, s[1], objcType, null);
                        label = s.Length == 3? s[2] : null;
                        action.Parameters.Add(par);
                    }
                    type.Actions.Add(action);
                }
            }
            return(type);
        }
Ejemplo n.º 2
0
		public static NSObjectTypeInfo ParseHeader (string headerFile)
		{
			string text = File.ReadAllText (headerFile);
			string userType = null, userBaseType = null;
			MatchCollection matches;
			NSObjectTypeInfo type;
			
			// First, grep for classes
			matches = typeInfoRegex.Matches (text);
			foreach (Match match in matches) {
				if (match.Groups[1].Value != "interface")
					continue;
				
				if (userType != null) {
					// UNSUPPORTED: more than 1 user-type defined in this header
					return null;
				}
				
				userType = match.Groups[2].Value;
				userBaseType = match.Groups[3].Value;
			}
			
			if (userType == null)
				return null;
			
			type = new NSObjectTypeInfo (userType, null, userBaseType, null, false, true, true);
			
			// Now grep for IBActions and IBOutlets
			matches = ibRegex.Matches (text);
			foreach (Match match in matches) {
				var kind = match.Groups[1].Value;
				var def = match.Groups[2].Value;
				if (kind == "IBOutlet") {
					var split = def.Split (whitespaceChars, StringSplitOptions.RemoveEmptyEntries);
					if (split.Length != 2)
						continue;
					string objcName = split[1].TrimStart ('*');
					string objcType = split[0].TrimEnd ('*');
					if (objcType == "id")
						objcType = "NSObject";
					if (string.IsNullOrEmpty (objcType)) {
						MessageService.ShowError (GettextCatalog.GetString ("Error while parsing header file."),
							string.Format (GettextCatalog.GetString ("The definition '{0}' can't be parsed."), def));
						objcType = "NSObject";
					}
					
					IBOutlet outlet = new IBOutlet (objcName, objcName, objcType, null);
					outlet.IsDesigner = true;
					
					type.Outlets.Add (outlet);
				} else {
					string[] split = def.Split (colonChar);
					string name = split[0].Trim ();
					var action = new IBAction (name, name);
					action.IsDesigner = true;
					
					string label = null;
					for (int i = 1; i < split.Length; i++) {
						var s = split[i].Split (splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries);
						string objcType = s[0];
						if (objcType == "id")
							objcType = "NSObject";
						var par = new IBActionParameter (label, s[1], objcType, null);
						label = s.Length == 3? s[2] : null;
						action.Parameters.Add (par);
					}
					
					type.Actions.Add (action);
				}
			}
			
			return type;
		}
Ejemplo n.º 3
0
        public static NSObjectTypeInfo ParseHeader(string headerFile)
        {
            string           text = File.ReadAllText(headerFile);
            string           userType = null, userBaseType = null;
            MatchCollection  matches;
            NSObjectTypeInfo type;

            // First, grep for classes
            matches = typeInfoRegex.Matches(text);
            foreach (Match match in matches)
            {
                if (match.Groups[1].Value != "interface")
                {
                    continue;
                }

                if (userType != null)
                {
                    // UNSUPPORTED: more than 1 user-type defined in this header
                    return(null);
                }

                userType     = match.Groups[2].Value;
                userBaseType = match.Groups[3].Value;
            }

            if (userType == null)
            {
                return(null);
            }

            type = new NSObjectTypeInfo(userType, null, userBaseType, null, false, true, true);

            // Now grep for IBActions and IBOutlets
            matches = ibRegex.Matches(text);
            foreach (Match match in matches)
            {
                var kind = match.Groups[1].Value;
                var def  = match.Groups[2].Value;
                if (kind == "IBOutlet")
                {
                    var    split    = def.Split(whitespaceChars, StringSplitOptions.RemoveEmptyEntries);
                    string objcType = split[0].TrimEnd('*');
                    string objcName = null;

                    for (int i = 1; i < split.Length; i++)
                    {
                        objcName = split[i].TrimStart('*');
                        if (string.IsNullOrEmpty(objcName))
                        {
                            continue;
                        }

                        if (i + 1 < split.Length)
                        {
                            // This is a bad sign... what tokens are after the name??
                            objcName = null;
                            break;
                        }
                    }

                    if (string.IsNullOrEmpty(objcType) || string.IsNullOrEmpty(objcName))
                    {
                        MessageService.ShowError(GettextCatalog.GetString("Error while parsing header file."),
                                                 string.Format(GettextCatalog.GetString("The definition '{0}' can't be parsed."), def));

                        // We can't recover if objcName is empty...
                        if (string.IsNullOrEmpty(objcName))
                        {
                            continue;
                        }

                        // We can try using NSObject...
                        objcType = "NSObject";
                    }

                    if (objcType == "id")
                    {
                        objcType = "NSObject";
                    }

                    IBOutlet outlet = new IBOutlet(objcName, objcName, objcType, null);
                    outlet.IsDesigner = true;

                    type.Outlets.Add(outlet);
                }
                else
                {
                    string[] split  = def.Split(colonChar);
                    string   name   = split[0].Trim();
                    var      action = new IBAction(name, name);
                    action.IsDesigner = true;

                    string label = null;
                    for (int i = 1; i < split.Length; i++)
                    {
                        var    s        = split[i].Split(splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries);
                        string objcType = s[0];
                        if (objcType == "id")
                        {
                            objcType = "NSObject";
                        }
                        var par = new IBActionParameter(label, s[1], objcType, null);
                        label = s.Length == 3? s[2] : null;
                        action.Parameters.Add(par);
                    }

                    type.Actions.Add(action);
                }
            }

            return(type);
        }
Ejemplo n.º 4
0
		public static NSObjectTypeInfo ParseHeader (string headerFile)
		{
			var text = System.IO.File.ReadAllText (headerFile);
			var matches = ibRegex.Matches (text);
			var type = new NSObjectTypeInfo (System.IO.Path.GetFileNameWithoutExtension (headerFile), null, null, null, false);
			foreach (Match match in matches) {
				var kind = match.Groups[1].Value;
				var def = match.Groups[2].Value;
				if (kind == "IBOutlet") {
					var split = def.Split (whitespaceChars, StringSplitOptions.RemoveEmptyEntries);
					if (split.Length != 2)
						continue;
					type.Outlets.Add (new IBOutlet (split[1].TrimStart ('*'), null, split[0].TrimEnd ('*'), null));
				} else {
					string[] split = def.Split (colonChar);
					var action = new IBAction (split[0].Trim (), null);
					string label = null;
					for (int i = 1; i < split.Length; i++) {
						var s = split[i].Split (splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries);
						var par = new IBActionParameter (label, s[1], s[0], null);
						label = s.Length == 3? s[2] : null;
						action.Parameters.Add (par);
					}
					type.Actions.Add (action);
				}
			}
			return type;
		}
		public static NSObjectTypeInfo ParseHeader (string headerFile)
		{
			var text = System.IO.File.ReadAllText (headerFile);
			var matches = ibRegex.Matches (text);
			var type = new NSObjectTypeInfo (System.IO.Path.GetFileNameWithoutExtension (headerFile), null, null, null, false);
			foreach (Match match in matches) {
				var kind = match.Groups[1].Value;
				var def = match.Groups[2].Value;
				if (kind == "IBOutlet") {
					var split = def.Split (whitespaceChars, StringSplitOptions.RemoveEmptyEntries);
					if (split.Length != 2)
						continue;
					string objcName = split[1].TrimStart ('*');
					string objcType = split[0].TrimEnd ('*');
					if (objcType == "id")
						objcType = "NSObject";
					if (string.IsNullOrEmpty (objcType)) {
						MessageService.ShowError (GettextCatalog.GetString ("Error while parsing header file."),
							string.Format (GettextCatalog.GetString ("The definition '{0}' can't be parsed."), def));
						objcType = "NSObject";
					}
					type.Outlets.Add (new IBOutlet (objcName, null, objcType, null));
				} else {
					string[] split = def.Split (colonChar);
					var action = new IBAction (split[0].Trim (), null);
					string label = null;
					for (int i = 1; i < split.Length; i++) {
						var s = split[i].Split (splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries);
						string objcType = s[0];
						if (objcType == "id")
							objcType = "NSObject";
						var par = new IBActionParameter (label, s[1], objcType, null);
						label = s.Length == 3? s[2] : null;
						action.Parameters.Add (par);
					}
					type.Actions.Add (action);
				}
			}
			return type;
		}