Example #1
0
        public static bool TryParseHighwayContractRouteBox(string input, out HighwayContractRouteBoxSyntaxNode result)
        {
            var tokens = Tokenizer.Tokenize(input).Reverse().ToImmutableArray();

            var state = new ParserState(tokens);

            var success = TryParseHighwayContractRouteBox(ref state, out var syntax) && state.Current.IsNone;

            result = success ? syntax : null;

            return(success);
        }
Example #2
0
        private static bool TryParseHighwayContractRouteBox(ref ParserState state, out HighwayContractRouteBoxSyntaxNode result)
        {
            result = null;

            var snapshot = state;

            RangeSyntaxNode        routeNumber;
            ImmutableArray <Token> boxKeywordTokens;

            if (TryParseRange(ref state, out var boxNumber))
            {
                state.ConsumeWhiteSpace();

                if (state.TryConsume(t => t.IsOctothorpe))
                {
                    state.ConsumeWhiteSpace();
                }

                if (state.TryConsume("box"))
                {
                    state.ConsumeWhiteSpace();

                    if (state.TryConsume(t => t.IsCommaOrPeriod))
                    {
                        state.ConsumeWhiteSpace();
                    }

                    boxKeywordTokens = state.TakeBuffer();

                    if (TryParseRange(ref state, out routeNumber))
                    {
                        state.ConsumeWhiteSpace();

                        if (state.TryConsume(t => t.IsOctothorpe))
                        {
                            state.ConsumeWhiteSpace();
                        }

                        if (state.TryConsume(t => t.IsCommaOrPeriod))
                        {
                            state.ConsumeWhiteSpace();
                        }

                        if (state.TryConsume("hc"))
                        {
                            goto Parsed;
                        }

                        if (state.TryConsume("c"))
                        {
                            state.ConsumeWhiteSpace();

                            if (state.TryConsume(t => t.IsCommaOrPeriod))
                            {
                                state.ConsumeWhiteSpace();
                            }

                            if (state.TryConsume("h"))
                            {
                                goto Parsed;
                            }
                        }
                        else if (state.TryConsume(t => t.Matches("route") || t.Matches("rt")))
                        {
                            state.ConsumeWhiteSpace();

                            if (state.TryConsume("contract"))
                            {
                                state.ConsumeWhiteSpace();

                                if (state.TryConsume("highway"))
                                {
                                    goto Parsed;
                                }
                            }
                            else if (state.TryConsume("star"))
                            {
                                goto Parsed;
                            }
                        }
                        else if (state.TryConsume("contract"))
                        {
                            state.ConsumeWhiteSpace();

                            if (state.TryConsume("highway"))
                            {
                                goto Parsed;
                            }
                        }
                    }
                }
            }

            state = snapshot;

            return(false);

Parsed:

            result = new HighwayContractRouteBoxSyntaxNode(
                state.TakeBuffer(),
                routeNumber,
                boxKeywordTokens,
                boxNumber);

            return(true);
        }