Esempio n. 1
0
        private static void parseEventBody(CsEvent ev, TokenJar tok, ref int i)
        {
            tok[i].Assert("{");
            i++;
            ev.Methods = new List<CsSimpleMethod>();

            while (!tok[i].IsBuiltin("}"))
            {
                var startIndex = tok[i].StartIndex;
                var cAttribs = new List<CsCustomAttributeGroup>();
                while (tok[i].IsBuiltin("["))
                    cAttribs.Add(parseCustomAttributeGroup(tok, ref i));
                var m = new CsSimpleMethod { StartIndex = startIndex, CustomAttributes = cAttribs };
                parseModifiers(m, tok, ref i);
                if (!tok[i].IsIdentifier("add") && !tok[i].IsIdentifier("remove"))
                    throw new ParseException("'add' or 'remove' expected.", tok[i].StartIndex, ev);
                m.Type = tok[i].TokenStr == "add" ? MethodType.Add : MethodType.Remove;
                if (ev.Methods.Any(me => me.Type == m.Type))
                {
                    if (m.Type == MethodType.Add)
                        throw new ParseException("An 'add' method has already been defined for this event.", tok[i].StartIndex, ev);
                    else
                        throw new ParseException("A 'remove' method has already been defined for this event.", tok[i].StartIndex, ev);
                }
                ev.Methods.Add(m);
                i++;
                if (tok[i].IsBuiltin("{"))
                {
                    try { m.Body = parseBlock(tok, ref i); }
                    catch (ParseException e)
                    {
                        if (e.IncompleteResult is CsBlock)
                            m.Body = (CsBlock) e.IncompleteResult;
                        throw new ParseException(e.Message, e.Index, ev, e);
                    }
                }
                else if (tok[i].IsBuiltin(";"))
                    i++;
                else
                    throw new ParseException("'{' or ';' expected.", tok[i].StartIndex, ev);
                m.EndIndex = tok[i - 1].EndIndex;
            }
            i++;
        }
Esempio n. 2
0
        private static void parsePropertyBody(CsProperty prop, TokenJar tok, ref int i)
        {
            if (!tok[i].IsBuiltin("{"))
                throw new ParseException(@"'{' expected.", tok[i].StartIndex);
            i++;

            while (!tok[i].IsBuiltin("}"))
            {
                var startIndex = tok[i].StartIndex;
                var cAttribs = new List<CsCustomAttributeGroup>();
                while (tok[i].IsBuiltin("["))
                    cAttribs.Add(parseCustomAttributeGroup(tok, ref i));
                var m = new CsSimpleMethod { StartIndex = startIndex, CustomAttributes = cAttribs };
                parseModifiers(m, tok, ref i);
                if (!tok[i].IsIdentifier("get") && !tok[i].IsIdentifier("set"))
                    throw new ParseException("'get' or 'set' expected.", tok[i].StartIndex, prop);
                m.Type = tok[i].TokenStr == "get" ? MethodType.Get : MethodType.Set;
                if (prop.Methods.Any(me => me.Type == m.Type))
                    throw new ParseException("A '{0}' method has already been defined for this property.".Fmt(m.Type), tok[i].StartIndex, prop);
                prop.Methods.Add(m);
                i++;
                if (tok[i].IsBuiltin("{"))
                {
                    try { m.Body = parseBlock(tok, ref i); }
                    catch (ParseException e)
                    {
                        if (e.IncompleteResult is CsBlock)
                            m.Body = (CsBlock) e.IncompleteResult;
                        throw new ParseException(e.Message, e.Index, prop, e);
                    }
                }
                else if (tok[i].IsBuiltin(";"))
                    i++;
                else
                    throw new ParseException("'{' or ';' expected.", tok[i].StartIndex, prop);
                m.EndIndex = tok[i - 1].EndIndex;
            }
            i++;
        }