public ExternFunctionToken(Token parent, Scope scope, IEnumerable<Token> tokens, Token dataTypeToken, IdentifierToken nameToken, BracketsToken argsToken)
     : base(parent, scope, new Span(tokens.First().Span.Start, tokens.Last().Span.End))
 {
     _tokens = tokens.ToArray();
     _dataTypeToken = dataTypeToken;
     _nameToken = nameToken;
     _argsToken = argsToken;
 }
        public FunctionCallToken(Token parent, Scope scope, IdentifierToken nameToken, BracketsToken argsToken)
            : base(parent, scope, new Span(nameToken.Span.Start, argsToken.Span.End))
        {
            _nameToken = nameToken;
            _argsToken = argsToken;

            _nameToken.Parent = this;
            _argsToken.Parent = this;
        }
Exemple #3
0
        private DefineToken(Token parent, Scope scope, IEnumerable<Token> tokens, IdentifierToken nameToken, BracketsToken argsToken, IEnumerable<Token> bodyTokens)
            : base(parent, scope, new Span(tokens.First().Span.Start, tokens.Last().Span.End))
        {
            _tokens = tokens.ToArray();
            foreach (var token in _tokens) token.Parent = this;

            _nameToken = nameToken;
            _argsToken = argsToken;
            _bodyTokens = bodyTokens.ToArray();

            if (_argsToken == null && _bodyTokens.Length == 1 &&
                (_bodyTokens[0].GetType() == typeof(DataTypeToken) || _bodyTokens[0].GetType() == typeof(DataTypeKeywordToken)))
            {
                _isDataType = true;
                //File.AddDefinedDataType(_nameToken.Text);
            }
        }
Exemple #4
0
        public FunctionToken(Token parent, Scope scope, IEnumerable<Token> tokens, Token dataTypeToken, IdentifierToken nameToken, BracketsToken argsToken, BracesToken scopeToken)
            : base(parent, scope, new Span(tokens.First().Span.Start, tokens.Last().Span.End))
        {
            _tokens = tokens.ToArray();

            _dataTypeToken = dataTypeToken;
            if (_dataTypeToken != null) _dataTypeToken.Parent = this;

            _nameToken = nameToken;
            _nameToken.Parent = this;

            _argsToken = argsToken;
            _argsToken.Parent = this;

            _scopeToken = scopeToken;
            _scopeToken.Parent = this;

            foreach (var tok in _tokens) tok.Parent = this;
        }
Exemple #5
0
        public static FunctionToken TryParse(Token parent, Scope scope, Token dataTypeToken, IdentifierToken nameToken)
        {
            if ((scope.Hint & ScopeHint.SuppressFunctionDefinition) != 0) return null;

            var startPos = scope.File.Position;

            var tokens = new List<Token>();
            if (dataTypeToken != null) tokens.Add(dataTypeToken);
            tokens.Add(nameToken);

            var argsScope = scope;
            argsScope.Hint |= ScopeHint.FunctionArgs;

            var token = scope.File.ParseSingleToken(parent, argsScope);
            if (token == null || token.GetType() != typeof(BracketsToken))
            {
                scope.File.Position = startPos;
                return null;
            }

            var argsToken = token as BracketsToken;
            tokens.Add(argsToken);

            var innerScope = scope;
            innerScope.Hint |= ScopeHint.SuppressFunctionDefinition | ScopeHint.NotOnRoot;

            var scopeToken = null as BracesToken;
            var optionsTokens = new List<Token>();

            var done = false;
            while (!done)
            {
                token = scope.File.ParseSingleToken(parent, innerScope);
                if (token == null)
                {
                    scope.File.Position = startPos;
                    return null;
                }

                if (token.GetType() == typeof(BracesToken))
                {
                    tokens.Add(token);
                    scopeToken = token as BracesToken;
                    done = true;
                }
                else if (token.BreaksStatement)
                {
                    scope.File.Position = startPos;
                    return null;
                }
                else
                {
                    tokens.Add(token);
                    optionsTokens.Add(token);
                }
            }

            return new FunctionToken(parent, scope, tokens, dataTypeToken, nameToken, argsToken, scopeToken);
        }
        public static VariableDeclarationToken TryParse(Token parent, Scope scope, Token dataTypeToken, IdentifierToken nameToken)
        {
            if (scope.Hint.HasFlag(ScopeHint.SuppressVarDecl)) return null;

            var startPos = scope.File.Position;

            var tokens = new List<Token>();
            tokens.Add(dataTypeToken);
            tokens.Add(nameToken);

            var nameTokens = new List<IdentifierToken>();
            nameTokens.Add(nameToken);

            if (scope.Hint.HasFlag(ScopeHint.FunctionArgs))
            {
                var token = scope.File.ParseSingleToken(parent, scope);
                if (token == null || (token.GetType() != typeof(StatementEndToken) && token.GetType() != typeof(DelimiterToken)))
                {
                    scope.File.Position = startPos;
                    return null;
                }
                tokens.Add(token);
            }
            else
            {
                var done = false;
                var needDelim = true;
                while (!done)
                {
                    var token = scope.File.ParseSingleToken(parent, scope);
                    if (token == null)
                    {
                        scope.File.Position = startPos;
                        return null;
                    }

                    if (token.GetType() == typeof(StatementEndToken))
                    {
                        done = true;
                        tokens.Add(token);
                    }
                    else if (needDelim && token.GetType() == typeof(DelimiterToken))
                    {
                        needDelim = false;
                        tokens.Add(token);
                    }
                    else if (!needDelim && token.GetType() == typeof(IdentifierToken))
                    {
                        needDelim = true;
                        tokens.Add(token);
                        nameTokens.Add(token as IdentifierToken);
                    }
                    else if (needDelim && token.GetType() == typeof(ArrayBracesToken))
                    {
                        // This is an array variable.
                        tokens.Add(token);
                    }
                    else
                    {
                        scope.File.Position = startPos;
                        return null;
                    }
                }
            }

            return new VariableDeclarationToken(parent, scope, tokens, dataTypeToken, nameTokens);
        }