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);
        }
Exemple #2
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);
        }