Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.MuParser$ChoicePoint


        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <start> :: = <<intArg>> | <<fileArg>>
        MuSyntax syntax = new MuAlternation(new MuArgument("intArg"), new MuArgument("fileArg"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"1"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new Integer(1), intArg.getValue());
        Assert.assertEquals(false, fileArg.isSet());

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new File("x"), fileArg.getValue());
        Assert.assertEquals(false, intArg.isSet());

    }
View Full Code Here


        MuSyntax syntax =
                new MuAlternation("root", new MuArgument("fileArg"), new MuSequence(new MuArgument(
                        "intArg"), new MuBackReference("root")));
        syntax.resolveBackReferences();

        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "2", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        // <root> ::= ( <<intArg>> <root> ) | <<fileArg>>
        MuSyntax syntax =
                new MuAlternation("root", new MuSequence(new MuArgument("intArg"),
                        new MuBackReference("root")), new MuArgument("fileArg"));
        syntax.resolveBackReferences();
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "1", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

            new MuBackReference("root")), new MuSequence(new MuArgument("bigArg"), new MuArgument("smallArg"))),
            new MuAlternation(new MuSequence(new MuArgument("intArg"), new MuBackReference("root")),
                new MuArgument("bigArg")));
        syntax.resolveBackReferences();

        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"BIG"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "LARGE"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "BIG"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "3", "BIG", "SMALL"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(1, smallArg.getValues().length);
        Assert.assertEquals(3, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "2", "TINY"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.jnode.shell.syntax.MuParser$ChoicePoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.