Exemplo n.º 1
0
        private static void ParseTag(Scope scope, GroupToken parent, KeywordToken tagToken, string[] endTokens)
        {
            var code = scope.Code;

            parent.AddToken(tagToken);

            var resetPos = code.Position;

            if (code.ReadTagName() && ProbeEnvironment.IsValidTagName(code.Text))
            {
                parent.AddToken(new KeywordToken(scope, code.Span, code.Text));
                if (code.ReadStringLiteral())
                {
                    parent.AddToken(new StringLiteralToken(scope, code.Span, code.Text));
                    return;
                }
            }
            else
            {
                code.Position = resetPos;
            }

            var exp = ExpressionToken.TryParse(scope, endTokens);

            if (exp != null)
            {
                parent.AddToken(exp);
            }
        }
Exemplo n.º 2
0
        private static void ParseFunctionAttributes(Scope scope, GroupToken parentToken)
        {
            var code = scope.Code;

            while (!code.EndOfFile)
            {
                if (code.PeekExact(';') || code.PeekExact('{') || code.PeekExact('}'))
                {
                    return;
                }

                if (code.ReadWord())
                {
                    switch (code.Text)
                    {
                    case "description":
                    case "prompt":
                    case "comment":
                    case "BEGINHLP":
                    case "accel":
                    {
                        parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text));
                        var exp = ExpressionToken.TryParse(scope, _attribEndTokens);
                        if (exp != null)
                        {
                            parentToken.AddToken(exp);
                        }
                    }
                    break;

                    case "nomenu":
                    case "ENDHLP":
                        parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text));
                        break;

                    case "tag":
                    {
                        parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text));
                        if (code.ReadTagName())
                        {
                            parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text));
                        }
                        var exp = ExpressionToken.TryParse(scope, _attribEndTokens);
                        if (exp != null)
                        {
                            parentToken.AddToken(exp);
                        }
                    }
                    break;

                    default:
                        return;
                    }
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private static bool TryParseColumnDefinition(Scope scope, GroupToken parent, Definition parentDef, bool includeNameAndDataType)
        {
            string          word;
            var             code = scope.Code;
            ExpressionToken exp;

            if (includeNameAndDataType)
            {
                // Column name
                if (parentDef != null && parentDef.AllowsChild)
                {
                    if (!string.IsNullOrEmpty(word = code.PeekWordR()))
                    {
                        var childDef = parentDef.GetChildDefinitions(word).FirstOrDefault();
                        if (childDef != null)
                        {
                            parent.AddToken(new IdentifierToken(scope, code.MovePeekedSpan(), code.Text, childDef));
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                // Data type
                if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null)
                {
                    parent.AddToken(exp);
                }
            }

            // Column attributes
            while (!code.EndOfFile)
            {
                if (code.PeekExact(')') || code.PeekExact('}') || code.PeekExact(','))
                {
                    break;
                }

                if (!string.IsNullOrEmpty(word = code.PeekWordR()))
                {
                    if (word == "prompt" || word == "comment" || word == "group" || word == "row" || word == "col" ||
                        word == "rows" || word == "cols" || word == "image")
                    {
                        parent.AddToken(new KeywordToken(scope, code.MovePeekedSpan(), code.Text));
                        if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null)
                        {
                            parent.AddToken(exp);
                        }
                        continue;
                    }

                    if (word == "endgroup" || word == "form" || word == "formonly" || word == "zoom" || word == "tool")
                    {
                        parent.AddToken(new KeywordToken(scope, code.MovePeekedSpan(), code.Text));
                        continue;
                    }

                    if (word == "tag")
                    {
                        ParseTag(scope, parent, new KeywordToken(scope, code.MovePeekedSpan(), "tag"), _columnEndTokens);
                        continue;
                    }

                    if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null)
                    {
                        parent.AddToken(exp);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null)
                    {
                        parent.AddToken(exp);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (code.ReadExact(','))
            {
                parent.AddToken(new DelimiterToken(scope, code.Span));
            }

            return(true);
        }
Exemplo n.º 4
0
        private void ParseCreateTable(KeywordToken tableToken)
        {
            AddToken(tableToken);

            var code = Code;

            // Table name
            if (!code.ReadWord())
            {
                return;
            }
            var table = DkDict.Dict.GetTable(code.Text);

            if (table != null)
            {
                AddToken(new IdentifierToken(Scope, code.Span, code.Text, table.Definition));
            }
            else
            {
                AddToken(new UnknownToken(Scope, code.Span, code.Text));
            }

            // Table number
            if (!code.ReadNumber())
            {
                return;
            }
            AddToken(new NumberToken(Scope, code.Span, code.Text));

            // Table number+1
            if (Code.ReadNumber())
            {
                AddToken(new NumberToken(Scope, code.Span, code.Text));
            }

            ExpressionToken exp;

            // Attributes
            ParseTableAttributes(_createTableEndTokens);

            BracketsToken brackets = null;
            BracesToken   braces   = null;
            GroupToken    parent   = null;

            if (code.ReadExact('('))
            {
                brackets = new BracketsToken(Scope);
                brackets.AddOpen(code.Span);
                AddToken(brackets);
                parent = brackets;
            }
            else if (code.ReadExact('{'))
            {
                braces = new BracesToken(Scope);
                braces.AddOpen(code.Span);
                AddToken(braces);
                parent = braces;
            }
            else
            {
                return;
            }

            // Columns
            while (!code.EndOfFile)
            {
                if (code.ReadExact(')') || code.ReadExact('}'))
                {
                    if (brackets != null)
                    {
                        brackets.AddClose(code.Span);
                    }
                    else if (braces != null)
                    {
                        braces.AddClose(code.Span);
                    }
                    return;
                }

                if (code.ReadExact(','))
                {
                    parent.AddToken(new DelimiterToken(Scope, code.Span));
                    continue;
                }

                if (!TryParseColumnDefinition(Scope, parent, table != null ? table.Definition : null, true))
                {
                    if ((exp = ExpressionToken.TryParse(Scope, _columnEndTokens)) != null)
                    {
                        parent.AddToken(exp);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }