コード例 #1
0
        public void TestLessAndGreater()
        {
            ArgumentToken <int> token = new ArgumentToken <int> .Builder().Name("arg").Parser(int.TryParse).Build();

            TokenMatchResult result1 = new TokenMatchResult(token, "12345", "12345", MatchOutcome.Full, 5, 1);

            TokenMatchResult result2 = new TokenMatchResult(token, "123", "123", MatchOutcome.Full, 3, 1);

            TokenMatchResult result3 = new TokenMatchResult(token, "12345", "12345", MatchOutcome.Partial, 3, 1);


            TokenMatchResult result4 = new TokenMatchResult(token, "123 45", "123 45", MatchOutcome.Full, 5, 2);

            //Chars matched
            Assert.False(result1 <= result2);
            Assert.False(result1 < result2);
            Assert.True(result1 > result2);
            Assert.True(result1 >= result2);

            //Outcome
            Assert.True(result1 > result3);
            Assert.True(result2 > result3);

            //Tokens Matched
            Assert.True(result1 < result4);
            Assert.True(result4 > result1);
        }
コード例 #2
0
        /// <summary>
        /// If,elseステートメントの開始
        /// </summary>
        /// <param defaultName="primitives"></param>
        /// <returns></returns>
        private static IfStatement readIf(TokenCollection stream)
        {
            IfStatementPrimitive token = stream.GetNextToken() as IfStatementPrimitive;

            if (token == null)
            {
                throw new HspLogicalLineException("条件分岐行:条件分岐プリミティブ以外からスタート");
            }

            //elseには式がない。
            if (stream.NextIsEndOfLine)
            {
                return(new IfStatement(token));
            }
            else
            {
                //式を読む。あまりが出なければOK
                ArgumentToken arg = CodeTokenFactory.ReadArgument(stream);
                if (stream.NextIsEndOfLine)
                {
                    return(new IfStatement(token, arg));
                }
            }
            throw new HspLogicalLineException("条件分岐行:余分なトークンがある");
        }
コード例 #3
0
        public void TestParseWithStringArg()
        {
            VerbToken token1 = new VerbToken(new Name("verb1", "a"));

            ArgumentToken token2 = TokenUtils.BuildArgString("arg1");

            CommandRoot command1 = new CommandRoot.Builder()
                                   .Id(0)
                                   .Description("command")
                                   .WithToken(token1)
                                   .WithUsage(new CommandUsage.Builder()
                                              .Description("usage1")
                                              .WithToken(token2)
                                              .Build())
                                   .Build();

            CommandLibrary library = new CommandLibrary();

            library.AddCommand(command1);

            CommandUsageMatchData matchData = library.Parse("verb1 \"the entire string\"");

            Assert.True(matchData.IsSuccessful);
            Assert.True(matchData.HasToken(token1));
            Assert.True(matchData.HasToken(token2));

            bool hasArg1Val = matchData.TryGetArgValue(token2, out string arg1Val);

            Assert.True(hasArg1Val);
            Assert.Equal("the entire string", arg1Val);
        }
コード例 #4
0
        public void TestParse()
        {
            VerbToken token1 = new VerbToken(new Name("verb1", "a"));

            ArgumentToken token2 = new ArgumentToken <int> .Builder().Name("arg").Parser(int.TryParse).IsOptional(false).Build();

            CommandRoot command1 = new CommandRoot.Builder()
                                   .Id(0)
                                   .Description("command")
                                   .WithToken(token1)
                                   .WithUsage(new CommandUsage.Builder()
                                              .Description("usage1")
                                              .WithToken(token2)
                                              .Build())
                                   .Build();

            CommandLibrary library = new CommandLibrary();

            library.AddCommand(command1);

            CommandUsageMatchData matchData = library.Parse("verb1 123");

            Assert.True(matchData.IsSuccessful);
            Assert.True(matchData.HasToken(token1));
            Assert.True(matchData.HasToken(token2));

            bool hasArgVal = matchData.TryGetArgValue(token2, out int argVal);

            Assert.True(hasArgVal);
            Assert.Equal(123, argVal);
        }
コード例 #5
0
        public void TestOptionWithQuotedStringNotFullMatch(string input)
        {
            ICommandArgumentToken <string> .ValueParser trivialStringParser = (string i, out string v) => { v = i; return(true); };

            ArgumentToken arg1 = new ArgumentToken <string> .Builder().Name("arg1").Parser(trivialStringParser).Build();

            ArgumentToken arg2 = new ArgumentToken <string> .Builder().Name("arg2").Parser(trivialStringParser).Build();

            ArgumentToken arg3 = new ArgumentToken <string> .Builder().Name("arg3").Parser(trivialStringParser).Build();

            var token = new OptionWithArgumentToken.Builder()
                        .Name("option", "alt1", "alt2")
                        .WithArgument(arg1)
                        .WithArgument(arg2)
                        .WithArgument(arg3)
                        .Build();

            ICommandUsage usage = new CommandUsage.Builder().WithToken(token).Build();

            TokenMatchCollection matchCollection = CommandParser.Match(usage.Tokens, input);

            Assert.True(matchCollection.Matches.Count() == 1);
            ParserTokenMatch match = matchCollection.Matches.First();

            Assert.False(match.IsFullMatch, input);
        }
コード例 #6
0
        } /* end ParseInfoRequest */

/* ---------------------------------------------------------------------------
 * private method ParseCompilationRequest(sym)
 * ---------------------------------------------------------------------------
 * compilationRequest :
 *   dialect? products? capabilities? sourceFile diagnostics?
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseCompilationRequest(ArgumentToken sym)
        {
            if (ArgumentLexer.IsDialectOption(sym))
            {
                sym = ParseDialect(sym);
            } /* end */

            if (ArgumentLexer.IsProductOption(sym))
            {
                sym = ParseProducts(sym);
            } /* end */

            if (ArgumentLexer.IsCapabilityOption(sym))
            {
                sym = ParseCapabilities(sym);
            } /* end */

            if (sym == ArgumentToken.SOURCE_FILE)
            {
                sym = ParseSourceFile(sym);
            }
            else
            {
                ReportMissingSourceFile();
            } /* end if */

            if (ArgumentLexer.IsDiagnosticsOption(sym))
            {
                sym = ParseDiagnostics(sym);
            } /* end */

            return(sym);
        } /* end ParseCompilationRequest */
コード例 #7
0
        public void TestMatchArgValuesWithOptionalTokens()
        {
            ArgumentToken arg1 = new ArgumentToken <int> .Builder().Name("arg1").IsOptional(false).Parser(int.TryParse).Build();

            ArgumentToken arg2 = new ArgumentToken <double> .Builder().Name("arg2").IsOptional(false).Parser(double.TryParse).Build();

            var tokens = new ICommandToken[]
            {
                new VerbToken(new Name("verb0")),
                new OptionWithArgumentToken.Builder().Name("-o2", "--option2").WithArgument(arg1).WithArgument(arg2).Build(),
            };

            var builder = new CommandUsage.Builder().Description("test usage");

            foreach (var token in tokens)
            {
                builder.WithToken(token);
            }

            ICommandUsage usage = builder.Build();

            TokenMatchCollection matchCollection = CommandParser.Match(usage.Tokens, "verb0 -o2 1 2.34");

            int  arg1Value;
            bool arg1Exists = matchCollection.TryGetArgValue(arg1, out arg1Value);

            double arg2Value;
            bool   arg2Exists = matchCollection.TryGetArgValue(arg2, out arg2Value);

            Assert.True(arg1Exists);
            Assert.True(arg2Exists);
            Assert.Equal(1, arg1Value);
            Assert.Equal(2.34, arg2Value);
        }
コード例 #8
0
        [InlineData("-o2 1", false)]      //partial match
        public void TestTokenIsFullMatch(string input, bool expIsFullMatch)
        {
            ArgumentToken arg1 = new ArgumentToken <int> .Builder().Name("arg1").IsOptional(false).Parser(int.TryParse).Build();

            ArgumentToken arg2 = new ArgumentToken <double> .Builder().Name("arg2").IsOptional(false).Parser(double.TryParse).Build();

            var tokens = new ICommandToken[]
            {
                new OptionWithArgumentToken.Builder().Name("-o2", "--option2").WithArgument(arg1).WithArgument(arg2).Build()
            };
            var builder = new CommandUsage.Builder()
                          .Description("test usage");

            foreach (var token in tokens)
            {
                builder.WithToken(token);
            }

            ICommandUsage usage = builder.Build();

            TokenMatchCollection matchCollection = CommandParser.Match(usage.Tokens, input);

            Assert.Same(usage.Tokens, matchCollection.MatchableTokens);
            Assert.NotEmpty(matchCollection.Matches);

            Assert.Equal(1, matchCollection.Matches.Count());
            ParserTokenMatch match = matchCollection.Matches.First();

            Assert.Equal(expIsFullMatch, match.IsFullMatch);
        }
コード例 #9
0
        } /* end  */

/* ---------------------------------------------------------------------------
 * private method ParseDiagnostics(sym)
 * ---------------------------------------------------------------------------
 * diagnostics :
 *   ( VERBOSE | LEXER_DEBUG | PARSER_DEBUG | PRINT_SETTINGS
 *     ERRANT_SEMICOLONS )+
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseDiagnostics(ArgumentToken sym)
        {
            while (ArgumentLexer.IsDiagnosticsOption(sym))
            {
                switch (sym)
                {
                case ArgumentToken.VERBOSE:
                    CompilerOptions.SetOption(Option.Verbose, true);
                    break;

                case ArgumentToken.LEXER_DEBUG:
                    CompilerOptions.SetOption(Option.LexerDebug, true);
                    break;

                case ArgumentToken.PARSER_DEBUG:
                    CompilerOptions.SetOption(Option.ParserDebug, true);
                    break;

                case ArgumentToken.SHOW_SETTINGS:
                    CompilerOptions.SetOption(Option.ShowSettings, true);
                    break;

                case ArgumentToken.ERRANT_SEMICOLONS:
                    CompilerOptions.SetOption(Option.ErrantSemicolons, true);
                    break;
                } /* end switch */

                sym = ArgumentLexer.NextToken();
            } /* end while*/

            return(sym);
        } /* end ParseDiagnostics */
コード例 #10
0
        /// <summary>
        /// 代入行
        /// </summary>
        /// <param defaultName="primitives"></param>
        /// <returns></returns>
        private static Assignment readAssignment(TokenCollection stream)
        {
            //変数を読む。失敗したら代入行じゃない。
            VariableToken token = CodeTokenFactory.ReadVariable(stream);

            //演算子を読む。失敗するなら代入行じゃない。
            if (stream.NextIsEndOfLine)
            {
                throw new HspLogicalLineException("代入行:演算子なし");
            }
            OperatorToken op = CodeTokenFactory.ReadOperator(stream);

            //式が続かないこともある。"x++"とか
            if (stream.NextIsEndOfLine)
            {
                return(new Assignment(token, op));
            }
            else
            {
                //引数を読む。あまりが出なければOK
                ArgumentToken arg = CodeTokenFactory.ReadArgument(stream);
                if (stream.NextIsEndOfLine)
                {
                    return(new Assignment(token, op, arg));
                }
            }
            throw new HspLogicalLineException("代入行:余分なトークンがある");
        }
コード例 #11
0
        public void TestParseArgument()
        {
            var arguments = new[] { "--some-option", "file1.bmp", "file2.png" };
            var tokens    = ArgumentToken.ParseArgument(arguments).ToArray();
            var expected  = new[] { new ArgumentToken("--some-option"), new ArgumentToken("file1.bmp"), new ArgumentToken("file2.png") };

            CollectionAssert.AreEqual(expected, tokens);
        }
コード例 #12
0
        public void TestArgumentTokenConstruction()
        {
            var token = new ArgumentToken <int> .Builder().Name("arg1").IsOptional(false).Parser(int.TryParse).Build();

            Assert.Equal("arg1", token.ArgumentName);
            Assert.Equal("<arg1>", token.DisplayName);
            Assert.False(token.IsOptional);
            Assert.Equal(TokenKind.Argument, token.Kind);
        }
コード例 #13
0
        private static LogicalLine readMcall(TokenCollection stream)
        {
            int start = stream.Position;
            McallFunctionPrimitive mcall = stream.GetNextToken() as McallFunctionPrimitive;

            if (mcall == null)
            {
                throw new HspLogicalLineException("mcall:mcallプリミティブ以外からスタート");
            }
            if (stream.NextIsEndOfLine)
            {
                stream.Position = start;
                return((LogicalLine)readCommand(stream));
            }
            ExpressionToken exp = CodeTokenFactory.ReadExpression(stream);

            if (exp.CanRpnConvert)            //RPN変換ができるなら普通の関数として扱う。
            {
                stream.Position = start;
                return((LogicalLine)readCommand(stream));
            }

            stream.Position = start;
            stream.GetNextToken();
            VariablePrimitive var = stream.GetNextToken() as VariablePrimitive;

            if (var == null)
            {
                throw new HspLogicalLineException("mcall行:変換不能な形式");
            }
            if (stream.NextIsBracketStart)            //mcall の記法は配列変数を認めない
            {
                throw new HspLogicalLineException("mcall行:変換不能な形式");
            }
            if (stream.NextIsEndOfLine)
            {
                throw new HspLogicalLineException("mcall行:変換不能な形式");
            }
            exp = CodeTokenFactory.ReadExpression(stream);
            if (stream.NextIsEndOfLine)
            {
                return(new McallStatement(mcall, var, exp, null));
            }
            ArgumentToken arg = CodeTokenFactory.ReadArgument(stream);

            if (stream.NextIsEndOfLine)
            {
                return(new McallStatement(mcall, var, exp, arg));
            }
            throw new HspLogicalLineException("mcall行:余分なトークンがある");
        }
コード例 #14
0
ファイル: DateMatchUtils.cs プロジェクト: samvasta/Budget-CLI
        public static bool TryMatchYesterday(ArgumentToken token, DateTime currentDate, string[] inputTokens, int startIdx, out TokenMatchResult result)
        {
            //Yesterday
            if (inputTokens[startIdx].Equals("yesterday", StringComparison.CurrentCultureIgnoreCase))
            {
                DateTime output = currentDate.Subtract(new TimeSpan(1, 0, 0, 0));
                result = new TokenMatchResult(token, inputTokens[startIdx], inputTokens[startIdx], MatchOutcome.Full, inputTokens[startIdx].Length, 1);
                result.SetArgValue(token, output);
                return(true);
            }

            result = TokenMatchResult.None;
            return(false);
        }
コード例 #15
0
        public void TestTryGetValueByString()
        {
            ArgumentToken <int> token = new ArgumentToken <int> .Builder().Name("arg").Parser(int.TryParse).Build();

            TokenMatchResult result = new TokenMatchResult(token, "123", "123", MatchOutcome.Full, 3, 1);

            result.SetArgValue(token, 123);

            int  argValue;
            bool hasValue = result.TryGetArgValue("arg", out argValue);

            Assert.True(hasValue);
            Assert.Equal(123, argValue);
        }
コード例 #16
0
        [InlineData(new [] { "a" }, 0, MatchOutcome.Partial, 0)]                        //not enough
        public void TestOptionWithArgumentsMatches(string[] input, int startIdx, MatchOutcome expMatchLength, int expNumMatchTokens)
        {
            ArgumentToken arg1 = new ArgumentToken <int> .Builder().Name("arg1").Parser(int.TryParse).Build();

            var token = new OptionWithArgumentToken.Builder()
                        .Name("option", "alt1", "alt2")
                        .WithArgument(arg1)
                        .Build();

            TokenMatchResult matchResult = token.Matches(input, startIdx);

            Assert.True(expMatchLength == matchResult.MatchOutcome, $"Failed in case \"{input}\"");
            Assert.Equal(expNumMatchTokens, matchResult.TokensMatched);
        }
コード例 #17
0
ファイル: DateMatchUtils.cs プロジェクト: samvasta/Budget-CLI
        public static bool TryMatchExplicitDate(ArgumentToken token, string[] inputTokens, int startIdx, out TokenMatchResult result)
        {
            DateTime output;

            //Explicit date
            if (DateTime.TryParse(inputTokens[startIdx], out output))
            {
                result = new TokenMatchResult(token, inputTokens[startIdx], inputTokens[startIdx], MatchOutcome.Full, inputTokens[startIdx].Length, 1);
                result.SetArgValue(token, output);
                return(true);
            }

            result = TokenMatchResult.None;
            return(false);
        }
コード例 #18
0
        public void TestLoadArgumentOptionCollection_NoToken()
        {
            var logger         = new LoggerImpl();
            var argumentTokens = new ArgumentToken[0];

            var(optionCollection, remainningTokens) = ArgumentOptionCollection.LoadArgumentOptionCollection(argumentTokens, logger);

            Assert.IsFalse(optionCollection.AllowDestinationOverwrite);
            Assert.IsFalse(optionCollection.EnableRecursiveDirectorySearch);
            Assert.AreEqual(ImageFileKind.Pdf, optionCollection.DestinationImageFileKind);
            Assert.AreEqual(new Range <uint>(uint.MinValue, uint.MaxValue), optionCollection.PowerpointPageRange);
            Assert.IsFalse(optionCollection.EnableVersionInfoDisplay);

            Assert.AreEqual(0, remainningTokens.Count);
        }
コード例 #19
0
        } /* end ParseMultipleProducts */

/* ---------------------------------------------------------------------------
 * private method ParseIdentifierOption(sym)
 * ---------------------------------------------------------------------------
 * identifierOption :
 *   USE_IDENTIFIERS_VERBATIM | TRANSLITERATE_IDENTIFIERS
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseIdentifierOption(ArgumentToken sym)
        {
            switch (sym)
            {
            case ArgumentToken.USE_IDENTIFIERS_VERBATIM:
                CompilerOptions.SetOption(Option.UseIdentifiersVerbatim, true);
                break;

            case ArgumentToken.TRANSLITERATE_IDENTIFIERS:
                CompilerOptions.SetOption(Option.UseIdentifiersVerbatim, false);
                break;
            } /* end switch */

            return(ArgumentLexer.NextToken());
        } /* end ParseIdentifierOption */
コード例 #20
0
        } /* end ParseIdentifierOption */

/* ---------------------------------------------------------------------------
 * private method ParseCommentOption(sym)
 * ---------------------------------------------------------------------------
 * commentOption :
 *   PRESERVE_COMMENTS | STRIP_COMMENTS
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseCommentOption(ArgumentToken sym)
        {
            switch (sym)
            {
            case ArgumentToken.PRESERVE_COMMENTS:
                CompilerOptions.SetOption(Option.PreserveComments, true);
                break;

            case ArgumentToken.STRIP_COMMENTS:
                CompilerOptions.SetOption(Option.PreserveComments, false);
                break;
            } /* end switch */

            return(ArgumentLexer.NextToken());
        } /* end ParseCommentOption */
コード例 #21
0
        [InlineData(new [] { "1234", "b", "c", "d" }, 2, false, 0)]        //Match is before the start token
        public void TestArgumentMatches(string[] input, int startIdx, bool expMatches, int expMatchLength)
        {
            var token = new ArgumentToken <int> .Builder().Name("arg1").IsOptional(false).Parser(int.TryParse).Build();

            TokenMatchResult matchResult = token.Matches(input, startIdx);

            if (expMatches)
            {
                Assert.True(matchResult.MatchOutcome == MatchOutcome.Full, $"Failed in case \"{input}\"");
            }
            else
            {
                Assert.False(matchResult.MatchOutcome == MatchOutcome.Full, $"Failed in case \"{input}\"");
            }
            Assert.Equal(expMatchLength, matchResult.TokensMatched);
        }
コード例 #22
0
        public void TestOptionWithArgumentsTokenConstruction()
        {
            ArgumentToken arg1 = new ArgumentToken <int> .Builder().Name("arg1").Parser(int.TryParse).Build();

            Name name  = new Name("option", "alt1", "alt2");
            var  token = new OptionWithArgumentToken.Builder()
                         .Name("option", "alt1", "alt2")
                         .WithArgument(arg1)
                         .Build();

            Assert.Equal(name, token.Name);
            Assert.Equal("(option|alt1|alt2) <arg1>", token.DisplayName);
            Assert.True(token.IsOptional);
            Assert.Equal(TokenKind.OptionWithArgument, token.Kind);
            Assert.Equal(1, token.Arguments.Length);
            Assert.Same(arg1, token.Arguments[0]);
        }
コード例 #23
0
        } /* end ParseCompilationRequest */

/* ---------------------------------------------------------------------------
 * private method ParseDialect(sym)
 * ---------------------------------------------------------------------------
 * dialect :
 *   ( PIM3 | PIM4 ) ( SAFER | COMPLIANT )? | EXT
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseDialect(ArgumentToken sym)
        {
            if (sym == ArgumentToken.EXT)
            {
                CompilerOptions.SetDialect(Dialect.Extended);
            }
            else
            {
                switch (sym)
                {
                case ArgumentToken.PIM3:
                    CompilerOptions.SetDialect(Dialect.PIM3);
                    break;

                case ArgumentToken.PIM4:
                    CompilerOptions.SetDialect(Dialect.PIM4);
                    break;
                } /* end switch */

                sym = ArgumentLexer.NextToken();

                switch (sym)
                {
                case ArgumentToken.SAFER:
                    CompilerOptions.SetOption(Option.Synonyms, false);
                    CompilerOptions.SetOption(Option.OctalLiterals, false);
                    CompilerOptions.SetOption(Option.ExplicitCast, false);
                    CompilerOptions.SetOption(Option.Coroutines, false);
                    CompilerOptions.SetOption(Option.VariantRecords, false);
                    CompilerOptions.SetOption(Option.LocalModules, false);
                    break;

                case ArgumentToken.COMPLIANT:
                    CompilerOptions.SetOption(Option.Synonyms, true);
                    CompilerOptions.SetOption(Option.OctalLiterals, true);
                    CompilerOptions.SetOption(Option.ExplicitCast, true);
                    CompilerOptions.SetOption(Option.Coroutines, true);
                    CompilerOptions.SetOption(Option.VariantRecords, true);
                    CompilerOptions.SetOption(Option.LocalModules, true);
                    break;
                } /* end switch */
            }     /* end if */

            return(ArgumentLexer.NextToken());
        } /* end ParseDialect */
コード例 #24
0
        public void TestEqualAndHashCode()
        {
            ArgumentToken <int> token = new ArgumentToken <int> .Builder().Name("arg").Parser(int.TryParse).Build();

            TokenMatchResult result1 = new TokenMatchResult(token, "123", "123", MatchOutcome.Full, 3, 1);

            TokenMatchResult result2 = new TokenMatchResult(token, "123", "123", MatchOutcome.Full, 3, 1);

            Assert.Equal(result1, result2);
            Assert.True(result1 == result2);
            Assert.False(result1 != result2);
            Assert.True(result1 <= result2);
            Assert.True(result1 >= result2);
            Assert.False(result1.Equals(null));
            Assert.True(result1.Equals((object)result2));
            Assert.False(result1.Equals("not the same type"));
            Assert.Equal(result1.GetHashCode(), result2.GetHashCode());
        }
コード例 #25
0
        [InlineData("verb0 verb4 -o1 -o2 1 2.34 -o3", 0, 4)]                    //All tokens present, wrong order
        public void TestMatchWithOptionalTokensWithArgs(string input, params int[] expectedMatchingIndexes)
        {
            ArgumentToken arg1 = new ArgumentToken <int> .Builder().Name("arg1").IsOptional(false).Parser(int.TryParse).Build();

            ArgumentToken arg2 = new ArgumentToken <double> .Builder().Name("arg2").IsOptional(false).Parser(double.TryParse).Build();

            var tokens = new ICommandToken[]
            {
                new VerbToken(new Name("verb0")),
                new StandAloneOptionToken(new Name("-o1", "--option1")),
                new OptionWithArgumentToken.Builder().Name("-o2", "--option2").WithArgument(arg1).WithArgument(arg2).Build(),
                new StandAloneOptionToken(new Name("-o3", "--option3")),
                new VerbToken(new Name("verb4")),
            };
            var builder = new CommandUsage.Builder()
                          .Description("test usage");

            foreach (var token in tokens)
            {
                builder.WithToken(token);
            }

            ICommandUsage usage = builder.Build();

            TokenMatchCollection matchCollection = CommandParser.Match(usage.Tokens, input);

            Assert.Same(usage.Tokens, matchCollection.MatchableTokens);
            if (expectedMatchingIndexes.Length > 0)
            {
                Assert.NotEmpty(matchCollection.Matches);

                Assert.Equal(expectedMatchingIndexes.Length, matchCollection.Matches.Count());

                //Ensure all that are expected are there
                foreach (var expectedMatchingIndex in expectedMatchingIndexes)
                {
                    Assert.True(matchCollection.Matches.Any(x => x.TokenIdx == expectedMatchingIndex));
                }
            }
            else
            {
                Assert.Empty(matchCollection.Matches);
            }
        }
コード例 #26
0
        } /* end ParseSingleProduct */

/* ---------------------------------------------------------------------------
 * private method ParseMultipleProducts(sym)
 * ---------------------------------------------------------------------------
 * multipleProducts :
 *   ( ast | graph | xlat | obj )+
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseMultipleProducts(ArgumentToken sym)
        {
            while (ArgumentLexer.IsMultipleProductsOption(sym))
            {
                switch (sym)
                {
                case ArgumentToken.AST:
                    SetOption(Option.AstRequired, true);
                    break;

                case ArgumentToken.NO_AST:
                    SetOption(Option.AstRequired, false);
                    break;

                case ArgumentToken.GRAPH:
                    SetOption(Option.GraphRequired, true);
                    break;

                case ArgumentToken.NO_GRAPH:
                    SetOption(Option.GraphRequired, true);
                    break;

                case ArgumentToken.XLAT:
                    SetOption(Option.XlatRequired, true);
                    break;

                case ArgumentToken.NO_XLAT:
                    SetOption(Option.XlatRequired, false);
                    break;

                case ArgumentToken.OBJ:
                    SetOption(Option.ObjRequired, true);
                    break;

                case ArgumentToken.NO_OBJ:
                    SetOption(Option.ObjRequired, true);
                    break;
                } /* end switch */

                sym = ArgumentLexer.NextToken();
            } /* end while */

            return(sym);
        } /* end ParseMultipleProducts */
コード例 #27
0
ファイル: DateMatchUtils.cs プロジェクト: samvasta/Budget-CLI
        public static bool TryMatchLastDayOfWeek(ArgumentToken token, DateTime currentDate, string[] inputTokens, int startIdx, out TokenMatchResult result)
        {
            //last <day-of-week>
            if (inputTokens.Length > startIdx + 1)
            {
                DayOfWeek dayOfWeek;
                if (DateParser.TryParseDayOfWeek(inputTokens[startIdx + 1], out dayOfWeek))
                {
                    DateTime output    = DateUtil.GetRelativeDateDayOfWeek(currentDate, dayOfWeek);
                    string   matchText = TokenUtils.GetMatchText(inputTokens, startIdx, 2);
                    result = new TokenMatchResult(token, matchText, matchText, MatchOutcome.Full, matchText.Length, 2);
                    result.SetArgValue(token, output);
                    return(true);
                }
            }

            result = TokenMatchResult.None;
            return(false);
        }
コード例 #28
0
        } /* end ErrorCount */

/* ---------------------------------------------------------------------------
 * private method ParseInfoRequest(sym)
 * ---------------------------------------------------------------------------
 * infoRequest :
 *   HELP | VERSION | LICENSE
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseInfoRequest(ArgumentToken sym)
        {
            switch (sym)
            {
            case ArgumentToken.HELP:
                status = ArgumentStatus.HelpRequested;
                break;

            case ArgumentToken.VERSION:
                status = ArgumentStatus.VersionRequested;
                break;

            case ArgumentToken.LICENSE:
                status = ArgumentStatus.LicenseRequested;
                break;
            } /* end switch */

            return(ArgumentLexer.NextToken());
        } /* end ParseInfoRequest */
コード例 #29
0
        } /* end ParseProducts */

/* ---------------------------------------------------------------------------
 * private method ParseSingleProduct(sym)
 * ---------------------------------------------------------------------------
 * singleProduct :
 *   SYNTAX_ONLY | AST_ONLY | GRAPH_ONLY | XLAT_ONLY | OBJ_ONLY
 *   ;
 * ------------------------------------------------------------------------ */

        private static ArgumentToken ParseSingleProduct(ArgumentToken sym)
        {
            switch (sym)
            {
            case ArgumentToken.SYNTAX_ONLY:
                CompilerOptions.SetOption(Option.AstRequired, false);
                CompilerOptions.SetOption(Option.GraphRequired, false);
                CompilerOptions.SetOption(Option.XlatRequired, false);
                CompilerOptions.SetOption(Option.ObjRequired, false);
                break;

            case ArgumentToken.AST_ONLY:
                CompilerOptions.SetOption(Option.AstRequired, true);
                CompilerOptions.SetOption(Option.GraphRequired, false);
                CompilerOptions.SetOption(Option.XlatRequired, false);
                CompilerOptions.SetOption(Option.ObjRequired, false);
                break;

            case ArgumentToken.GRAPH_ONLY:
                CompilerOptions.SetOption(Option.AstRequired, false);
                CompilerOptions.SetOption(Option.GraphRequired, true);
                CompilerOptions.SetOption(Option.XlatRequired, false);
                CompilerOptions.SetOption(Option.ObjRequired, false);
                break;

            case ArgumentToken.XLAT_ONLY:
                CompilerOptions.SetOption(Option.AstRequired, false);
                CompilerOptions.SetOption(Option.GraphRequired, false);
                CompilerOptions.SetOption(Option.XlatRequired, true);
                CompilerOptions.SetOption(Option.ObjRequired, false);
                break;

            case ArgumentToken.OBJ_ONLY:
                CompilerOptions.SetOption(Option.AstRequired, false);
                CompilerOptions.SetOption(Option.GraphRequired, false);
                CompilerOptions.SetOption(Option.XlatRequired, false);
                CompilerOptions.SetOption(Option.ObjRequired, true);
                break;
            } /* end switch */

            return(ArgumentLexer.NextToken());
        } /* end ParseSingleProduct */
コード例 #30
0
ファイル: DateMatchUtils.cs プロジェクト: samvasta/Budget-CLI
        public static bool TryMatchLastDayOfMonth(ArgumentToken token, DateTime currentDate, string[] inputTokens, int startIdx, out TokenMatchResult result)
        {
            //last <month> <day-of-month>
            if (inputTokens.Length > startIdx + 2)
            {
                int month;
                int day;
                if (DateParser.TryParseMonth(inputTokens[startIdx + 1], out month) &&
                    DateParser.TryParseDayOfMonth(inputTokens[startIdx + 2], currentDate.Year - 1, month, out day))
                {
                    DateTime output    = new DateTime(currentDate.Year - 1, month, day);
                    string   matchText = TokenUtils.GetMatchText(inputTokens, startIdx, 3);
                    result = new TokenMatchResult(token, matchText, matchText, MatchOutcome.Full, matchText.Length, 3);
                    result.SetArgValue(token, output);
                    return(true);
                }
            }

            result = TokenMatchResult.None;
            return(false);
        }