Пример #1
0
        private static void ToParameters(List<IDLParameter> Parameters, IDLParserTokenPair ParameterSymbols)
        {
            ParameterSymbols.Item1 = ParameterSymbols.Item1.AssertSymbol("(");
            ParameterSymbols.Item2 = ParameterSymbols.Item1.SkipTo().UntilSelected(
                p =>
                {
                    if (p.Text != ")")
                    {
                        if (Parameters.Count > 0)
                        {
                            p.AssertSymbol(",");
                            p = p.SkipTo();
                        }

                        var ParameterTypeToken = p;

                        #region KeywordAttribute
                        var KeywordAttribute = default(IDLParserToken);

                        // C# default constructor is so cool that we want it for idl!
                        if (ParameterTypeToken.Text == "attribute")
                        {
                            KeywordAttribute = ParameterTypeToken;
                            ParameterTypeToken = ParameterTypeToken.SkipTo();
                        }
                        #endregion


                        var KeywordIn = default(IDLParserToken);
                        var KeywordOptional = default(IDLParserToken);


                        #region KeywordIn
                        if (ParameterTypeToken.Text == "in")
                        {
                            KeywordIn = ParameterTypeToken;
                            ParameterTypeToken = ParameterTypeToken.SkipTo();
                        }
                        #endregion

                        #region KeywordOptional
                        // can we make it implicitly optional by attribute and haveng a value for it?
                        if (ParameterTypeToken.Text == "optional")
                        {
                            KeywordOptional = ParameterTypeToken;
                            ParameterTypeToken = ParameterTypeToken.SkipTo();
                        }
                        #endregion


                        var ParameterType = ToTypeReference(ParameterTypeToken);

                        var param = new IDLParameter
                        {
                            KeywordAttribute = KeywordAttribute,

                            KeywordIn = KeywordIn,
                            KeywordOptional = KeywordOptional,
                            ParameterType = ParameterType,


                        };

                        // like the const
                        param.Name = ParameterType.Terminator.SkipTo().AssertName();

                        #region DefaultValue
                        if (param.Name.SkipTo().Text == "=")
                        {
                            param.KeywordAssignment = param.Name.SkipTo().AssertSymbol("=");
                            param.DefaultValue = param.KeywordAssignment.SkipTo().ToNumericLiteral();

                            Parameters.Add(param);
                            return param.DefaultValue.Terminator.SkipTo();
                        }
                        #endregion


                        Parameters.Add(param);
                        return param.Name.SkipTo();
                    }

                    return p;
                }
            ).AssertSymbol(")");
        }
Пример #2
0
        private static void ToParameters(List <IDLParameter> Parameters, IDLParserTokenPair ParameterSymbols)
        {
            ParameterSymbols.Item1 = ParameterSymbols.Item1.AssertSymbol("(");
            ParameterSymbols.Item2 = ParameterSymbols.Item1.SkipTo().UntilSelected(
                p =>
            {
                if (p.Text != ")")
                {
                    if (Parameters.Count > 0)
                    {
                        p.AssertSymbol(",");
                        p = p.SkipTo();
                    }

                    var ParameterTypeToken = p;

                    #region KeywordAttribute
                    var KeywordAttribute = default(IDLParserToken);

                    // C# default constructor is so cool that we want it for idl!
                    if (ParameterTypeToken.Text == "attribute")
                    {
                        KeywordAttribute   = ParameterTypeToken;
                        ParameterTypeToken = ParameterTypeToken.SkipTo();
                    }
                    #endregion


                    var KeywordIn       = default(IDLParserToken);
                    var KeywordOptional = default(IDLParserToken);


                    #region KeywordIn
                    if (ParameterTypeToken.Text == "in")
                    {
                        KeywordIn          = ParameterTypeToken;
                        ParameterTypeToken = ParameterTypeToken.SkipTo();
                    }
                    #endregion

                    #region KeywordOptional
                    // can we make it implicitly optional by attribute and haveng a value for it?
                    if (ParameterTypeToken.Text == "optional")
                    {
                        KeywordOptional    = ParameterTypeToken;
                        ParameterTypeToken = ParameterTypeToken.SkipTo();
                    }
                    #endregion


                    var ParameterType = ToTypeReference(ParameterTypeToken);

                    var param = new IDLParameter
                    {
                        KeywordAttribute = KeywordAttribute,

                        KeywordIn       = KeywordIn,
                        KeywordOptional = KeywordOptional,
                        ParameterType   = ParameterType,
                    };

                    // like the const
                    param.Name = ParameterType.Terminator.SkipTo().AssertName();

                    #region DefaultValue
                    if (param.Name.SkipTo().Text == "=")
                    {
                        param.KeywordAssignment = param.Name.SkipTo().AssertSymbol("=");
                        param.DefaultValue      = param.KeywordAssignment.SkipTo().ToNumericLiteral();

                        Parameters.Add(param);
                        return(param.DefaultValue.Terminator.SkipTo());
                    }
                    #endregion


                    Parameters.Add(param);
                    return(param.Name.SkipTo());
                }

                return(p);
            }
                ).AssertSymbol(")");
        }