コード例 #1
0
        private LSLParameterListNode(LSLParser.OptionalParameterListContext context,
                                     LSLParameterListType parameterListType)
        {
            SourceRange = new LSLSourceCodeRange(context);

            SourceRangesAvailable = true;

            ParameterListType = parameterListType;
        }
コード例 #2
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="LSLParser.optionalParameterList"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitOptionalParameterList([NotNull] LSLParser.OptionalParameterListContext context)
 {
 }
コード例 #3
0
        /// <summary>
        ///     Builds a parameter list node directly from a parser context, checking for duplicates and reporting
        ///     duplicate parameter errors via a validator strategies object. <see cref="ILSLCodeValidatorStrategies" />.
        /// </summary>
        /// <param name="context">The context to build from</param>
        /// <param name="validatorStrategies">The validator strategies object to use for reporting errors or warnings</param>
        /// <param name="parameterListType">The parameter list type.</param>
        /// <returns>the created parameter list node</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="context" /> or <paramref name="validatorStrategies" /> is
        ///     <c>null</c>.
        /// </exception>
        internal static LSLParameterListNode BuildFromParserContext(LSLParser.OptionalParameterListContext context,
                                                                    LSLParameterListType parameterListType, ILSLCodeValidatorStrategies validatorStrategies)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (validatorStrategies == null)
            {
                throw new ArgumentNullException("validatorStrategies");
            }


            var result = new LSLParameterListNode(context, parameterListType);

            var parameterList = context.parameterList();

            if (parameterList == null)
            {
                return(result);
            }

            var parameterNames = new HashSet <string>();

            var parameterIndex = 0;

            foreach (var comma in parameterList.children)
            {
                //'comma' for some reason will be an internal object
                //that cannot be accessed via cast when a COMMA token is encountered.
                //
                //However, Payload contains a CommonToken instance, which implements IToken.
                var token = comma.Payload as IToken;

                //when a parameter def is found, 'comma' will be the grammar defined
                //LSLParser.ParameterDefinitionContext type.
                var parameter = comma as LSLParser.ParameterDefinitionContext;

                if (token != null)
                {
                    result._sourceRangeCommaList.Add(new LSLSourceCodeRange(token));
                }
                else if (parameter != null)
                {
                    if (parameterNames.Contains(parameter.ID().GetText()))
                    {
                        var paramLocation = new LSLSourceCodeRange(parameter);

                        validatorStrategies.SyntaxErrorListener.ParameterNameRedefined(
                            paramLocation,
                            parameterListType,
                            LSLTypeTools.FromLSLTypeName(parameter.TYPE().GetText()),
                            parameter.ID().GetText());

                        result.HasErrors = true;

                        result._parameters.Clear();

                        return(result);
                    }


                    parameterNames.Add(parameter.ID().GetText());

                    var addition = new LSLParameterNode(parameter)
                    {
                        ParameterIndex = parameterIndex
                    };

                    result.Add(addition);

                    parameterIndex++;
                }
            }

            parameterNames.Clear();

            return(result);
        }
コード例 #4
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="LSLParser.optionalParameterList"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitOptionalParameterList([NotNull] LSLParser.OptionalParameterListContext context)
 {
     return(VisitChildren(context));
 }