Example #1
0
        public InterfaceMethodCallToken(Scope scope, VariableToken intVarToken, DotToken dotToken, IdentifierToken nameToken, BracketsToken argsToken, InterfaceMethodDefinition def)
            : base(scope)
        {
#if DEBUG
            if (intVarToken == null)
            {
                throw new ArgumentNullException("intVarToken");
            }
            if (dotToken == null)
            {
                throw new ArgumentNullException("dotToken");
            }
            if (nameToken == null)
            {
                throw new ArgumentNullException("nameToken");
            }
            if (argsToken == null)
            {
                throw new ArgumentNullException("argsToken");
            }
            if (def == null)
            {
                throw new ArgumentNullException("def");
            }
#endif
            AddToken(intVarToken);
            AddToken(dotToken);
            AddToken(_nameToken = nameToken);
            AddToken(argsToken);

            _methodDef = def;
            _nameToken.SourceDefinition = def;
        }
Example #2
0
 public RelIndAndFieldToken(Scope scope, RelIndToken relIndToken, DotToken dotToken, RelIndFieldToken fieldToken)
     : base(scope)
 {
     AddToken(relIndToken);
     AddToken(dotToken);
     AddToken(_fieldToken = fieldToken);
 }
Example #3
0
 public ClassAndFunctionToken(Scope scope, ClassToken classToken, DotToken dotToken, FunctionCallToken funcToken, Definitions.FunctionDefinition funcDef)
     : base(scope)
 {
     AddToken(classToken);
     AddToken(dotToken);
     AddToken(_funcToken = funcToken);
 }
Example #4
0
 public ExtractTableAndFieldToken(Scope scope, ExtractTableToken exToken, DotToken dotToken, ExtractFieldToken fieldToken)
     : base(scope)
 {
     AddToken(exToken);
     AddToken(dotToken);
     AddToken(fieldToken);
 }
Example #5
0
        public InterfacePropertyToken(Scope scope, VariableToken intVarToken, DotToken dotToken, IdentifierToken nameToken, InterfacePropertyDefinition propDef)
            : base(scope)
        {
#if DEBUG
            if (intVarToken == null)
            {
                throw new ArgumentNullException("intVarToken");
            }
            if (dotToken == null)
            {
                throw new ArgumentNullException("dotToken");
            }
            if (nameToken == null)
            {
                throw new ArgumentNullException("nameToken");
            }
            if (propDef == null)
            {
                throw new ArgumentNullException("propDef");
            }
#endif
            nameToken.SourceDefinition = propDef;
            _propDef = propDef;

            AddToken(intVarToken);
            AddToken(dotToken);
            AddToken(nameToken);
        }
Example #6
0
        public TableAndFieldToken(Scope scope, TableToken tableToken, DotToken dotToken, TableFieldToken fieldToken)
            : base(scope)
        {
#if DEBUG
            if (tableToken == null || dotToken == null || fieldToken == null)
            {
                throw new ArgumentNullException();
            }
#endif
            AddToken(_tableToken = tableToken);
            AddToken(dotToken);
            AddToken(_fieldToken = fieldToken);
        }
Example #7
0
        private DataType _dataType;             // Can be null

        /// <summary>
        /// Creates a function call token.
        /// </summary>
        /// <param name="scope">(required) Current scope</param>
        /// <param name="classToken">(optional) Class name token</param>
        /// <param name="dotToken">(optional) Dot delimiter between class and function name</param>
        /// <param name="nameToken">(required) Function name</param>
        /// <param name="argsToken">(required) Function args</param>
        /// <param name="def">(optional) Existing function definition</param>
        public FunctionCallToken(Scope scope, ClassToken classToken, DotToken dotToken, IdentifierToken nameToken, BracketsToken argsToken, FunctionDefinition def)
            : base(scope)
        {
#if DEBUG
            if (nameToken == null)
            {
                throw new ArgumentNullException("nameToken");
            }
            if (argsToken == null)
            {
                throw new ArgumentNullException("argsToken");
            }
#endif
            AddToken(_classToken = classToken);
            AddToken(dotToken);
            AddToken(_nameToken         = nameToken);
            _nameToken.SourceDefinition = def;
            AddToken(_argsToken         = argsToken);

            _dataType = def.DataType;
        }
Example #8
0
        private static Token ProcessWord(ExpressionToken exp, Scope scope, string word, Span wordSpan)
        {
            // Global keyword that take effect anywhere.
            switch (word)
            {
            case "static":
                return(new KeywordToken(scope, wordSpan, word));
            }

            var code = scope.Code;

            if (code.PeekExact('.'))
            {
                var dotSpan = code.MovePeekedSpan();
                var word2   = code.PeekWordR();
                if (!string.IsNullOrEmpty(word2))
                {
                    var word2Span           = code.MovePeekedSpan();
                    var argsPresent         = (scope.Hint & ScopeHint.SuppressFunctionCall) == 0 && code.PeekExact('(');
                    var argsOpenBracketSpan = argsPresent ? code.MovePeekedSpan() : Span.Empty;

                    foreach (var def in scope.DefinitionProvider.GetAny(wordSpan.Start, word))
                    {
                        if (def.AllowsChild)
                        {
                            // When arguments are present, take only the definitions that accept arguments
                            var childDefs = def.GetChildDefinitions(word2).Where(x => argsPresent ? x.ArgumentsRequired : true).ToArray();
                            if (childDefs.Any())
                            {
                                ArgsToken  argsToken = null;
                                Definition childDef  = null;

                                if (argsPresent)
                                {
                                    var openBracketToken = new OperatorToken(scope, argsOpenBracketSpan, "(");
                                    argsToken = ArgsToken.ParseAndChooseArguments(scope, openBracketToken, childDefs, out childDef);
                                }
                                else
                                {
                                    childDef = childDefs[0];
                                }

                                var word1Token = new IdentifierToken(scope, wordSpan, word, def);
                                var dotToken   = new DotToken(scope, dotSpan);
                                var word2Token = new IdentifierToken(scope, word2Span, word2, childDef);
                                var compToken  = new CompositeToken(scope, childDef.DataType);
                                compToken.AddToken(word1Token);
                                compToken.AddToken(dotToken);
                                compToken.AddToken(word2Token);
                                if (argsToken != null)
                                {
                                    compToken.AddToken(argsToken);
                                }
                                return(compToken);
                            }
                        }
                    }
                }
                else
                {
                    code.Position = dotSpan.Start;
                    return(new UnknownToken(scope, wordSpan, word));
                }
            }

            if ((scope.Hint & ScopeHint.SuppressFunctionCall) == 0 && code.PeekExact('('))
            {
                var argsOpenBracketSpan = code.MovePeekedSpan();

                foreach (var def in scope.DefinitionProvider.GetAny(wordSpan.Start, word))
                {
                    if (def.ArgumentsRequired)
                    {
                        var wordToken        = new IdentifierToken(scope, wordSpan, word, def);
                        var openBracketToken = new OperatorToken(scope, argsOpenBracketSpan, "(");
                        var argsToken        = ArgsToken.Parse(scope, openBracketToken, def.Signature);

                        var compToken = new CompositeToken(scope, def.DataType);
                        compToken.AddToken(wordToken);
                        compToken.AddToken(argsToken);

                        if (def.AllowsFunctionBody && (scope.Hint & ScopeHint.SuppressFunctionDefinition) == 0)
                        {
                            ParseFunctionAttributes(exp, scope, compToken);
                            if (code.PeekExact('{'))
                            {
                                compToken.AddToken(BracesToken.Parse(scope, def, argsToken.Span.End + 1));
                            }
                        }

                        return(compToken);
                    }
                }
            }

            foreach (var def in scope.DefinitionProvider.GetAny(wordSpan.Start, word))
            {
                if (def.ArgumentsRequired || def.RequiresChild)
                {
                    continue;
                }

                return(new IdentifierToken(scope, wordSpan, word, def));
            }

            if (StatementToken.IsStatementBreakingWord(scope, word))
            {
                // There could be a statement without a terminating ';' before this.
                // This can happen if it's a macro that already includes the ';'.
                return(null);
            }

            if (Constants.HighlightKeywords.Contains(word))
            {
                return(new KeywordToken(scope, wordSpan, word));
            }

            return(new UnknownToken(scope, wordSpan, word));
        }
Example #9
0
        private static bool TryParseColumn(Scope scope, GroupToken parent, bool allowRelInd, ExtractTableDefinition extractDef)
        {
            var code = scope.Code;

            if (code.ReadWord())
            {
                var wordPos = code.TokenStartPostion;

                var table = DkDict.Dict.GetTable(code.Text);
                if (table != null)
                {
                    var tableToken = new TableToken(scope, code.Span, code.Text, table.Definition);
                    if (code.ReadExact('.'))
                    {
                        var dotToken = new DotToken(scope, code.Span);
                        if (code.ReadWord())
                        {
                            var field = table.GetColumn(code.Text);
                            if (field != null)
                            {
                                var fieldName = code.Text;
                                var fieldSpan = code.Span;

                                var fieldToken = new TableFieldToken(scope, fieldSpan, fieldName, field);
                                parent.AddToken(new TableAndFieldToken(scope, tableToken, dotToken, fieldToken));
                            }
                            else
                            {
                                parent.AddToken(new CompositeToken(scope, null, tableToken, dotToken, new UnknownToken(scope, code.Span, code.Text)));
                            }
                        }
                        else
                        {
                            parent.AddToken(new CompositeToken(scope, null, tableToken, dotToken));
                        }
                    }
                    else
                    {
                        parent.AddToken(tableToken);
                    }
                    return(true);
                }

                if (allowRelInd)
                {
                    var relind = DkDict.Dict.GetRelInd(code.Text);
                    if (relind != null)
                    {
                        parent.AddToken(new RelIndToken(scope, code.Span, code.Text, relind.Definition));
                        return(true);
                    }
                }

                if (extractDef != null && code.Text == extractDef.Name)
                {
                    parent.AddToken(new IdentifierToken(scope, code.Span, code.Text, extractDef));
                    if (code.ReadExact('.'))
                    {
                        parent.AddToken(new DotToken(scope, code.Span));
                        var word = code.PeekWordR();
                        if (!string.IsNullOrEmpty(word))
                        {
                            var childDef = extractDef.GetChildDefinitions(word).FirstOrDefault();
                            if (childDef != null)
                            {
                                parent.AddToken(new IdentifierToken(scope, code.MovePeekedSpan(), word, childDef));
                            }
                        }
                    }
                    return(true);
                }

                // Word was not recognized, so set parser back to before the word so it can get picked up later.
                code.Position = wordPos;
            }

            return(false);
        }