Exemple #1
0
        private void ParseFunctionParameterList(ScriptFunction func)
        {
            Modifiers modifiers;
            bool      atEndOfParameterList = false;

            while ((!atEndOfParameterList) &&
                   (!_source.NextIsKeyword(PredefinedSymbol.CloseParenthesis)))
            {
                modifiers = new Modifiers();

                while (_source.PeekNextToken() is ModifierToken)
                {
                    modifiers.Add((ModifierToken)_source.ReadNextToken());
                }

                if (_source.NextIsKeyword(PredefinedSymbol.VariableArguments))
                {
                    func.VariableArguments = true;
                    _source.ExpectKeyword(PredefinedSymbol.CloseParenthesis, "Variable arguments must be the last parameter");
                    break;
                }

                Token parameterType = _source.ReadNextAsVariableType();
                Token parameterName = null;
                _source.IgnoreAsteriskIfPresent();

                CompilerUtils.VerifyModifiersAgainstType(ModifierTargets.FunctionParameter, modifiers);

                VerifyParameterTypeValidForFunction(parameterType);

                if (!_source.PeekNextToken().Defined)
                {
                    parameterName = _source.ReadNextTokenAndThrowIfAlreadyDefined();
                }
                else
                {
                    func.IsPrototypeOnly = true;
                }

                FunctionParameter parameter = new FunctionParameter(parameterType, parameterName);
                parameter.Modifiers = modifiers;

                if (_source.NextIsKeyword(PredefinedSymbol.SetEqual))
                {
                    parameter.DefaultValue = _source.ReadNextAsConstInt();
                }

                if (_source.NextIsKeyword(PredefinedSymbol.CloseParenthesis))
                {
                    atEndOfParameterList = true;
                }
                else
                {
                    _source.ExpectKeyword(PredefinedSymbol.Comma);
                }

                func.Parameters.Add(parameter);
            }
        }
        private void DeclareLocalVariable(Token variableType)
        {
            _source.IgnoreAsteriskIfPresent();

            Token variableName = _source.ReadNextTokenAndThrowIfAlreadyDefined();

            CompilerUtils.SetArrayPropertiesOnTokenFromStream(_source, variableName);

            CompilerUtils.VerifyModifiersAgainstType(ModifierTargets.LocalVariable, _state.NextTokenModifiers);

            /* TODO: get this working
             * ScriptVariable newVariable = ProcessVariableDeclaration(variableType, _output.GlobalData, null, _state.NextTokenModifiers);
             *
             * variableName.Define(TokenType.LocalVariable, newVariable); */

            if (_source.NextIsKeyword(PredefinedSymbol.SetEqual))
            {
                Expression setEqualTo = ReadExpression(false, PredefinedSymbol.Semicolon, PredefinedSymbol.Comma);
                // TODO: check types, assign result to variable
            }
        }
Exemple #3
0
 private void VerifyModifiersAgainstType(ModifierTargets target)
 {
     CompilerUtils.VerifyModifiersAgainstType(target, _state.NextTokenModifiers);
 }