Ejemplo n.º 1
0
 public ErlangListComprehensionSyntax(
     ErlangLeftBracketToken leftBracket,
     ErlangExpressionSyntax expression,
     ErlangPipePipeToken doublePipe,
     IEnumerable <ErlangSeparatedSyntaxNodeSyntax <ErlangListComprehensionGeneratorSyntax> > generators,
     IEnumerable <ErlangSeparatedSyntaxNodeSyntax <ErlangListComprehensionFilterSyntax> > filters,
     ErlangRightBracketToken rightBracket)
     : base(leftBracket, rightBracket)
 {
     Expression = expression;
     DoublePipe = doublePipe;
     Generators = new SyntaxList <ErlangSeparatedSyntaxNodeSyntax <ErlangListComprehensionGeneratorSyntax> >(generators);
     Filters    = new SyntaxList <ErlangSeparatedSyntaxNodeSyntax <ErlangListComprehensionFilterSyntax> >(filters);
 }
Ejemplo n.º 2
0
        private static ErlangListComprehensionSyntax ParseListComprehension(ErlangLeftBracketToken leftBracket, ErlangExpressionSyntax expression, ErlangPipePipeToken doublePipe, TokenBuffer buffer, ParseStyle style)
        {
            var generators = ParseSyntaxListWithComma(buffer, style, ErlangListComprehensionGeneratorSyntax.Parse);
            var filters    = ParseSyntaxListWithComma(buffer, style, ErlangListComprehensionFilterSyntax.Parse);

            ErlangRightBracketToken rightBracket = null;
            var right = buffer.Peek();

            if (ErlangToken.IsRightBracket(right))
            {
                buffer.Advance();
                rightBracket = (ErlangRightBracketToken)right;
            }

            return(new ErlangListComprehensionSyntax(leftBracket, expression, doublePipe, generators, filters, rightBracket));
        }
Ejemplo n.º 3
0
        internal static ErlangListSyntax ParseList(TokenBuffer buffer, ParseStyle style)
        {
            var left = buffer.Peek();

            if (ErlangToken.IsString(left))
            {
                buffer.Advance();
                return(new ErlangListStringSyntax((ErlangStringToken)left));
            }
            else if (ErlangToken.IsLeftBracket(left))
            {
                buffer.Advance();
                var items = new List <ErlangListItemSyntax>();
                ErlangExpressionSyntax tail = null;
                while (buffer.TokensRemain())
                {
                    var item = ParseListItem(buffer, style);
                    if (item == null)
                    {
                        break;
                    }
                    items.Add(item);
                    if (!ErlangToken.IsComma(item.Separator))
                    {
                        break;
                    }
                }

                if (items.Count == 1 && ErlangToken.IsDoublePipe(buffer.Peek()))
                {
                    // list comprehension, parse generator expression and filters
                    // result of generator expressions get filtered, e.g.
                    //   [X || {X, some_atom} <- some_list()].
                    var listItem   = items.Single();
                    var doublePipe = (ErlangPipePipeToken)buffer.Peek();
                    buffer.Advance();
                    return(ParseListComprehension((ErlangLeftBracketToken)left, listItem.Item, doublePipe, buffer, style));
                }
                else if (items.Count > 0)
                {
                    var lastSep = items.Last().Separator;
                    if (ErlangToken.IsPipe(lastSep))
                    {
                        // list tail, only parse one more expression
                        tail = ParseExpression(buffer, style);
                    }
                    else if (lastSep != null)
                    {
                        Debug.Assert(false, "unexpected list separator");
                    }
                }

                ErlangRightBracketToken rightBracket = null;
                var next = buffer.Peek();
                if (ErlangToken.IsRightBracket(next))
                {
                    buffer.Advance();
                    rightBracket = (ErlangRightBracketToken)next;
                }
                else
                {
                    Debug.Assert(false, "Missing closing bracket");
                }

                return(new ErlangListRegularSyntax((ErlangLeftBracketToken)left, items, tail, rightBracket));
            }

            return(null);
        }
Ejemplo n.º 4
0
 public ErlangListSyntax(ErlangLeftBracketToken leftBracket, ErlangRightBracketToken rightBracket)
 {
     LeftBracket  = leftBracket;
     RightBracket = rightBracket;
 }
Ejemplo n.º 5
0
 public ErlangListRegularSyntax(ErlangLeftBracketToken leftBracket, IEnumerable <ErlangListItemSyntax> items, ErlangExpressionSyntax tail, ErlangRightBracketToken rightBracket)
     : base(leftBracket, rightBracket)
 {
     Items = new SyntaxList <ErlangListItemSyntax>(items);
     Tail  = tail;
 }
Ejemplo n.º 6
0
 public ErlangNonEmptyListOfTypeSyntax(ErlangLeftBracketToken left, ErlangTypeSyntax type, ErlangCommaToken comma, ErlangDotDotDotToken dotDotDot, ErlangRightBracketToken right)
     : base(left, type, right)
 {
     Comma     = comma;
     DotDotDot = dotDotDot;
 }
Ejemplo n.º 7
0
 public ErlangListOfTypeSyntax(ErlangLeftBracketToken left, ErlangTypeSyntax type, ErlangRightBracketToken right)
     : base(left, right)
 {
     Type = type;
 }
Ejemplo n.º 8
0
 public ErlangEmptyListTypeSyntax(ErlangLeftBracketToken left, ErlangRightBracketToken right)
     : base(left, right)
 {
 }