Exemplo n.º 1
0
        public static Parser Create(ParseStyle parseStyle)
        {
            if (parseStyle == ParseStyle.Basic)
                return new BasicParser();
            if (parseStyle == ParseStyle.Gnu)
                return new GnuParser();
            if (parseStyle == ParseStyle.Posix)
                return new PosixParser();

            throw new ArgumentException("The parse style is not supported");
        }
Exemplo n.º 2
0
        public static Parser Create(ParseStyle parseStyle)
        {
            if (parseStyle == ParseStyle.Basic)
            {
                return(new BasicParser());
            }
            if (parseStyle == ParseStyle.Gnu)
            {
                return(new GnuParser());
            }
            if (parseStyle == ParseStyle.Posix)
            {
                return(new PosixParser());
            }

            throw new ArgumentException("The parse style is not supported");
        }
Exemplo n.º 3
0
        private static ErlangListItemSyntax ParseListItem(TokenBuffer buffer, ParseStyle style)
        {
            var expression = ParseExpression(buffer, style);

            if (expression != null)
            {
                ErlangPunctuationToken separator = null;
                var sep = buffer.Peek();
                if (ErlangToken.IsComma(sep) || ErlangToken.IsPipe(sep))
                {
                    buffer.Advance();
                    separator = (ErlangPunctuationToken)sep;
                }

                return(new ErlangListItemSyntax(expression, separator));
            }

            return(null);
        }
Exemplo n.º 4
0
        public ArgumentParser(ParseStyle style, IReadOnlyInvariantSet <Argument> arguments)
        {
            if (ArgumentParser.NotImplementedStyles.Contains(style))
            {
                throw new NotImplementedException("Specified parsing style is not yet implemented.");
            }

            this.Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments));
            this.Style     = style;

            this.parser = style switch
            {
                ParseStyle.DOS => DosParser.Singleton,
                ParseStyle.GNU => GnuParser.Singleton,
                ParseStyle.MSBuild => MsBuildParser.Singleton,
                ParseStyle.Posix => PosixParser.Singleton,
                ParseStyle.Unity => UnityParser.Singleton,
                ParseStyle.Windows => WindowsParser.Singleton,
                _ => throw new NotImplementedException("Unrecognized parse style.")
            };

            this.parser.ThrowIfIllegal(arguments);
        }
Exemplo n.º 5
0
        public void HandleCommandLine(string[] args, ParseStyle parseStyle)
        {
            ICommandLineParser parser = Parser.Create(parseStyle);

            HandleCommandLine(args, parser);
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        internal static ErlangListComprehensionFilterSyntax Parse(TokenBuffer buffer, ParseStyle style)
        {
            var expression = ParseExpression(buffer, style);

            if (expression != null)
            {
                ErlangCommaToken comma = null;
                var next = buffer.Peek();
                if (ErlangToken.IsComma(next))
                {
                    buffer.Advance();
                    comma = (ErlangCommaToken)next;
                }

                return(new ErlangListComprehensionFilterSyntax(expression, comma));
            }

            return(null);
        }
Exemplo n.º 8
0
        internal static ErlangListComprehensionGeneratorSyntax Parse(TokenBuffer buffer, ParseStyle style)
        {
            var start      = buffer.Offset;
            var expression = ParseExpression(buffer, style);

            if (expression != null)
            {
                var next = buffer.Peek();
                if (ErlangToken.IsLeftArrow(next))
                {
                    buffer.Advance();
                    var arrow    = (ErlangLessMinusToken)next;
                    var function = ParseExpression(buffer, style);
                    if (function != null)
                    {
                        ErlangCommaToken comma = null;
                        next = buffer.Peek();
                        if (ErlangToken.IsComma(next))
                        {
                            buffer.Advance();
                            comma = (ErlangCommaToken)next;
                        }

                        return(new ErlangListComprehensionGeneratorSyntax(expression, arrow, function, comma));
                    }
                }
            }

            buffer.SetOffset(start);
            return(null);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 public void HandleCommandLine(string[] args, ParseStyle parseStyle)
 {
     ICommandLineParser parser = Parser.Create(parseStyle);
     HandleCommandLine(args, parser);
 }