Beispiel #1
0
            protected override void VisitStarExpression(StarExpression star)
            {
                CS.IndentInOut(
                    "StarExpression",
                    () =>
                {
                    using var start    = Locals.Use("start");
                    using var nodes    = Locals.Use("nodes");
                    using var location = Locals.Use("location");
                    using var node     = Locals.Use("node");
                    CS.Ln($"{start} = {Cfg.CurName};");
                    CS.Ln($"{nodes} = new List<INode>(10);");
                    Locals.PeekPrep(Writer);
                    CS.ForEver(
                        () =>
                    {
                        VisitExpression(star.Expression);
                        CS.If(
                            $"{Locals.Result}.IsSuccess",
                            () =>
                        {
                            CS.Ln($"{Cfg.CurName} = {Locals.Result}.Next;");
                            CS.Ln($"{nodes}.AddRange({Locals.Result}.Nodes);");
                        },
                            () =>
                        {
                            CS.Ln("break;");
                        });
                    });

                    CS.Ln($"{location} = Location.From({start}, {Cfg.CurName});");
                    CS.Ln($"{node} = NodeList.From({location}, NodeSymbols.Star, {nodes});");
                    CS.Ln($"{Locals.Result} = Result.Success({location}, {Cfg.CurName}, {node});");
                });
            }
Beispiel #2
0
        private Expression Suffix(INode node)
        {
            if (node.Name == "quantified")
            {
                Debug.Assert(node.Count == 2);

                var expression = Primary(node[0]);
                switch (node[1].Name)
                {
                case "?":
                    return(OptionalExpression.From(node, expression));

                case "*":
                    return(StarExpression.From(node, expression));

                case "+":
                    return(PlusExpression.From(node, expression));

                default:
                    throw new NotImplementedException();
                }
            }

            return(Primary(node));
        }
Beispiel #3
0
 protected override void VisitStarExpression(StarExpression expression)
 {
     base.VisitStarExpression(expression);
     if (expression.Expression.Attr.IsNullable)
     {
         Results.AddError(new MessageError(MessageCode.NullableManyContent, expression));
     }
 }
 public override void VisitStarExpression(StarExpression node)
 {
     if (node.Parent is BinaryExpression b)
     {
         // use dynamic type as union of all column types
         _binder.SetSemanticInfo(node, new SemanticInfo(ScalarTypes.Dynamic));
     }
     else
     {
         // stand alone asterisk equiv to 'true'
         _binder.SetSemanticInfo(node, new SemanticInfo(ScalarTypes.Bool));
     }
 }
Beispiel #5
0
            private static Expression Expression(INode node)
            {
                switch (node.Name)
                {
                case "sequence": return(Sequence(node));

                case "choice": return(Choice(node));

                case "prefix.drop": return(DropExpression.From(node[0], Expression(node[0])));

                case "prefix.lift": return(LiftExpression.From(node[0], Expression(node[0])));

                case "prefix.fuse": return(FuseExpression.From(node[0], Expression(node[0])));

                case "prefix.not": return(NotExpression.From(node[0], Expression(node[0])));

                case "suffix.zero-or-more": return(StarExpression.From(node[0], Expression(node[0])));

                case "suffix.one-or-more": return(PlusExpression.From(node[0], Expression(node[0])));

                case "suffix.zero-or-one": return(OptionalExpression.From(node[0], Expression(node[0])));

                case "inline": return(InlineExpression.From(node[0], Tree.Rule.From(Identifier(node[0]), Expression(node[1]))));

                case "identifier": return(NameExpression.From(node, Identifier(node)));

                case "any": return(AnyExpression.From(node));

                case "verbatim-string": return(StringLiteralExpression.From(node, ((ILeaf)node).Value));

                case "character-class": return(Class(node));

                case "string": return(String(node));

                default:
                    throw new NotImplementedException();
                }
            }
Beispiel #6
0
 protected override void VisitStarExpression(StarExpression expression)
 {
     MaybeParent(expression.Expression is PrefixExpression, expression.Expression);
     Writer.Write($"{OpSymbols.Star}");
 }
 public override void VisitStarExpression(StarExpression node)
 {
     // use dynamic type as union of all column types
     _binder.SetSemanticInfo(node, new SemanticInfo(ScalarTypes.Dynamic));
 }
Beispiel #8
0
            public SingleExpression(TextReader reader)
            {
                while (reader.Peek() != -1)
                {
                    char c = (char)reader.Peek();

                    if (c == '(')
                    {
                        reader.Read();
                        Expression = new SingleExpression(reader);
                        if ((char)reader.Read() != ')')
                        {
                            throw new Exception("Expected )");
                        }
                    }
                    else if (c == ')')
                    {
                        return;
                    }
                    else if (c == '[')
                    {
                        reader.Read();
                        Expression = new RangeExpression(reader);
                        if ((char)reader.Read() != ']')
                        {
                            throw new Exception("Expected ]");
                        }
                    }
                    else if (c == '{')
                    {
                        reader.Read();
                        Expression = new RepeatExpression(reader)
                        {
                            Expression = Expression
                        };
                        if ((char)reader.Read() != '}')
                        {
                            throw new Exception("Expected }");
                        }
                    }
                    else if (c == '|')
                    {
                        reader.Read();
                        Expression = new OrExpression {
                            Left = Expression, Right = new SingleExpression(reader)
                        };
                    }
                    else if (c == '.')
                    {
                        reader.Read();
                        Expression = new ConcatExpression {
                            Left = Expression, Right = new SingleExpression(reader).Expression
                        };
                    }
                    else if (c == '*')
                    {
                        reader.Read();
                        Expression = new StarExpression {
                            Expression = Expression
                        };
                    }
                    else if (c == '+')
                    {
                        reader.Read();
                        Expression = new PlusExpression {
                            Expression = Expression
                        };
                    }
                    else
                    {
                        throw new Exception("Unexpected " + c);
                    }
                }
            }
Beispiel #9
0
 protected override void VisitStarExpression(StarExpression star)
 {
     VisitExpression(star.Expression);
     Push(new Star(Pop()));
 }
Beispiel #10
0
            public SingleExpression(TextReader reader)
            {
                while (reader.Peek() != -1)
                {
                    char c = (char)reader.Peek();

                    if (c == '(')
                    {
                        reader.Read();
                        Expression = new SingleExpression(reader);
                        if ((char)reader.Read() != ')')
                            throw new Exception("Expected )");
                    }
                    else if (c == ')')
                    {
                        return;
                    }
                    else if (c == '[')
                    {
                        reader.Read();
                        Expression = new RangeExpression(reader);
                        if ((char)reader.Read() != ']')
                            throw new Exception("Expected ]");
                    }
                    else if (c == '{')
                    {
                        reader.Read();
                        Expression = new RepeatExpression(reader) { Expression = Expression };
                        if ((char)reader.Read() != '}')
                            throw new Exception("Expected }");
                    }
                    else if (c == '|')
                    {
                        reader.Read();
                        Expression = new OrExpression { Left = Expression, Right = new SingleExpression(reader) };
                    }
                    else if (c == '.')
                    {
                        reader.Read();
                        Expression = new ConcatExpression { Left = Expression, Right = new SingleExpression(reader).Expression };
                    }
                    else if (c == '*')
                    {
                        reader.Read();
                        Expression = new StarExpression { Expression = Expression };
                    }
                    else if (c == '+')
                    {
                        reader.Read();
                        Expression = new PlusExpression { Expression = Expression };
                    }
                    else
                    {
                        throw new Exception("Unexpected " + c);
                    }
                }
            }
Beispiel #11
0
 protected override void VisitStarExpression(StarExpression expression)
 {
     base.VisitStarExpression(expression);
     SetNullable(expression, expression.Expression.Attr.IsNullable);
 }
Beispiel #12
0
 public override T VisitStarExpression(StarExpression node)
 {
     throw new NotImplementedException();
 }